使用ReplicatedMergeTree本地表的Distributed分布式表的组合
vi /etc/clickhouse-server/config.xml--配置zookeeper
创建本地表
--创建本地表CREATE TABLE myck.demo_local on cluster cluster2(id UInt32,name String)Engine = ReplicatedMergeTree('/clickhouse/tables/{shard}/demo_local', '{replica}')order by id ;
创建分布式表
CREATE TABLE demo_all on cluster cluster2 Engine=Distributed('cluster2','myck','demo_local',id) as myck.demo_local;
--在linux01服务器上向分布式表中 插入数据INSERT INTO demo_all values(1,'zs');INSERT INTO demo_all values(2,'zs');INSERT INTO demo_all values(3,'zs');INSERT INTO demo_all values(4,'zs');SELECt *FROM demo_local┌─id─┬─name─┐│ 2 │ zs │└────┴──────┘┌─id─┬─name─┐│ 4 │ zs │└────┴──────┘--在linux02服务器上向分布式表中 插入数据INSERT INTO demo_all values(6,'zs');INSERT INTO demo_all values(8,'zs');SELECt *FROM demo_local┌─id─┬─name─┐│ 2 │ zs │└────┴──────┘┌─id─┬─name─┐│ 6 │ zs │└────┴──────┘┌─id─┬─name─┐│ 4 │ zs │└────┴──────┘┌─id─┬─name─┐│ 8 │ zs │└────┴──────┘--linux01与linux02中都是该数据 说明副本自动复制 由于没有设置internal_replication
--在linux01服务器上向本地表中 插入数据INSERT into demo_local values(10,'zs');INSERT into demo_local values(12,'zs');select * from demo_local ;┌─id─┬─name─┐│ 12 │ zs │└────┴──────┘┌─id─┬─name─┐│ 2 │ zs ││ 4 │ zs ││ 6 │ zs ││ 8 │ zs ││ 10 │ zs │└────┴──────┘--在linux02中向本地表中插入数据INSERT into demo_local values(14,'zs');INSERT into demo_local values(16,'zs');select * from demo_local ;┌─id─┬─name─┐│ 2 │ zs ││ 4 │ zs ││ 6 │ zs ││ 8 │ zs ││ 10 │ zs │└────┴──────┘┌─id─┬─name─┐│ 14 │ zs │└────┴──────┘┌─id─┬─name─┐│ 12 │ zs │└────┴──────┘┌─id─┬─name─┐│ 16 │ zs │└────┴──────┘
MergeTree本地表和分布式表的组合
在linux01中向分布式表插入数据,副本会自动复制.而在linux02中向分布式表插入数据,副本不会自动复制,数据会发送失败,暂时还没找到出现此问题的原因.