ClickHouse更改数据文件目录
除了软链接之外,网上没找到特别准确更改CK数据文件目录的文章。
软链接那种也不推荐,实际上数据字典的目录还是原来的,只不过原来的目录做了层快捷方式到新目录。相当于多了个故障点。
实际更改也并不复杂,如下:
1.默认的数据目录包含在/var/lib/clickhouse中,将该文件夹移动到需要更改的新目录,假设为/clickhouse。
vi /etc/clickhouse-server/config.xml 更改全部的/var/lib/clickhouse改为/clickhouse
2.停止数据库服务
[root@szceb-ck01 ~]# /etc/init.d/clickhouse-server stop
3.移动位置
[root@szceb-ck01 ~]# mv /var/lib/clickhouse /
4.查看原有全部库的软链接
[root@szceb-ck01 ~]# cd /clickhouse/metadata [root@szceb-ck01 metadata]# ll total 20 lrwxrwxrwx 1 clickhouse clickhouse 67 Jun 17 11:04 default -> /var/lib/clickhouse/store/d62/d62f0212-2505-4257-87ed-3d35e7486fa1/ -rw-r----- 1 clickhouse clickhouse 78 Jun 17 11:04 default.sql drwxr-x--- 2 clickhouse clickhouse 6 Jun 17 11:04 information_schema drwxr-x--- 2 clickhouse clickhouse 6 Jun 17 11:04 INFORMATION_SCHEMA -rw-r----- 1 clickhouse clickhouse 51 Jun 17 11:04 information_schema.sql -rw-r----- 1 clickhouse clickhouse 51 Jun 17 11:04 INFORMATION_SCHEMA.sql lrwxrwxrwx 1 clickhouse clickhouse 67 Jun 17 11:04 system -> /var/lib/clickhouse/store/8a1/8a14d4ab-3d9d-45d6-86db-ed0e58115b53/ -rw-r----- 1 clickhouse clickhouse 78 Jun 17 11:04 system.sql lrwxrwxrwx 1 clickhouse clickhouse 67 Jun 17 14:48 traffic -> /var/lib/clickhouse/store/59a/59a29a98-284f-4c99-b0af-8a73bba2d395/ -rw-r----- 1 clickhouse clickhouse 78 Jun 17 14:48 traffic.sql
说明:这些是原来库自动创建的软链接,以default为例子:default实际指向还是/var/lib/clickhouse/.../.../,需要重置为新位置的目录。
5.重置软链接指向
[root@szceb-ck01 metadata]# rm -f system traffic default [root@szceb-ck01 metadata]# ln -s /clickhouse/store/d62/d62f0212-2505-4257-87ed-3d35e7486fa1/ default [root@szceb-ck01 metadata]# ln -s /clickhouse/store/8a1/8a14d4ab-3d9d-45d6-86db-ed0e58115b53/ system [root@szceb-ck01 metadata]# ln -s /clickhouse/store/59a/59a29a98-284f-4c99-b0af-8a73bba2d395/ traffic [root@szceb-ck01 metadata]# chown -h clickhouse:clickhouse system traffic default
注意,chown一定要加上-h参数,不然更改的权限目标实际上是软链接对应的真正的位置。
6.启动数据库
[root@szceb-ck01 ~]# /etc/init.d/clickhouse-server start
7.查看数据字典
szceb-ck01 :) select * from system.databases; SELECT * FROM system.databases Query id: 18ef56c3-2cfa-4eff-8cb7-6d8e748c7ac1 ┌─name───────────────┬─engine─┬─data_path──────────┬─metadata_path───────────────────────────────────────────────┬─uuid─────────────────────────────────┬─comment─┐ │ INFORMATION_SCHEMA │ Memory │ /clickhouse/ │ │ 00000000-0000-0000-0000-000000000000 │ │ │ default │ Atomic │ /clickhouse/store/ │ /clickhouse/store/d62/d62f0212-2505-4257-87ed-3d35e7486fa1/ │ d62f0212-2505-4257-87ed-3d35e7486fa1 │ │ │ information_schema │ Memory │ /clickhouse/ │ │ 00000000-0000-0000-0000-000000000000 │ │ │ system │ Atomic │ /clickhouse/store/ │ /clickhouse/store/8a1/8a14d4ab-3d9d-45d6-86db-ed0e58115b53/ │ 8a14d4ab-3d9d-45d6-86db-ed0e58115b53 │ │ │ traffic │ Atomic │ /clickhouse/store/ │ /clickhouse/store/906/59a29a98-284f-4c99-b0af-8a73bba2d395/ │ 906023dc-f646-4d93-8cbb-f5ae8a1f0482 │ │ └────────────────────┴────────┴────────────────────┴─────────────────────────────────────────────────────────────┴──────────────────────────────────────┴─────────┘ 5 rows in set. Elapsed: 0.003 sec.