etcd — the Distributed Configuration Store
etcd is the distributed configuration store (DCS) that Patroni uses to elect a leader and hold cluster state. Run all the commands in this page on pg-sv01, pg-sv02 and pg-sv03.
Install
sudo apt-get update
sudo apt-get install -y etcd-server etcd-client
sudo systemctl stop etcd # stop the single-node default before reconfiguring
Configure
etcd reads its settings from /etc/default/etcd. The config is almost identical on every node — only ETCD_NAME and the node's own IP change. Create it on each node, substituting that node's name and address:
# On pg-sv01 use NAME=pg-sv01 / IP=10.100.100.104, on pg-sv02 use pg-sv02 / .105, etc.
MYNAME=$(hostname)
MYIP=$(ip -4 -o addr show eth0 | awk '{print $4}' | cut -d/ -f1)
sudo tee /etc/default/etcd >/dev/null <<EOF
ETCD_NAME=$MYNAME
ETCD_DATA_DIR=/var/lib/etcd/pg-cluster
ETCD_LISTEN_PEER_URLS=http://$MYIP:2380
ETCD_LISTEN_CLIENT_URLS=http://$MYIP:2379,http://127.0.0.1:2379
ETCD_INITIAL_ADVERTISE_PEER_URLS=http://$MYIP:2380
ETCD_ADVERTISE_CLIENT_URLS=http://$MYIP:2379
ETCD_INITIAL_CLUSTER=pg-sv01=http://10.100.100.104:2380,pg-sv02=http://10.100.100.105:2380,pg-sv03=http://10.100.100.106:2380
ETCD_INITIAL_CLUSTER_STATE=new
ETCD_INITIAL_CLUSTER_TOKEN=pg-etcd-cluster
EOF
sudo rm -rf /var/lib/etcd/pg-cluster
sudo install -d -o etcd -g etcd -m 0700 /var/lib/etcd/pg-cluster
Firewall (UFW)
Allow the etcd client and peer ports only from the three database nodes — run on each node:
for p in 10.100.100.104 10.100.100.105 10.100.100.106; do
sudo ufw allow from $p to any port 2379 proto tcp
sudo ufw allow from $p to any port 2380 proto tcp
done
Start — all three together
⚠️ Important: with
ETCD_INITIAL_CLUSTER_STATE=new, each member blocks until quorum forms, and systemd treats the service as "started" only once it has joined. If you start nodes one at a time, the first one hangs waiting for peers. Configure all three first, then start them at the same time.
sudo systemctl enable etcd
# run this on all three nodes within a few seconds of each other:
sudo systemctl --no-block restart etcd
Verify
etcdctl --endpoints=http://10.100.100.104:2379,http://10.100.100.105:2379,http://10.100.100.106:2379 \
endpoint health --cluster
etcdctl --endpoints=http://127.0.0.1:2379 member list
You should see all three endpoints reported healthy and three members in the list. The DCS is ready.
No comments to display
No comments to display