Distributed deployment of clickhouse in Docker

Startup service

docker run --add-host=ck2:172.17.0.3 --add-host=ck3:172.17.0.4 -d --name ck1 -h ck1 --ip 172.17.0.2 --ulimit nofile=262144:262144 -p 8124:8123 -p 9001:9000 yandex/clickhouse-server
docker run --add-host=ck1:172.17.0.2 --add-host=ck3:172.17.0.4 -d --name ck2 -h ck2 --ip 172.17.0.3 --ulimit nofile=262144:262144 -p 8125:8123 -p 9002:9000 yandex/clickhouse-server
docker run --add-host=ck1:172.17.0.2 --add-host=ck2:172.17.0.3 -d --name ck3 -h ck3 --ip 172.17.0.4 --ulimit nofile=262144:262144 -p 8126:8123 -p 9003:9000 yandex/clickhouse-server

Parameter description

  • Add host: add hosts configuration other than yourself
  • name: container name
  • h: host name
  • ip: address assigned to container

clickhouse distributed configuration

Modify container profile

First, copy the configuration file in the container to the local area for modification, find the configuration node remote server, and add the following configuration:

<my_ck_cluster>
    <shard>
        <internal_replication>true</internal_replication>
        <replica>
            <host>ck01</host>
            <port>9000</port>
        </replica>
    </shard>
    <shard>
        <internal_replication>true</internal_replication>
        <replica>
            <host>ck02</host>
            <port>9000</port>
        </replica>
    </shard>
    <shard>
        <internal_replication>true</internal_replication>
        <replica>
            <host>ck03</host>
            <port>9000</port>
        </replica>
    </shard>
</my_ck_cluster>

If you need to use zookeeper, add the following configuration under zookeeper:

<zookeeper incl="zookeeper-servers" optional="true" />
<zookeeper>
    <node index="1">
        <host>zk01</host>
        <port>2181</port>
    </node>
    <node index="2">
        <host>zk02</host>
        <port>2181</port>
    </node>
    <node index="3">
        <host>zk03</host>
        <port>2181</port>
    </node>
</zookeeper>

Copy the modified configuration file back to the container

docker cp config.xml ck1:/etc/clickhouse-server/config.xml
docker cp config.xml ck2:/etc/clickhouse-server/config.xml
docker cp config.xml ck3:/etc/clickhouse-server/config.xml

Restart related containers

docker restart ck1 ck2 ck3

View the contents of / etc/hosts

docker exec -it ck1 /bin/bash less /etc/hosts The contents are as follows:

172.17.0.2      ck1
172.17.0.3      ck2
172.17.0.4      ck3

Tags: Programming Docker Zookeeper xml less

Posted on Mon, 30 Mar 2020 09:34:52 -0700 by The Wise One