This Terraform project sets up a ClickHouse cluster with 3 nodes in Google Cloud Platform:
- 2 nodes running both ClickHouse data server and ClickHouse Keeper
- 1 node running only ClickHouse Keeper for quorum (no data)
- Google Cloud Platform account with a project
- Terraform installed locally
- Google Cloud SDK installed
- SSH key pair
- Change default password in modules/clickhouse/user_admin.xml with ( echo -n 'your_new_strong_password' | sha256sum | tr -d ' -' )
- Set up your Google Cloud credentials:
export GOOGLE_APPLICATION_CREDENTIALS="$HOME/.googlecloud.json"- Update the private key path in the
terraform.tfvarsfile:
private_key_path = "~/.ssh/id_ed25519" # Path to your private SSH keyTo deploy the ClickHouse cluster:
- Navigate to the dev environment:
cd environments/dev- Initialize Terraform:
terraform init- Apply the Terraform plan:
terraform apply- After deployment completes (approx. 5-10 minutes), you'll get outputs with the ClickHouse endpoints:
clickhouse_endpoints = {
"chnode1" = "x.x.x.x:8123"
"chnode2" = "y.y.y.y:8123"
"chnode3" = "z.z.z.z:8123"
}
clickhouse_clients = {
"chnode1" = "x.x.x.x:9000"
"chnode2" = "y.y.y.y:9000"
"chnode3" = "z.z.z.z:9000"
}
You can connect to your ClickHouse cluster using the clickhouse-client:
clickhouse-client --host=x.x.x.x --port=9000Or via HTTP:
curl "http://x.x.x.x:8123/?query=SELECT%20*%20FROM%20db1.table1_dist"The cluster is configured with:
- 2 shards (one on each data node)
- 1 replica per shard
- A distributed table to query data across all shards
Each node has the following configuration files:
network-and-logging.xml- Basic network and logging configurationenable-keeper.xml- ClickHouse Keeper configuration with server IDmacros.xml- Defines shard and replica macros (data nodes only)remote-servers.xml- Cluster configurationuse-keeper.xml- Configuration to use ClickHouse Keeper for coordination
To destroy the infrastructure:
terraform destroy