Infrastructure Preparation
Objectives
After this lesson, you will:
- Understand hardware and software requirements for Patroni cluster
- Configure network and firewall
- Setup 3 VMs/Servers (VirtualBox/VMware/Cloud)
- Establish SSH key-based authentication
- Synchronize time with NTP/chrony
1. Hardware & Software Requirements
Lab Architecture
We will setup a cluster with 3 nodes:
Lab Architecture
Hardware Requirements (per node)
Minimum (Lab/Dev):
- CPU: 2 cores
- RAM: 4 GB
- Disk: 20 GB (OS) + 20 GB (PostgreSQL data)
- Network: 1 Gbps
Recommended (Production):
- CPU: 4-8 cores
- RAM: 8-32 GB (depends on workload)
- Disk:
- OS: 50 GB SSD
- PostgreSQL data: 100+ GB NVMe SSD
- WAL: Separate disk (optional, for performance)
- Network: 10 Gbps, redundant NICs
Storage recommendations:
Software Requirements
Operating System:
- Ubuntu 22.04 LTS (recommended)
- Rocky Linux 9 / AlmaLinux 9
- Debian 12
Software Stack:
Network Requirements
Latency:
- Between PostgreSQL nodes: < 10ms (same datacenter)
- Between etcd nodes: < 5ms (critical!)
- Client to database: < 50ms
Bandwidth:
- Replication: Depends on write load
- etcd: Low bandwidth, but low latency critical
Ports to open:
| Service | Port | Protocol | Purpose |
|---|---|---|---|
| PostgreSQL | 5432 | TCP | Database connections |
| Patroni REST API | 8008 | TCP | Health checks, management |
| etcd client | 2379 | TCP | Client-to-etcd communication |
| etcd peer | 2380 | TCP | etcd cluster communication |
| SSH | 22 | TCP | Remote administration |
2. Network and Firewall Configuration
IP Planning
Node assignments:
Optional components:
Hostname Configuration
On each node:
Firewall Configuration (UFW)
On Ubuntu:
Expected output:
Firewall Configuration (firewalld)
On Rocky Linux / AlmaLinux:
Network Performance Testing
Test latency between nodes:
3. Setup 3 VMs/Servers
Option 1: VirtualBox (Local Development)
Create VM template:
Configure network:
Option 2: VMware Workstation
Create VM: 1. New Virtual Machine → Custom 2. Hardware compatibility: Workstation 17.x 3. Install from: ISO image (Ubuntu 22.04) 4. Guest OS: Linux → Ubuntu 64-bit 5. VM name: pg-node1 6. Processors: 2 cores 7. Memory: 4096 MB 8. Network: Bridged or NAT with port forwarding 9. Disk: 40 GB, single file 10. Finish and install OS
Clone for other nodes:
- Right-click VM → Manage → Clone
- Create linked clone or full clone
- Change VM name and network settings
Post-Installation Steps (All Platforms)
Update system:
Disable swap (recommended for databases):
Set system limits:
4. SSH Key-based Authentication
Generate SSH keys
On your local machine/jump server:
Copy keys to all nodes
Configure SSH client
Edit ~/.ssh/config:
Test SSH connectivity
Setup inter-node SSH (for postgres user)
On each node:
5. Time Synchronization (NTP/chrony)
Why time sync is critical?
Importance:
- Distributed systems rely on consistent time
- etcd uses timestamps for leader election
- PostgreSQL WAL includes timestamps
- Monitoring and debugging requires accurate time
Acceptable drift: < 500ms (ideally < 100ms)
Install and configure chrony (Recommended)
Ubuntu/Debian:
Configuration:
Start and enable:
Expected output:
Alternative: systemd-timesyncd (Simpler)
Ubuntu/Debian:
Configuration:
Enable and verify:
Verify time synchronization across cluster
Create verification script:
6. Lab: Complete Infrastructure Setup
Lab Objectives
- Setup 3 VMs with correct network
- Configure firewall for all required ports
- Establish SSH passwordless authentication
- Synchronize time with NTP
- Verify connectivity between nodes
Lab Steps
Step 1: Verify VM specifications
Step 2: Network connectivity test
Step 3: Verify SSH authentication
Step 4: Check time synchronization
Step 5: Run comprehensive validation
Expected output (all green checkmarks):
7. Summary
Infrastructure Checklist
Before proceeding to lesson 5, ensure:
✅ 3 VMs/Servers ready with sufficient CPU, RAM, disk
✅ Networking configured: static IPs, /etc/hosts
✅ Firewall rules: ports 22, 5432, 8008, 2379, 2380
✅ SSH keys deployed, passwordless authentication works
✅ Time sync configured with chrony/timesyncd
✅ System optimized: swap disabled, kernel parameters tuned
✅ Connectivity verified: all nodes can reach each other
Troubleshooting
Problem: SSH connection refused
Problem: Time drift detected
Problem: Network unreachable
Review Questions
- Why do we need at least 3 nodes for Patroni cluster?
- What firewall ports need to be opened? Why?
- Why is time synchronization important for distributed systems?
- Should swap be enabled for PostgreSQL server? Why?
- What should be the latency between etcd nodes?
Preparation for next lesson
Lesson 5 will guide PostgreSQL installation:
- Install PostgreSQL from package repository
- Configure postgresql.conf
- Set up pg_hba.conf
- Lab: Install PostgreSQL on 3 nodes