【AntDB Installation and Deployment Documentation】ETCD+patroni for High Availability (2)
Configure etcd's service
Executed by root user
cat > /etc/systemd/system/etcd.service <<EOF
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
User=root
Type=notify
WorkingDirectory=/var/lib/etcd/
ExecStart=/bin/etcd --config-file=/etc/etcd/conf.yaml
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
Start etcd
Start etcd as a service
Executed by root user
systemctl daemon-reload
Open the port, the non-default port must remember to open, otherwise systemctl start etcd will fail
systemctl enable etcd #After enable, etcd will start automatically when the host is booted.
Execute as antdb user
systemctl start etcd If it's already on at the beginning, then systemctl restart etcd
systemctl status etcd
Check the status of etcd cluster
systemctl status etcd
Expected output.
[root@host227 ~]# systemctl status etcd
● etcd.service - Etcd Server
Loaded: loaded (/etc/systemd/system/etcd.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2022-08-01 17:11:38 CST; 4min 3s ago
Main PID: 25631 (etcd)
Tasks: 46
Memory: 31.1M
CGroup: /system.slice/etcd.service
└─25631 /bin/etcd --config-file=/etc/etcd/conf.yaml
After etcd is configured on all 3 hosts, you can check the status of the etcd cluster
etcdctl --endpoints=http://127.0.0.1:12379 member list
Expected output
[root@host227 ~]# etcdctl --endpoints=http://127.0.0.1:12379 member list
88b36252d4fcd138: name=etcd-2 peerURLs=http://10.20.16.228:12380 clientURLs=http://10.20.16.228:12379 isLeader=false
9ad1f6e716a2ebe6: name=etcd-1 peerURLs=http://10.20.16.227:12380 clientURLs=http://10.20.16.227:12379 isLeader=true
fc652d5e31669223: name=etcd-3 peerURLs=http://10.20.16.214:12380 clientURLs=http://10.20.16.214:12379 isLeader=false
Manage the cluster with Patroni
The following operations need to be performed on all 3 hosts, modify the configuration according to the actual situation.
Configure patroni
Create the file /etc/patroni.yml and configure it as follows.
Executed by root user.
cat > /etc/patroni.yml <<EOF
scope: antdb-cluster # Naming of clusters
namespace: /antdb/ # Here the default is service, if it is not set, it will be /service/.
name: adbnode_01 # Node names, which need to be different for each node
restapi:
listen: 10.20.16.227:8008 # Change to actual ip
connect_address: 10.20.16.227:8008 # Change to actual ip
etcd:
hosts: 10.20.16.227:12379,10.20.16.228:12379,10.20.16.214:12379
bootstrap:
# this section will be written into Etcd:/<namespace>/<scope>/config after initializing new cluster
# and all other cluster members will use it as a `global configuration`
dcs:
ttl: 15
loop_wait: 5
retry_timeout: 5
maximum_lag_on_failover: 1048576
master_start_timeout: 300
synchronous_mode: true
postgresql:
use_pg_rewind: true
parameters:
listen_addresses: "*"
port: 40571 # Change to the actual AntDB port number
wal_level: logical #patroni's stream replication level requires logical
log_directory: "pg_log"
log_destination: "csvlog"
hot_standby: "on"
wal_keep_size: 10240
max_wal_senders: 10
postgresql:
listen: 10.20.16.227:40571 # Change to actual ip and AntDB port
connect_address: 10.20.16.227:40571 # Change to actual ip and AntDB port
data_dir: /data/shan2/pgdata # Change to the actual data catalog
bin_dir: /data/shan2/pgsql_adb/bin # Change to the actual installation directory
pgpass: /data/shan2/.pgpass # Modify it to an actual .pgpass file. pgpass cannot be in the same directory as pgdata.
authentication: # Change to actual username and password
replication:
username: replicator
password: antdb
superuser:
username: shan
password: shan@123
parameters:
unix_socket_directories: '/tmp'
tags:
nofailover: false
noloadbalance: false
clonefrom: false
nosync: false
EOF
The above configuration is modified according to the actual situation.
Configure service for patroni
Executed by the root user.
Note that the User and Group users here are the same as the AntDB installation users.
cat > /usr/lib/systemd/system/patroni.service <<EOF
[Unit]
Description=Runners to orchestrate a high-availability AntDB5.0
After=syslog.target network.target
[Service]
Type=simple
User=shan2
Group=shan2
ExecStart=/usr/local/bin/patroni /etc/patroni.yml
KillMode=process
TimeoutSec=30
Restart=no
[Install]
WantedBy=multi-user.target
EOF