https://github.com/synacktraa/clickhouse-on-ec2-using-tf
Deploy clickhouse server on EC2 using Terraform.
https://github.com/synacktraa/clickhouse-on-ec2-using-tf
Last synced: 5 months ago
JSON representation
Deploy clickhouse server on EC2 using Terraform.
- Host: GitHub
- URL: https://github.com/synacktraa/clickhouse-on-ec2-using-tf
- Owner: synacktraa
- License: mit
- Created: 2025-06-10T21:32:21.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-06-10T22:01:46.000Z (about 1 year ago)
- Last Synced: 2025-07-01T18:10:42.804Z (12 months ago)
- Language: HCL
- Size: 4.88 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Clickhouse on EC2 using terraform
## Prerequisites
1. **AWS CLI configured** with appropriate credentials
2. **Terraform installed**
## Deployment Steps
### 1. Initialize Terraform
```bash
git clone https://github.com/synacktraa/clickhouse-on-ec2-using-tf.git
cd clickhouse-on-ec2-using-tf
terraform init
```
### 2. Create Keys
```bash
ssh-keygen -t rsa -b 4096 -f ec2-clickhouse
```
### 3. Apply the Configuration
```bash
terraform apply
```
#### Variables
- `instance_type` - Change Instance's type (Default: `t3.small`)
- `volume_size` - Modify storage size of the device (Default: `20gb`)
- `allowed_cidr_blocks` - Restrict access to certain IPs (Default: `0.0.0.0/0`)
Type `yes` when prompted to confirm the deployment.
### 4. Get Outputs
After deployment, get the connection details:
```bash
# Get public IP and connection info
terraform output
# Get the generated password of clickhouse server (sensitive output)
terraform output -raw clickhouse_password
```
## Accessing the instance
### Via SSH Tunnel
```bash
$(terraform output -raw ssh_command)
```
### Clickhouse HTTP Interface (Web/API)
```bash
# Basic health check
curl http://$(terraform output -raw public_ip):8123/ping
# Run a simple query
curl -u "default:$(terraform output -raw clickhouse_password)" "http://$(terraform output -raw public_ip):8123/?query=SELECT+version()"
```
### Clickhouse Native TCP Client
```bash
clickhouse-client --host $(terraform output -raw public_ip) --port 9000 --user default --password $(terraform output -raw clickhouse_password)
```
## Cleanup
To destroy all resources:
```bash
terraform destroy
```
Type `yes` when prompted to confirm destruction.
## Troubleshooting
1. Verify security group rules allow your IP
2. Check if ClickHouse is listening: `netstat -tlnp | grep :8123`
3. Test from within the instance: `curl localhost:8123/ping`