{"id":15874161,"url":"https://github.com/garutilorenzo/clickhouse-cluster","last_synced_at":"2025-08-10T03:33:21.546Z","repository":{"id":154321544,"uuid":"349491459","full_name":"garutilorenzo/clickhouse-cluster","owner":"garutilorenzo","description":"ClickHouse cluster Docker environment","archived":false,"fork":false,"pushed_at":"2021-04-19T13:21:25.000Z","size":31,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-07T21:15:47.356Z","etag":null,"topics":["clickhouse","cluster","container","database","docker","docker-image","dockerfile"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/garutilorenzo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-19T16:42:54.000Z","updated_at":"2024-10-24T16:39:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"f52cd225-11e8-49ae-9249-f9823bf6c636","html_url":"https://github.com/garutilorenzo/clickhouse-cluster","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/garutilorenzo/clickhouse-cluster","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garutilorenzo%2Fclickhouse-cluster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garutilorenzo%2Fclickhouse-cluster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garutilorenzo%2Fclickhouse-cluster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garutilorenzo%2Fclickhouse-cluster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/garutilorenzo","download_url":"https://codeload.github.com/garutilorenzo/clickhouse-cluster/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garutilorenzo%2Fclickhouse-cluster/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269672052,"owners_count":24457112,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clickhouse","cluster","container","database","docker","docker-image","dockerfile"],"created_at":"2024-10-06T01:21:10.790Z","updated_at":"2025-08-10T03:33:21.506Z","avatar_url":"https://github.com/garutilorenzo.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Clickhouse Cluster CI](https://github.com/garutilorenzo/clickhouse-cluster/actions/workflows/ci.yml/badge.svg)](https://github.com/garutilorenzo/clickhouse-cluster/actions/workflows/ci.yml)\n[![GitHub issues](https://img.shields.io/github/issues/garutilorenzo/clickhouse-cluster)](https://github.com/garutilorenzo/clickhouse-cluster/issues)\n![GitHub](https://img.shields.io/github/license/garutilorenzo/clickhouse-cluster)\n[![GitHub forks](https://img.shields.io/github/forks/garutilorenzo/clickhouse-cluster)](https://github.com/garutilorenzo/clickhouse-cluster/network)\n[![GitHub stars](https://img.shields.io/github/stars/garutilorenzo/clickhouse-cluster)](https://github.com/garutilorenzo/clickhouse-cluster/stargazers)\n\n![Clickhouse Logo](https://garutilorenzo.github.io/images/clickhouse.png)\n\n# ClickHouse cluster Docker environment\n\n[ClickHouse®](https://clickhouse.tech/) is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).\n\n# How this repo work\n\nThis simple docker environment shows how clickhouse  cluster works.\nThe cluster is made by two clickhouse services (click-one and click-two) and one zookeeper service (needed for replicated tables).\nAll 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.\n\n# Cluster description\n\nThis setup is meaded by two cluster:\n\n* replicated\n* distributed\n\nthe cluster configuration is located in cluster.xml on both config directories:\n\n```\n\u003cyandex\u003e\n   \u003cdefault_replica_path replace=\"replace\"\u003e/clickhouse/tables/{shard}/{database}/{table}\u003c/default_replica_path\u003e\n   \u003cdefault_replica_name replace=\"replace\"\u003e{replica}\u003c/default_replica_name\u003e\n   \u003cremote_servers replace=\"replace\"\u003e\n        \u003creplicated\u003e\n            \u003cshard\u003e\n              \u003creplica\u003e\n                  \u003chost\u003eclick-one\u003c/host\u003e\n                  \u003cport\u003e9000\u003c/port\u003e\n               \u003c/replica\u003e\n               \u003creplica\u003e\n                  \u003chost\u003eclick-two\u003c/host\u003e\n                  \u003cport\u003e9000\u003c/port\u003e\n               \u003c/replica\u003e\n             \u003c/shard\u003e\n        \u003c/replicated\u003e\n        \u003cdistributed\u003e\n            \u003cshard\u003e\n              \u003creplica\u003e\n                  \u003chost\u003eclick-one\u003c/host\u003e\n                  \u003cport\u003e9000\u003c/port\u003e\n               \u003c/replica\u003e\n            \u003c/shard\u003e\n            \u003cshard\u003e\n               \u003creplica\u003e\n                  \u003chost\u003eclick-two\u003c/host\u003e\n                  \u003cport\u003e9000\u003c/port\u003e\n               \u003c/replica\u003e\u003e\n             \u003c/shard\u003e\n        \u003c/distributed\u003e\n    \u003c/remote_servers\u003e\n\u003c/yandex\u003e\n```\n\n[Replicated](https://clickhouse.tech/docs/en/engines/table-engines/mergetree-family/replication/) 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.\n\n[Distributed](https://clickhouse.tech/docs/en/engines/table-engines/special/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.\n\n# Start the cluster\n\nUse this command to start the cluster:\n\n```\ndocker-compose up -d\n```\n\non click-one container the sql directory is mounted on /docker-entrypoint-initdb.d path. \nThe files:\n\n* distributed.sql - creates tutorial_distributed database and then tutorial_distributed.hits_v1 table\n* replicated.sql - creates tutorial_replicated database and then tutorial_replicated.hits_v1 table\n\nThis table is the same used on clickhouse [tutorial](https://clickhouse.tech/docs/en/getting-started/tutorial/)\n\nYou can then download the sample dataset:\n\n```\ncurl https://datasets.clickhouse.tech/hits/tsv/hits_v1.tsv.xz | unxz --threads=`nproc` \u003e hits_v1.tsv\n```\n\nand inject data inside the cluster:\n\n```\ndocker-compose exec click-one clickhouse-client --query \"INSERT INTO tutorial_distributed.hits_v1 FORMAT TSV\" --max_insert_block_size=100000 \u003c hits_v1.tsv\ndocker-compose exec click-one clickhouse-client --query \"INSERT INTO tutorial_replicated.hits_v1 FORMAT TSV\" --max_insert_block_size=100000 \u003c hits_v1.tsv\n```\n\n# Cleanup\n\nUse this command to clean all data and stop the containers:\n\n```console\ndocker-compose down -v\n```\n\n# Notes about docker image\n\nIn this setup i've used a custom docker image.\nThere are some difference between the official image:\n\n* added healtcheck on Dockerfile\n* added sticky bit on /var/lib/clickhouse /var/log/clickhouse-server /etc/clickhouse-server /etc/clickhouse-client directories\n* entrypoint.sh refectoring","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarutilorenzo%2Fclickhouse-cluster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgarutilorenzo%2Fclickhouse-cluster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarutilorenzo%2Fclickhouse-cluster/lists"}