|
1 | 1 | # questdb-devops
|
2 | 2 | Quick Deployment of QuestDB with Envoy on the Cloud using Terraform and Docker
|
3 | 3 |
|
| 4 | +## Technology Stack |
| 5 | +- **QuestDB**: High-performance time-series database |
| 6 | +- **Envoy Proxy**: Used as TLS/SSL termination layer since QuestDB Community Edition doesn't support native TLS |
| 7 | +- **Docker**: Container runtime for QuestDB and Envoy deployment |
| 8 | +- **Docker Compose**: Container orchestration for multi-container deployment |
| 9 | +- **Terraform**: Infrastructure as Code tool for cloud deployment |
| 10 | +- **ZFS**: Advanced file system for data persistence |
| 11 | +- **Google Cloud Platform**: Cloud infrastructure provider |
4 | 12 |
|
| 13 | +## Prerequisites |
| 14 | +- Ubuntu-based system (tested on Ubuntu 22.04 LTS) |
| 15 | +- Google Cloud Platform account with billing enabled |
| 16 | +- A GCP project with Compute Engine API enabled |
| 17 | +- A secondary disk mounted at /dev/sdb for ZFS storage (will be created by Terraform) |
| 18 | +- Terraform and gcloud CLI installed locally |
5 | 19 |
|
6 |
| -1. install terraform and gcloud cli |
7 |
| -2. setup gcloud cli login |
8 |
| -3. in terraform folder run terraform apply |
9 |
| -4. run setup.sh script make sure the persistent volume on linux mahcine is mounted to /dev/sdb before use chmod +x to enable permission to run |
| 20 | +## Architecture |
| 21 | +- QuestDB runs in a Docker container handling time-series data storage and processing |
| 22 | +- Envoy Proxy container acts as a reverse proxy providing: |
| 23 | + - TLS termination for HTTPS (port 9000) |
| 24 | + - TLS termination for PostgreSQL wire protocol (port 8812) |
| 25 | +- ZFS provides reliable storage with compression and data integrity features |
| 26 | + |
| 27 | +## Installation Steps |
| 28 | + |
| 29 | +### 1. Local Environment Setup |
| 30 | +```bash |
| 31 | +# Install Terraform |
| 32 | +sudo apt-get update && sudo apt-get install -y gnupg software-properties-common |
| 33 | +wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg |
| 34 | +echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list |
| 35 | +sudo apt update && sudo apt-get install terraform |
| 36 | + |
| 37 | +# Install Google Cloud CLI |
| 38 | +curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg |
| 39 | +echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list |
| 40 | +sudo apt-get update && sudo apt-get install google-cloud-cli |
| 41 | +gcloud init |
| 42 | +``` |
| 43 | + |
| 44 | +### 2. GCP Configuration |
| 45 | +```bash |
| 46 | +# Authenticate with GCP |
| 47 | +gcloud auth application-default login |
| 48 | + |
| 49 | +# Configure terraform.tfvars |
| 50 | +cat > terraform/terraform.tfvars <<EOF |
| 51 | +project_id = "your-project-id" |
| 52 | +allowed_ip = "your-ip-address/32" |
| 53 | +EOF |
| 54 | +``` |
| 55 | + |
| 56 | +### 3. Infrastructure Deployment |
| 57 | +```bash |
| 58 | +cd terraform |
| 59 | +terraform init |
| 60 | +terraform plan # Review the changes |
| 61 | +terraform apply # Deploy the infrastructure |
| 62 | +``` |
| 63 | + |
| 64 | +### 4. Server Configuration |
| 65 | +After the infrastructure is deployed, SSH into the created VM instance: |
| 66 | +```bash |
| 67 | +# Make setup script executable and run it |
| 68 | +chmod +x setup.sh |
| 69 | +./setup.sh |
| 70 | + |
| 71 | +# Generate SSL certificates |
| 72 | +cd questdb |
| 73 | +chmod +x generate-certs.sh |
| 74 | +./generate-certs.sh --name "your-domain-or-ip" |
| 75 | + |
| 76 | +# Start the services |
| 77 | +docker compose up -d |
| 78 | +``` |
| 79 | + |
| 80 | +## SSL Certificate Management |
| 81 | +- Self-signed certificates are generated in `questdb/certs/` |
| 82 | +- Certificate files: |
| 83 | + - `cert.pem`: Public certificate |
| 84 | + - `key.pem`: Private key |
| 85 | +- Default validity: 365 days |
| 86 | +- To regenerate with custom settings: |
| 87 | +```bash |
| 88 | +./generate-certs.sh --country US --state California --locality "San Francisco" \ |
| 89 | + --org "Your Company" --name "your-domain.com" --valid 730 |
| 90 | +``` |
| 91 | + |
| 92 | +## Service URLs |
| 93 | +- QuestDB Web Console: `https://<your-server-ip>:9000` |
| 94 | +- PostgreSQL Interface: `postgresql://<your-server-ip>:8812` |
| 95 | + |
| 96 | +## Troubleshooting |
| 97 | +1. Certificate Issues: |
| 98 | + - Ensure both cert.pem and key.pem have 644 permissions |
| 99 | + - Verify certificate validity: `openssl x509 -in certs/cert.pem -text -noout` |
| 100 | +2. Connection Issues: |
| 101 | + - Check GCP firewall rules (created by Terraform) |
| 102 | + - Verify Envoy logs: `docker logs envoy` |
| 103 | + - Verify QuestDB logs: `docker logs questdb` |
| 104 | + |
| 105 | +## Data Management |
| 106 | +- QuestDB data is stored in ZFS pool at /questdb_zfs |
| 107 | +- ZFS features enabled: |
| 108 | + - LZ4 compression |
| 109 | + - Disabled access time updates |
| 110 | + - 12-bit ashift for modern drives |
| 111 | + |
| 112 | +## Performance Tuning |
| 113 | +Environment variables in docker-compose.yml optimize QuestDB for: |
| 114 | +- Yearly data partitioning |
| 115 | +- Optimized WAL and data append sizes |
| 116 | +- Configured memory allocation for column operations |
| 117 | + |
| 118 | +## Notes |
| 119 | +- The setup script will install Docker, ZFS utilities, and configure the storage |
| 120 | +- SSL certificates are required for secure communication |
| 121 | +- Default ports: 9000 (HTTPS), 8812 (PostgreSQL) |
| 122 | +- Data is persisted in a ZFS pool mounted at /questdb_zfs |
0 commit comments