Patroni lab, Ubuntu 20, Part 2

Install locally:
echo -e '\n192.168.88.11 node1\n192.168.88.12 node2\n192.168.88.13 node3\n' | tee -a /etc/hosts
Use local machine to install a hosts file on each node:
ssh node1 "echo -e '\n192.168.88.11 node1\n192.168.88.12 node2\n192.168.88.13 node3\n' | tee -a /etc/hosts"
ssh node2 "echo -e '\n192.168.88.11 node1\n192.168.88.12 node2\n192.168.88.13 node3\n' | tee -a /etc/hosts"
ssh node3 "echo -e '\n192.168.88.11 node1\n192.168.88.12 node2\n192.168.88.13 node3\n' | tee -a /etc/hosts"
Set correct time zone:
timedatectl set-timezone Europe/Riga
Install etcd:
apt-get -y install etcd
Stop etcd to install new config:
systemctl stop etcd
Install config, run on node1:

echo '
ETCD_NAME="node1"
ETCD_INITIAL_CLUSTER="node1=http://192.168.88.11:2380"
ETCD_INITIAL_CLUSTER_TOKEN="patroni-token"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.88.11:2380"
ETCD_DATA_DIR="/var/lib/etcd/postgres.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.88.11:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.88.11:2379,http://localhost:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.88.11:2379"
' | sudo tee -a /etc/default/etcd
Run on node1:
etcdctl member add node2 http://192.168.88.12:2380
It will print:
Added member named node2 with ID bd23008c29fbeab8 to cluster

ETCD_NAME="node2"
ETCD_INITIAL_CLUSTER="node1=http://localhost:2380,node2=http://192.168.88.12:2380"
ETCD_INITIAL_CLUSTER_STATE="existing"
If we run again then it will say:
client: etcd cluster is unavailable or misconfigured; error #0: client: etcd member http://localhost:2379 has no leader
Run on node2:
apt-get -y install etcd && systemctl stop etcd
Run on node2:

echo '
ETCD_NAME="node2"
ETCD_INITIAL_CLUSTER="node1=http://192.168.88.11:2380,node2=http://192.168.88.12:2380"
ETCD_INITIAL_CLUSTER_TOKEN="patroni-token"
ETCD_INITIAL_CLUSTER_STATE="existing"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.88.12:2380"
ETCD_DATA_DIR="/var/lib/etcd/postgres.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.88.12:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.88.12:2379,http://localhost:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.88.12:2379"
' | sudo tee -a /etc/default/etcd
On node2 start etcd daemon and enable at startup:
systemctl enable --now etcd
On node1 run:
etcdctl member list
It will print:
17bc0070e84a2f7f: name=node1 peerURLs=http://192.168.88.11:2380 clientURLs=http://192.168.88.11:2379 isLeader=true
8aba58e830a6682b: name=node2 peerURLs=http://192.168.88.12:2380 clientURLs=http://192.168.88.12:2379 isLeader=false
On node1 run:
etcdctl member add node3 http://192.168.88.13:2380
It will print:
Added member named node3 with ID 8c8561bf4d2dff70 to cluster

ETCD_NAME="node3"
ETCD_INITIAL_CLUSTER="node1=http://192.168.88.11:2380,node2=http://192.168.88.12:2380,node3=http://192.168.88.13:2380"
ETCD_INITIAL_CLUSTER_STATE="existing"
Run on node3:
apt-get -y install etcd && systemctl stop etcd
Run on node3:

echo '
ETCD_NAME="node3"
ETCD_INITIAL_CLUSTER="node1=http://192.168.88.11:2380,node2=http://192.168.88.12:2380,node3=http://192.168.88.13:2380"
ETCD_INITIAL_CLUSTER_TOKEN="patroni-token"
ETCD_INITIAL_CLUSTER_STATE="existing"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.88.13:2380"
ETCD_DATA_DIR="/var/lib/etcd/postgres.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.88.13:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.88.13:2379,http://localhost:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.88.13:2379"
' | sudo tee -a /etc/default/etcd
Start and enable service at startup on node3:
systemctl enable --now etcd
Check on any node:
etcdctl member list
Check on each node where the process is listening on:
ss --tcp --listen --numeric --process | grep etcd
output on node1:
LISTEN    0         4096             127.0.0.1:2379             0.0.0.0:*        users:(("etcd",pid=14481,fd=8))
LISTEN    0         4096         192.168.88.13:2379             0.0.0.0:*        users:(("etcd",pid=14481,fd=7))
LISTEN    0         4096         192.168.88.13:2380             0.0.0.0:*        users:(("etcd",pid=14481,fd=6))
output on node2:
LISTEN    0         4096             127.0.0.1:2379             0.0.0.0:*        users:(("etcd",pid=3006,fd=8))
LISTEN    0         4096         192.168.88.12:2379             0.0.0.0:*        users:(("etcd",pid=3006,fd=7))
LISTEN    0         4096         192.168.88.12:2380             0.0.0.0:*        users:(("etcd",pid=3006,fd=6))
output on node3:
LISTEN    0         4096             127.0.0.1:2379             0.0.0.0:*        users:(("etcd",pid=14481,fd=8))
LISTEN    0         4096         192.168.88.13:2379             0.0.0.0:*        users:(("etcd",pid=14481,fd=7))
LISTEN    0         4096         192.168.88.13:2380             0.0.0.0:*        users:(("etcd",pid=14481,fd=6))

No comments: