docker - 由于权限不足,无法插入 ClickHouse 数据库:/var/lib/clickhouse/data/
问题描述
我通过 docker-compose 在容器中创建了一个 ClickHouse 数据库的实例:
version: '3'
services:
ch:
image: yandex/clickhouse-server
restart: on-failure
volumes:
- '/mnt/c/DevTools/source/storm/clickhouse_setup/data/ch:/var/lib/clickhouse/'
- './ch_configs:/etc/clickhouse-server/'
ports:
- 9000:9000
- 8123:8123
ulimits:
nofile: 262144
client:
image: yandex/clickhouse-client
volumes:
- './client-config.xml:/etc/clickhouse-client/config.xml'
我可以访问它并找到我创建的数据库,但是当我运行时
INSERT INTO simple_people (id, first_name, last_name) VALUES(1,'david','lo')
我得到这个回应:
Query id: 46ef1af8-5728-425e-87f5-511f7e0e79d1
Received exception from server (version 20.12.3):
Code: 1000. DB::Exception: Received from ch:9000. DB::Exception: Access to file denied: insufficient permissions: /var/lib/clickhouse/data/registry/simple_people/tmp_insert_1_2_2_0.
1 rows in set. Elapsed: 0.068 sec.
如何获得 INSERT INTO 的许可?
笔记:
我运行没有问题:
SELECT * FROM simple_people
我在 WSL:Ubuntu-20.04
解决方案
我直接在没有 docker 的 Windows server 2019 上的 WSL Ubuntu 18.04 上安装了 clickhouse,并遇到了同样的问题。在我的例子中,我试图将数据插入到带有 ClickHouse 存储策略设置的表中,以便所有数据都存储在 /mnt/f/clickhouse 中(Windows 上的 F:\clickhouse)。我得到的错误是:
DB::Exception: Access to file denied: insufficient permissions: /mnt/f/clickhouse/store/1e6/1e69cad8-25a1-4ec5-ab5b-fb32d73b7c8c/tmp_insert_all_2_2_0
该问题的解决方法是启用 WSL 上的元数据功能,该功能通过重新安装启用该功能的 F: 驱动器在 linux 和 windows 之间同步权限。如果 clickhouse 文件夹已经存在,则重新创建它。
sudo umount /mnt/f
sudo mount -t drvfs F: /mnt/f -o metadata
额外的信息
如果您对如何在 clickhouse 上设置存储策略以选择数据的位置有任何疑问。以下是我的 /etc/clickhouse-server/config.d/storage.xml 的内容
<yandex>
<storage_configuration>
<disks>
<!--
default disk is special, it always
exists even if not explicitly
configured here, but you can't change
it's path here (you should use <path>
on top level config instead)
-->
<default>
<!--
You can reserve some amount of free space
on any disk (including default) by adding
keep_free_space_bytes tag
-->
<keep_free_space_bytes>1024</keep_free_space_bytes>
</default>
<mnt_f>
<!--
disk path must end with a slash,
folder should be writable for clickhouse user
-->
<path>/mnt/f/clickhouse/</path>
</mnt_f>
</disks>
<policies>
<mnt_f_only> <!-- name for new storage policy -->
<volumes>
<mnt_f_volume> <!-- name of volume -->
<!--
we have only one disk in that volume
and we reference here the name of disk
as configured above in <disks> section
-->
<disk>mnt_f</disk>
</mnt_f_volume>
</volumes>
</mnt_f_only>
</policies>
</storage_configuration>
</yandex>
创建表时选择存储策略:
CREATE TABLE test(
EventId String,
EventName Nullable(String),
) ENGINE = MergeTree()
ORDER BY EventId
SETTINGS storage_policy = 'mnt_f_only';
推荐阅读
- google-home - 来自谷歌迷你智能家居的回答
- powershell - Powershell - 查找网络共享上的所有扩展
- pyspark - Azure databricks 数据帧写入会导致作业中止错误
- javascript - 更新已在 JavaScript 中的 Bot Framework v4 中发布 Adaptive Card
- sql - 如何在 SQL 中计算胜率?
- c# - 使用字符串中的公钥验证 JWT
- http - Flutter/Dart 解码 HttpClientResponse
- javascript - nodemon 应用程序在生产中崩溃(没有错误),在 localhost 中工作
- algorithm - 给定多个集合,我如何找到每个集合中所有其他子集唯一的最小子集?
- amazon-web-services - go and dynamo 从表中的字段和字段不为空/字段不为空的表中获取数据