vim /etc/clickhouse-server/config.xml
true 10.0.5.153 9000 true 10.0.5.154 9000 true 10.0.5.155 9001 10.0.5.37 2181 10.0.5.37 2182 10.0.5.37 2183
01 10.0.5.153
02 10.0.5.154
03 10.0.5.155
使用scp命令将配置文件传到两外两台机器上:
scp /etc/clickhouse-server/config.xml root@10.0.5.153:/etc/clickhouse-server/config.xml
scp /etc/clickhouse-server/config.xml root@10.0.5.154:/etc/clickhouse-server/config.xml
这个参考我之前发布的下载资源,windows下直接使用cmd即可打开zk集群服务。
需要修改文件组:
# -m是多行模式,分号+回车执行当前语句。
clickhouse-client --port=xxx --host=xxx --user=xxx --password=xxx -m

-- 集群上创建数据库
create database a9_mixed on cluster clickhouse_3shards_1replicas;-- 在已有数据的表上创建分布式表,这里t_log_goods是机器上已经存在数据的表。
create table t_log_goods_all on cluster clickhouse_3shards_1replicas [as a9_mixed.t_log_goods] engine = Distributed(clickhouse_3shards_1replicas,a9_mixed,t_log_goods);-- show create table 的语句为:
CREATE TABLE a9_mixed.t_log_goods_all
(`val` Int32,`new` Int32,`flag` Int32,`rname` String,`optime` Int32,`level` Int32,`goodsid` Int32,`old` Int32,`rid` Int64,`platform` Int32,`sid` Int32,`quality` Int32,`uid` Int32,`guid` Int64,`id` Int32,`sdk` String,`power` Int64,`seri` Int32,`goodstype` Int32
)
ENGINE = Distributed('clickhouse_3shards_1replicas', 'a9_mixed', 't_log_goods');
-- 重新在机器上执行 这样子只会在执行sql的机器上新建名字为t_log_goods_all的表,其他机器并不会新建表。-- 删除分布式表
drop table t_log_goods_all on cluster clickhouse_3shards_1replicas;-- 新建本地表,然后对应一张分布式表
CREATE TABLE t_local on cluster clickhouse_3shards_1replicas
(EventDate DateTime,CounterID UInt32,UserID UInt32
) ENGINE MergeTree() PARTITION BY toYYYYMM(EventDate) ORDER BY (CounterID, EventDate);-- 对应的分布式表
CREATE TABLE t_logical_Distributed on cluster clickhouse_3shards_1replicas
(EventDate DateTime,CounterID UInt32,UserID UInt32
)
ENGINE = Distributed(clickhouse_3shards_1replicas, test01, t_local, CounterID) ;-- 向分布式表中写入数据,分布式表最终也是把数据分散写入对应的分片。
INSERT INTO t_logical_Distributed VALUES ('2021-01-16 00:00:00', 5, 5),('2021-02-10 00:00:00',6, 6),('2021-03-10 00:00:00',4, 4);