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.
| Piece | What it does | Why |
|---|---|---|
ch-1 to ch-4 | ClickHouse 26.8.36.3 (the 26.8 LTS line), 2 CPUs and 1.5 GB each | two shards, so data and work split in half; two replicas per shard, so a node can die |
keeper-1 to keeper-3 | ClickHouse Keeper, the Raft coordination service | the replicas agree on which parts exist through it; three members survive losing one |
ch-lb | HAProxy, TLS passthrough, health check on /ping | one address for clients, and a dead node leaves the rotation within 2 s |
SeaweedFS (../seaweedfs) | S3-compatible object store | BACKUP ... TO S3 target |
labs (profile) | Python lab container | the 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, quotasWhat makes it production-shaped
- No default user. A fresh ClickHouse image accepts
defaultwith no password.config/users/users.xmlreplaces the users section with one bootstrapadmin; everyone else is created with SQL and stored in Keeper (replicatedaccess 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 withinterserver_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.
The private keys in config/certs/ are not in git: make-certs.sh
creates them. Lab passwords are committed on purpose; in production they
come from a secret manager.