Learn Labs
Foundations

The Production Cluster

Two shards, two replicas each, three Keepers, HAProxy, TLS and backups: what compose_prod.yaml runs and why

compose.yaml runs one ClickHouse server to learn on. compose_prod.yaml runs what the rest of this book measures: a cluster shaped like a small production deployment, on one laptop.

any nodefetch partsfetch partsclientHTTPS :8443 / native TLS :9440HAProxyTLS passthrough, /ping checkch-1shard 01ch-2shard 01ch-3shard 02ch-4shard 02Keeper ×3Raft: parts log, DDL queue, usersSeaweedFS S3BACKUP / RESTOREevery node takes any query: the Distributed table fans out to one replica of each shard and merges the answers
PieceWhat it doesWhy
ch-1 to ch-4ClickHouse 26.8.36.3 (the 26.8 LTS line), 2 CPUs and 1.5 GB eachtwo shards, so data and work split in half; two replicas per shard, so a node can die
keeper-1 to keeper-3ClickHouse Keeper, the Raft coordination servicethe replicas agree on which parts exist through it; three members survive losing one
ch-lbHAProxy, TLS passthrough, health check on /pingone address for clients, and a dead node leaves the rotation within 2 s
SeaweedFS (../seaweedfs)S3-compatible object storeBACKUP ... TO S3 target
labs (profile)Python lab containerthe labs in this book; it has the Docker socket so drills can kill nodes

Starting it

cd seaweedfs && docker compose -f compose_prod.yaml up -d   # backup target
cd ../clickhouse
./scripts/make-certs.sh                                      # lab CA + server cert, once
docker compose -f compose_prod.yaml up -d
./scripts/init.sh                                            # database, roles, users, quotas

What makes it production-shaped

  • No default user. A fresh ClickHouse image accepts default with no password. config/users/users.xml replaces the users section with one bootstrap admin; everyone else is created with SQL and stored in Keeper (replicated access storage), so a user created on one node exists on all four.
  • TLS for clients. HTTPS on 8443 and native TLS on 9440 are the only ports published; plain 8123 and 9000 stay inside the Docker network for the replicas and Distributed queries.
  • Shared secrets between servers. Distributed queries carry the cluster secret, and replicas fetch parts from each other with interserver_http_credentials, so a client can't impersonate a server.
  • Memory bounded twice. A query may use 1 GB (max_memory_usage); the server as a whole stops at 80% of its container limit, so the kernel's OOM killer never gets there first.
  • Health checks, resource limits, log rotation, pinned versions on every container.

Three things that broke on the first start

These are worth knowing because each one looks fine until it isn't.

Every Keeper was "unhealthy" while Keeper was fine. The health check ran echo ruok | nc localhost 9181. Inside the container localhost resolves to the IPv6 address ::1 first, and Keeper listens on 0.0.0.0, IPv4 only. mntr on 127.0.0.1 showed a leader with two synced followers the whole time. Compose refused to start the ClickHouse nodes because their dependency was unhealthy. The fix is 127.0.0.1 in both health checks.

HAProxy crash-looped while the nodes were down. HAProxy resolves backend names at start-up and refuses to start if it can't. A load balancer that won't start because a backend is down defeats its purpose. haproxy.cfg now uses Docker's DNS at runtime (resolvers docker, init-addr last,libc,none), so it starts with nodes missing and picks up a restarted node's new IP.

Python refused the lab certificate. Python 3.13 verifies certificates strictly, and rejected the CA with CA cert does not include key usage extension. openssl req -x509 adds no keyUsage by default. make-certs.sh now creates a proper CA (basicConstraints=CA:TRUE, keyUsage=keyCertSign,cRLSign). Curl and ClickHouse's own client accepted the old one, which is why it went unnoticed.

On this page