1.这里我们准备3台机器如下
- docker01-node(192.168.56.10)
- docker02-node(192.168.56.11)
- docker03-node(192.168.56.12)
2.分别在3台机器上安装单机版的clickhouse环境
参考https://blog.csdn.net/K_520_W/article/details/115427298安装即可
3.修改3台机器的config.xml文件
目的:修改这里的目的是为了让用户在任意机器都可以访问clickhouse节点上的数据
配置文件的路径:/etc/clickhouse-server/config.xml
4.在三台机器的/etc目录下新建metrika.xml文件
<clickhouse_remote_servers> <!--集群名称,clickhouse支持多集群的模式--> <clickhouse_cluster> <!--定义分片节点,这里我指定3个分片,每个分片只有1个副本,也就是它本身--> <shard> <internal_replication>true</internal_replication> <replica> <host>docker01-node</host> <port>9000</port> </replica> </shard> <shard> <replica> <internal_replication>true</internal_replication> <host>docker02-node</host> <port>9000</port> </replica> </shard> <shard> <internal_replication>true</internal_replication> <replica> <host>docker03-node</host> <port>9000</port> </replica> </shard> </clickhouse_cluster> </clickhouse_remote_servers> <!--zookeeper集群的连接信息,用来做高可用的--> <zookeeper-servers> <node index="1"> <host>docker01-node</host> <port>2181</port> </node> <node index="2"> <host>docker02-node</host> <port>2182</port> </node> <node index="3"> <host>docker03-node</host> <port>2183</port> </node> </zookeeper-servers> <!--定义宏变量,后面需要用,每台机器不一样--> <macros> <replica>clickhouse01</replica> </macros> <!--不限制访问来源ip地址--> <networks> <ip>::/0</ip> </networks> <!--数据压缩方式,默认为lz4--> <clickhouse_compression> <case> <min_part_size>10000000000</min_part_size> <min_part_size_ratio>0.01</min_part_size_ratio> <method>lz4</method> </case> </clickhouse_compression> </yandex>
5.启动zookeeper集群
6.启动clickhouse集群
命令:service clickhouse-server start
7.检查集群是否启动成功
1)选择一台机器启动客户端
clickhouse-client
2)查看集群命令:select * from system.clusters