
ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).
This simple docker environment shows how clickhouse cluster works. The cluster is made by two clickhouse services (click-one and click-two) and one zookeeper service (needed for replicated tables). All configurations are stored on config directory at the same level of this README. In this directory you can find two directories one for each clickhouse service.
This setup is meaded by two cluster:
the cluster configuration is located in cluster.xml on both config directories:
<yandex>
<default_replica_path replace="replace">/clickhouse/tables/{shard}/{database}/{table}</default_replica_path>
<default_replica_name replace="replace">{replica}</default_replica_name>
<remote_servers replace="replace">
<replicated>
<shard>
<replica>
<host>click-one</host>
<port>9000</port>
</replica>
<replica>
<host>click-two</host>
<port>9000</port>
</replica>
</shard>
</replicated>
<distributed>
<shard>
<replica>
<host>click-one</host>
<port>9000</port>
</replica>
</shard>
<shard>
<replica>
<host>click-two</host>
<port>9000</port>
</replica>>
</shard>
</distributed>
</remote_servers>
</yandex>
Replicated cluster is made by 2 servers, both of them are in the same shard this means that each table will be replicate 1 to 1 form one server to another.
Distributed cluster is also made by two servers, but the servers are spread in two shard. NOTE: This config is not safe for production environments! Each shard in this configuration has no replica, this means that if we lose a server the entire distributed cluster will be inaccessible and we can have a possible data loss.
Use this command to start the cluster:
docker-compose up -d
on click-one container the sql directory is mounted on /docker-entrypoint-initdb.d path. The files:
This table is the same used on clickhouse tutorial
You can then download the sample dataset:
curl https://datasets.clickhouse.tech/hits/tsv/hits_v1.tsv.xz | unxz --threads=`nproc` > hits_v1.tsv
and inject data inside the cluster:
docker-compose exec click-one clickhouse-client --query "INSERT INTO tutorial_distributed.hits_v1 FORMAT TSV" --max_insert_block_size=100000 < hits_v1.tsv
docker-compose exec click-one clickhouse-client --query "INSERT INTO tutorial_replicated.hits_v1 FORMAT TSV" --max_insert_block_size=100000 < hits_v1.tsv
Use this command to clean all data and stop the containers:
docker-compose down -v
In this setup i've used a custom docker image. There are some difference between the official image:
Content type
Image
Digest
Size
169 MB
Last updated
over 5 years ago
docker pull garutilorenzo/clickhouse