Skip to content

Commit 5fd7e85

Browse files
committed
update readme and shell
1 parent f327451 commit 5fd7e85

File tree

7 files changed

+183
-10
lines changed

7 files changed

+183
-10
lines changed

.gitignore

Whitespace-only changes.

README.md

+117-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,122 @@
11
# questdb-devops
22
Quick Deployment of QuestDB with Envoy on the Cloud using Terraform and Docker
33

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
412

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
519

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

questdb/docker-compose.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ services:
3636

3737
networks:
3838
my_private:
39-
driver: bridge
40-
39+
driver: bridge

questdb/generate-certs.sh

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Default values
5+
CERT_DIR="./certs"
6+
DAYS_VALID=365
7+
COUNTRY="US"
8+
STATE="State"
9+
LOCALITY="City"
10+
ORGANIZATION="MyOrganization"
11+
COMMON_NAME="localhost"
12+
13+
# Help function
14+
show_help() {
15+
echo "Usage: $0 [OPTIONS]"
16+
echo "Options:"
17+
echo " -d, --dir DIR Certificate directory (default: ./certs)"
18+
echo " -v, --valid DAYS Days until expiration (default: 365)"
19+
echo " -c, --country CODE 2-letter country code (default: US)"
20+
echo " -s, --state STATE State name (default: State)"
21+
echo " -l, --locality CITY City name (default: City)"
22+
echo " -o, --org NAME Organization name (default: MyOrganization)"
23+
echo " -n, --name HOSTNAME Common Name/hostname (default: localhost)"
24+
echo " -h, --help Show this help message"
25+
}
26+
27+
# Parse command line arguments
28+
while [[ $# -gt 0 ]]; do
29+
case $1 in
30+
-d|--dir) CERT_DIR="$2"; shift 2 ;;
31+
-v|--valid) DAYS_VALID="$2"; shift 2 ;;
32+
-c|--country) COUNTRY="$2"; shift 2 ;;
33+
-s|--state) STATE="$2"; shift 2 ;;
34+
-l|--locality) LOCALITY="$2"; shift 2 ;;
35+
-o|--org) ORGANIZATION="$2"; shift 2 ;;
36+
-n|--name) COMMON_NAME="$2"; shift 2 ;;
37+
-h|--help) show_help; exit 0 ;;
38+
*) echo "Unknown option: $1"; show_help; exit 1 ;;
39+
esac
40+
done
41+
42+
# Create directory
43+
mkdir -p $CERT_DIR
44+
45+
# Generate self-signed certificate and private key
46+
openssl req -x509 -nodes -days $DAYS_VALID \
47+
-newkey rsa:2048 \
48+
-keyout $CERT_DIR/key.pem \
49+
-out $CERT_DIR/cert.pem \
50+
-subj "/C=$COUNTRY/ST=$STATE/L=$LOCALITY/O=$ORGANIZATION/CN=$COMMON_NAME"
51+
52+
# Set proper permissions for Envoy user (101)
53+
chmod 644 $CERT_DIR/cert.pem
54+
chmod 644 $CERT_DIR/key.pem
55+
56+
# Verify the certificate
57+
echo "Verifying certificate..."
58+
openssl x509 -in $CERT_DIR/cert.pem -text -noout | grep -E "Subject:|Issuer:|Not|DNS:"
59+
60+
echo -e "\nCertificates generated successfully in $CERT_DIR:"
61+
ls -l $CERT_DIR

setup.sh

100644100755
File mode changed.

terraform/main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ resource "google_compute_firewall" "qdb-firewall" {
6262
resource "google_compute_instance" "qdb-ubuntu" {
6363
name = "qdb-ubuntu"
6464
machine_type = "n2d-standard-2"
65-
zone = "australia-southeast1-a"
65+
zone = "asia-east1-a"
6666

6767
tags = ["qdb"]
6868

@@ -99,7 +99,7 @@ output "public-ipv4" {
9999
resource "google_compute_disk" "persistent-data" {
100100
name = "persistent-data"
101101
type = "pd-balanced"
102-
zone = "australia-southeast1-a"
102+
zone = "asia-east1-a"
103103
size = "20"
104104
}
105105

terraform/variables.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ variable "my_ip" {}
66

77

88
variable "region" {
9-
default = "australia-southeast1"
9+
default = "asia-east1"
1010
}
1111

1212
variable "zone" {
13-
default = "australia-southeast1"
13+
default = "asia-east1"
1414
}
1515

0 commit comments

Comments
 (0)