01- Patroni Cluster on Rocky Linux9.5 - Setup ETCD

In previous Patroni Cluster articles, we used the same nodes for ETCD and Postgres services. The OS was Ubuntu 22.04. This time we will run ETCD and Postgres on their own nodes and OS will be Rocky Linux9.5. In the topology below, we must have at least 2 ETCD nodes UP and Running for database service to be available. When only 1 etcd node is alive, Patroni cannot write to the DCS and it goes into read-only / paused mode. 

 

ETCD Cluster Installation (on etcd01, etcd02, etcd03):

sudo su
dnf update -y
dnf install -y wget curl

#Download and Install etcd v3.5.19
wget https://github.com/etcd-io/etcd/releases/download/v3.5.19/etcd-v3.5.19-linux-amd64.tar.gz
tar xvf etcd-v3.5.19-linux-amd64.tar.gz
mv etcd-v3.5.19-linux-amd64/etcd* /usr/local/bin/

#Add etcdctl to PATH Permanently
echo 'export PATH=$PATH:/usr/local/bin' > /etc/profile.d/etcd.sh
chmod +x /etc/profile.d/etcd.sh
source /etc/profile.d/etcd.sh

#SELinux is blocks the execution of the etcd binary under /usr/local/bin. Therefore we label the binary properly.
chcon -t bin_t /usr/local/bin/etcd

#Create Service User and Directories
useradd --system --home /var/lib/etcd --shell /bin/false etcd
mkdir -p /var/lib/etcd /etc/etcd
chown -R etcd:etcd /var/lib/etcd /etc/etcd

 

nano /etc/etcd/etcd.env
#Add the following lines into the env file

#Node1:
ETCD_NAME="etcd-01"
ETCD_DATA_DIR="/var/lib/etcd"
ETCD_INITIAL_CLUSTER="etcd-01=http://192.168.1.151:2380,etcd-02=http://192.168.1.152:2380,etcd-03=http://192.168.1.153:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.151:2380"
ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.151:2379"


#Node2:
ETCD_NAME="etcd-02"
ETCD_DATA_DIR="/var/lib/etcd"
ETCD_INITIAL_CLUSTER="etcd-01=http://192.168.1.151:2380,etcd-02=http://192.168.1.152:2380,etcd-03=http://192.168.1.153:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.152:2380"
ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.152:2379"


#Node3:
ETCD_NAME="etcd-03"
ETCD_DATA_DIR="/var/lib/etcd"
ETCD_INITIAL_CLUSTER="etcd-01=http://192.168.1.151:2380,etcd-02=http://192.168.1.152:2380,etcd-03=http://192.168.1.153:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.153:2380"
ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.153:2379"

 

Create ETCD systemd service

nano /etc/systemd/system/etcd.service

[Unit]
Description=etcd key-value store
Documentation=https://github.com/etcd-io/etcd
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
WorkingDirectory=/var/lib/etcd
EnvironmentFile=/etc/etcd/etcd.env
ExecStart=/usr/local/bin/etcd
Restart=always
RestartSec=10s
LimitNOFILE=40000
User=etcd
Group=etcd

[Install]
WantedBy=multi-user.target

 

Start and Enable ETCD

systemctl daemon-reexec
systemctl daemon-reload
systemctl enable --now etcd

 

Verify

etcdctl --endpoints=http://192.168.1.151:2379,http://192.168.1.152:2379,http://192.168.1.153:2379 endpoint status --write-out=table
etcdctl endpoint health --endpoints=http://192.168.1.151:2379,http://192.168.1.152:2379,http://192.168.1.153:2379 endpoint status --write-out=table

ETCD cluster is UP. Now we can change the following config in etcd.env

nano /etc/etcd/etcd.env

#From:
ETCD_INITIAL_CLUSTER_STATE="new"

#To:
ETCD_INITIAL_CLUSTER_STATE="existing"

#Then restart etcd
systemctl restart etcd


#Verify
etcdctl --endpoints=http://192.168.1.151:2379,http://192.168.1.152:2379,http://192.168.1.153:2379 endpoint status --write-out=table





In Part2, We will setup Patroni + PostgreSQL cluster.