# db CREATE DATABASE dp ON CLUSTER cluster_2S_2R; # base table CREATE TABLE World on CLUSTER cluster_2S_2R ( val String ) ENGINE = ReplicatedMergeTree() ORDER BY val # distributed table | rand() 随机分片 CREATE TABLE World_distributed ON Cluster cluster_2S_2R ENGINE = Distributed(cluster_2S_2R,dp,World,rand()); # data insert INSERT INTO World_distributed(val) SELECT number FROM numbers(10);
Add New Replicas
在当前 CK 集群中新增 SHARD 副本。新架构图描述如下
Show Table Full Engine
1 2
SELECT * FROM system.tables WHERE database = 'dp' AND name = 'World' FORMAT Vertical;
Show Replicas Info
1 2
SELECT * FROM system.zookeeper WHERE path = '/clickhouse/tables/e60cfcf5-27eb-4672-b773-89d06a127422/shard-one/replicas';
Sync Database / Table
1 2 3 4 5 6 7 8 9 10 11 12 13
# on new clickhouse node | clickhouse-05 or clickhouse-06 CREATE DATABASE dp ON CLUSTER cluster_2S_2R; # table base on FULL ENGINE info CREATE TABLE World on CLUSTER cluster_2S_2R ( val String ) ENGINE = ReplicatedMergeTree('/clickhouse/tables/e60cfcf5-27eb-4672-b773-89d06a127422/{shard}', '{replica}') ORDER BY val; # distributed table CREATE TABLE World_distributed ON Cluster cluster_2S_2R ENGINE = Distributed(cluster_2S_2R,dp,World,rand());
Show New Replicas Info
1 2
SELECT * FROM system.zookeeper WHERE path = '/clickhouse/tables/e60cfcf5-27eb-4672-b773-89d06a127422/shard-one/replicas';
Sync Replicas Data
Test New Replicas
1
INSERT INTO World_distributed(val) SELECT number FROM numbers(10);
搭建过程常见问题
New Replicas 无法同步数据
检查 NEW NODES 中 TABLE 的 FULL ENGINE 是否相同
1 2
SELECT * FROM system.tables WHERE database = 'dp' AND name = 'World' FORMAT Vertical;
Received exception from server (version 23.6.2): Code: 516. DB::Exception: Received from localhost:9000. DB::Exception: Received from clickhouse-01:9000. DB::Exception: default: Authentication failed: password is incorrect, or there is no user with such name.
If you have installed ClickHouse and forgot password you can reset it in the configuration file. The password for default user is typically located at /etc/clickhouse-server/users.d/default-password.xml and deleting this file will reset the password. See also /etc/clickhouse-server/users.xml on the server where ClickHouse is installed.