使用docker部署ClickHouse集群
准备工作
部署方案
Load Blancer + ReplicatedMergeTree + Distributed + zookeeper
2 shards 2 replicas
机器信息
主机名 | IP | 分片 | 副本 |
---|---|---|---|
clickhouse1 | 192.168.0.13 | shard1 | replica1 |
clickhouse2 | 192.168.0.14 | shard1 | replica2 |
clickhouse3 | 192.168.0.15 | shard2 | replica1 |
clickhouse4 | 192.168.0.100 | shard2 | replica2 |
规划4个节点, 2个分片, 每个分片2个副本。 分片1的副本在主机clickhouse1和clickhouse2上, 2分片的副本在主机clickhouse3和clickhouse4上。
官方建议zookeeper集群与clickhouse集群分开部署,避免资源竞争导致服务异常。
这里我们将zookeeper汲取 部署到k8s上,部署教程为:
clickhouse集群我们采用docker部署
部署clickhouse集群
获取配置文件
- 按照官方教程,启动clickhouse-server
docker run -d --name clickhouse-server --ulimit nofile=262144:262144 --volume=/data/clickhouse/:/var/lib/clickhouse yandex/clickhouse-server
- 容器启动之后,复制容器内的配置文件到本地
mkdir -p /etc/clickhouse-server docker cp clickhouse-server:/etc/clickhouse-server/ /etc/
修改/etc/clickhouse-server/config.xml
-
找到下述配置,打开注释并进行修改
<listen_host>::1</listen_host> <listen_host>0.0.0.0</listen_host> <listen_host>127.0.0.1</listen_host>
-
找到metrika.xml位置,修改include from节点为实际引用到的文件
<!-- If element has 'incl' attribute, then for it's value will be used corresponding substitution from another file. By default, path to file with substitutions is /etc/metrika.xml. It could be changed in config in 'include_from' element. Values for substitutions are specified in /yandex/name_of_substitution elements in that file. --> <include_from>/etc/clickhouse-server/metrika.xml</include_from>
-
增加分片与副本信息
<!-- Configuration of clusters that could be used in Distributed tables. https://clickhouse.com/docs/en/operations/table_engines/distributed/ --> <remote_servers> <!-- Test only shard config for testing distributed storage --> <cluster_2s_2r> <!-- 数据分片1 --> <shard> <internal_replication>true</internal_replication> <replica> <host>192.168.0.13</host> <port>9000</port> <user>default</user> <password></password> </replica> <replica> <host>192.168.0.14</host> <port>9000</port> <user>default</user> <password></password> </replica> </shard> <!-- 数据分片2 --> <shard> <internal_replication>true</internal_replication> <replica>