暂无图片
暂无图片
8
暂无图片
暂无图片
暂无图片

PostgreSQL高可用Patroni+Etcd

原创 孙莹 2023-09-10
1400

PostgreSQL高可用Patroni+Etcd

patroni.png

Patroni 简介

Patroni基于Python开发的模板,结合DCS(例如 ZooKeeper, etcd, Consul )可以定制PostgreSQL⾼可⽤⽅案。Patroni并不是⼀套拿来即⽤的PostgreSQL⾼可⽤组件,涉及较多的配置和定制⼯作。Patroni接管PostgreSQL数据库的启停,同时监控本地的PostgreSQL数据库,并将本地的PostgreSQL数据库信息写⼊DCS。Patroni的主备端是通过是否能获得 leader key 来控制的,获取到了leader key的Patroni为主节点,其它的为备节点。

Etcd 简介

Etcd是⼀款基于Raft算法和协议开发的分布式 key-value 数据库,基于Go语⾔编写,Patroni监控本地的PostgreSQL状态,并将相关信息写⼊Etcd,每个Patroni都能读写Etcd上的key,从⽽获取外地PostgreSQL数据库信息。当Etcd的leader节点不可⽤时,Etcd会⼀致性的选择⼀个合适的节点作为主节点,新的Etcd主节点将获取leader key,因此建议Etcd集群为三个以上且为奇数的节点。⼀个标准的3节点etcd集群,最⼤容许1个节点故障。

本文将引导您完成在CentOS7.9上使用 PostgreSQL14数据库版本从零安装配置高可用Patroni+Etcd集群

环境准备

主机名 IP地址 操作系统版本 数据库版本 patroni版本 etcd版本
node1 192.168.17.20 CentOS7.9 14.9 3.1.0 3.5.9
node2 192.168.17.21 CentOS7.9 14.9 3.1.0 3.5.9
node3 192.168.17.22 CentOS7.9 14.9 3.1.0 3.5.9

下载软件地址

https://ftp.postgresql.org/pub/source/v14.9/postgresql-14.9.tar.gz

https://ftp.postgresql.org/pub/repos/yum/common/pgdg-rhel7-extras/redhat/rhel-7-x86_64/etcd-3.5.9-1.rhel7.x86_64.rpm

操作系统准备

安装CentOS7.9这里省略

关闭防火墙

systemctl stop firewalld systemctl disable firewalld

3台主机都要操作

[root@node1 ~]# systemctl stop firewalld [root@node1 ~]# systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. [root@node1 ~]# [root@node2 ~]# systemctl stop firewalld [root@node2 ~]# systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. [root@node2 ~]# [root@node3 ~]# systemctl stop firewalld [root@node3 ~]# systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. [root@node3 ~]#

关闭SELINUX

setenforce 0 sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

3台主机都要操作

[root@node1 ~]# setenforce 0 [root@node1 ~]# sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config [root@node2 ~]# setenforce 0 [root@node2 ~]# sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config [root@node3 ~]# setenforce 0 [root@node3 ~]# sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

配置yum源

sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \ -i.bak \ /etc/yum.repos.d/CentOS-*.repo

3台主机都要操作

[root@node1 ~]# sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \ > -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \ > -i.bak \ > /etc/yum.repos.d/CentOS-*.repo [root@node1 ~]# [root@node2 ~]# sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \ > -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \ > -i.bak \ > /etc/yum.repos.d/CentOS-*.repo [root@node2 ~]# [root@node3 ~]# sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \ > -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \ > -i.bak \ > /etc/yum.repos.d/CentOS-*.repo [root@node3 ~]#

配置时间同步

yum install -y ntpdate ntpdate time.windows.com && hwclock -w

3台主机都要操作

[root@node1 ~]# yum install -y ntpdate Loaded plugins: fastestmirror, langpacks Determining fastest mirrors base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/2): extras/7/x86_64/primary_db | 250 kB 00:00:00 (2/2): base/7/x86_64/primary_db | 6.1 MB 00:00:00 Package ntpdate-4.2.6p5-29.el7.centos.2.x86_64 already installed and latest version Nothing to do [root@node1 ~]# ntpdate time.windows.com && hwclock -w 8 Sep 15:32:30 ntpdate[2130]: adjust time server 52.231.114.183 offset 0.018752 sec [root@node1 ~]# [root@node2 ~]# yum install -y ntpdate Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 Package ntpdate-4.2.6p5-29.el7.centos.2.x86_64 already installed and latest version Nothing to do [root@node2 ~]# ntpdate time.windows.com && hwclock -w 8 Sep 15:32:30 ntpdate[2290]: step time server 52.231.114.183 offset -0.875401 sec [root@node2 ~]# [root@node3 ~]# yum install -y ntpdate Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 Package ntpdate-4.2.6p5-29.el7.centos.2.x86_64 already installed and latest version Nothing to do [root@node3 ~]# ntpdate time.windows.com && hwclock -w 8 Sep 15:32:30 ntpdate[2090]: step time server 52.231.114.183 offset -0.770114 sec [root@node3 ~]#

安装所需依赖的包

yum install -y readline readline-devel zlib zlib-devel gettext gettext-devel openssl openssl-devel pam pam-devel libxml2 libxml2-devel libxslt libxslt-devel perl perl-devel tcl-devel uuid-devel gcc gcc-c++ make flex bison perl-ExtUtils*

3台主机都要操作,操作略

设置hosts文件

cat >> /etc/hosts << EOF 192.168.17.20 node1 192.168.17.21 node2 192.168.17.22 node3 EOF

3台主机都要操作

[root@node1 ~]# cat >> /etc/hosts << EOF > > 192.168.17.20 node1 > 192.168.17.21 node2 > 192.168.17.22 node3 > > EOF [root@node1 ~]# [root@node2 ~]# cat >> /etc/hosts << EOF > > 192.168.17.20 node1 > 192.168.17.21 node2 > 192.168.17.22 node3 > > EOF [root@node2 ~]# [root@node3 ~]# cat >> /etc/hosts << EOF > > 192.168.17.20 node1 > 192.168.17.21 node2 > 192.168.17.22 node3 > > EOF [root@node3 ~]#

添加用户

groupadd postgres useradd -g postgres postgres echo "postgres"|passwd --stdin postgres

3台主机都要操作

[root@node1 ~]# groupadd postgres [root@node1 ~]# useradd -g postgres postgres [root@node1 ~]# echo "postgres"|passwd --stdin postgres Changing password for user postgres. passwd: all authentication tokens updated successfully. [root@node1 ~]# [root@node2 ~]# groupadd postgres [root@node2 ~]# useradd -g postgres postgres [root@node2 ~]# echo "postgres"|passwd --stdin postgres Changing password for user postgres. passwd: all authentication tokens updated successfully. [root@node2 ~]# [root@node3 ~]# groupadd postgres [root@node3 ~]# useradd -g postgres postgres [root@node3 ~]# echo "postgres"|passwd --stdin postgres Changing password for user postgres. passwd: all authentication tokens updated successfully. [root@node3 ~]#

创建目录

mkdir -p /opt/pg14 /opt/pgdata /opt/pgarchive chown -R postgres:postgres /opt chmod 0755 /opt/pg14 chmod 0700 /opt/pgdata /opt/pgarchive

3台主机都要操作

[root@node1 ~]# mkdir -p /opt/pg14 /opt/pgdata /opt/pgarchive [root@node1 ~]# chown -R postgres:postgres /opt [root@node1 ~]# chmod 0755 /opt/pg14 [root@node1 ~]# chmod 0700 /opt/pgdata /opt/pgarchive [root@node1 ~]# [root@node2 ~]# mkdir -p /opt/pg14 /opt/pgdata /opt/pgarchive [root@node2 ~]# chown -R postgres:postgres /opt [root@node2 ~]# chmod 0755 /opt/pg14 [root@node2 ~]# chmod 0700 /opt/pgdata /opt/pgarchive [root@node2 ~]# [root@node3 ~]# mkdir -p /opt/pg14 /opt/pgdata /opt/pgarchive [root@node3 ~]# chown -R postgres:postgres /opt [root@node3 ~]# chmod 0755 /opt/pg14 [root@node3 ~]# chmod 0700 /opt/pgdata /opt/pgarchive [root@node3 ~]#

源码编译软件

安装PostgreSQL

把软件包postgresql-14.9.tar.gz上传到/home/postgres目录下

su - postgres tar zxf postgresql-14.9.tar.gz cd postgresql-14.9/ ./configure --prefix=/opt/pg14 gmake world && gmake install-world ln -s /opt/pg14 /opt/pgsql

3台主机都要操作,操作略

配置环境变量

cd ~ cat >> /home/postgres/.bash_profile <<EOF #PostgreSQL settings export PGPORT=5432 export PGUSER=postgres export PGHOME=/opt/pgsql export PGDATA=/opt/pgdata export LD_LIBRARY_PATH=\$PGHOME/lib export PATH=\$PGHOME/bin:\$PATH EOF source /home/postgres/.bash_profile postgres --version

3台主机都要操作

[postgres@node1 postgresql-14.9]$ cd ~ [postgres@node1 ~]$ cat >> /home/postgres/.bash_profile <<EOF > > #PostgreSQL settings > export PGPORT=5432 > export PGUSER=postgres > export PGHOME=/opt/pgsql > export PGDATA=/opt/pgdata > export LD_LIBRARY_PATH=\$PGHOME/lib > export PATH=\$PGHOME/bin:\$PATH > > EOF [postgres@node1 ~]$ source /home/postgres/.bash_profile [postgres@node1 ~]$ postgres --version postgres (PostgreSQL) 14.9 [postgres@node1 ~]$ [postgres@node2 postgresql-14.9]$ cd ~ [postgres@node2 ~]$ cat >> /home/postgres/.bash_profile <<EOF > > #PostgreSQL settings > export PGPORT=5432 > export PGUSER=postgres > export PGHOME=/opt/pgsql > export PGDATA=/opt/pgdata > export LD_LIBRARY_PATH=\$PGHOME/lib > export PATH=\$PGHOME/bin:\$PATH > > EOF [postgres@node2 ~]$ source /home/postgres/.bash_profile [postgres@node2 ~]$ postgres --version postgres (PostgreSQL) 14.9 [postgres@node2 ~]$ [postgres@node3 postgresql-14.9]$ cd ~ [postgres@node3 ~]$ cat >> /home/postgres/.bash_profile <<EOF > > #PostgreSQL settings > export PGPORT=5432 > export PGUSER=postgres > export PGHOME=/opt/pgsql > export PGDATA=/opt/pgdata > export LD_LIBRARY_PATH=\$PGHOME/lib > export PATH=\$PGHOME/bin:\$PATH > > EOF [postgres@node3 ~]$ source /home/postgres/.bash_profile [postgres@node3 ~]$ postgres --version postgres (PostgreSQL) 14.9 [postgres@node3 ~]$

安装etcd

把软件包etcd-3.5.9-1.rhel7.x86_64.rpm上传到/root目录下

yum install -y etcd-3.5.9-1.rhel7.x86_64.rpm cd /etc/etcd/ mkdir data mv etcd.conf etcd.conf.bak cat >> etcd.conf << EOF name: etcd1 data-dir: /etc/etcd/data listen-client-urls: http://0.0.0.0:2379 advertise-client-urls: http://192.168.17.20:2379 listen-peer-urls: http://0.0.0.0:2380 initial-adverties-peer-urls: http://192.168.17.20:2380 initial-cluster: etcd1=http://192.168.17.20:2380,etcd2=http://192.168.17.21:2380,etcd3=http://192.168.17.22:2380 initial-cluster-token: etcd-cluster initial-cluster-state: new enable-v2: true EOF cat /etc/etcd/etcd.conf cat >> /etc/systemd/system/etcd.service << EOF [Unit] Description=Etcd Server After=network.target After=network-online.target Wants=network-online.target [Service] Type=notify WorkingDirectory=/etc/etcd ExecStart=/usr/bin/etcd --config-file /etc/etcd/etcd.conf Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl start etcd.service systemctl status etcd.service etcdctl member list etcdctl endpoint status --write-out=table --endpoints=192.168.17.20:2379,192.168.17.21:2379,192.168.17.22:2379

3台主机都要操作,注意etcd.conf每个节点的IP地址和name都要修改

[root@node1 ~]# cd [root@node1 ~]# yum install -y etcd-3.5.9-1.rhel7.x86_64.rpm Loaded plugins: fastestmirror, langpacks Examining etcd-3.5.9-1.rhel7.x86_64.rpm: etcd-3.5.9-1.rhel7.x86_64 Marking etcd-3.5.9-1.rhel7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package etcd.x86_64 0:3.5.9-1.rhel7 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================== Installing: etcd x86_64 3.5.9-1.rhel7 /etcd-3.5.9-1.rhel7.x86_64 51 M Transaction Summary ==================================================================================================================================== Install 1 Package Total size: 51 M Installed size: 51 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : etcd-3.5.9-1.rhel7.x86_64 1/1 Verifying : etcd-3.5.9-1.rhel7.x86_64 1/1 Installed: etcd.x86_64 0:3.5.9-1.rhel7 Complete! [root@node1 ~]# cd /etc/etcd/ [root@node1 etcd]# mkdir data [root@node1 etcd]# mv etcd.conf etcd.conf.bak [root@node1 etcd]# cat >> etcd.conf << EOF > name: etcd1 > data-dir: /etc/etcd/data > listen-client-urls: http://0.0.0.0:2379 > advertise-client-urls: http://192.168.17.20:2379 > listen-peer-urls: http://0.0.0.0:2380 > initial-adverties-peer-urls: http://192.168.17.20:2380 > initial-cluster: etcd1=http://192.168.17.20:2380,etcd2=http://192.168.17.21:2380,etcd3=http://192.168.17.22:2380 > initial-cluster-token: etcd-cluster > initial-cluster-state: new > enable-v2: true > > EOF [root@node1 etcd]# cat /etc/etcd/etcd.conf name: etcd1 data-dir: /etc/etcd/data listen-client-urls: http://0.0.0.0:2379 advertise-client-urls: http://192.168.17.20:2379 listen-peer-urls: http://0.0.0.0:2380 initial-adverties-peer-urls: http://192.168.17.20:2380 initial-cluster: etcd1=http://192.168.17.20:2380,etcd2=http://192.168.17.21:2380,etcd3=http://192.168.17.22:2380 initial-cluster-token: etcd-cluster initial-cluster-state: new enable-v2: true [root@node1 etcd]# cat >> /etc/systemd/system/etcd.service << EOF > [Unit] > Description=Etcd Server > After=network.target > After=network-online.target > Wants=network-online.target > > [Service] > Type=notify > WorkingDirectory=/etc/etcd > ExecStart=/usr/bin/etcd --config-file /etc/etcd/etcd.conf > Restart=on-failure > LimitNOFILE=65536 > > [Install] > WantedBy=multi-user.target > > EOF [root@node1 etcd]# systemctl daemon-reload [root@node1 etcd]# systemctl start etcd.service [root@node1 etcd]# systemctl status etcd.service ● etcd.service - Etcd Server Loaded: loaded (/etc/systemd/system/etcd.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2023-09-08 23:00:28 CST; 1min 39s ago Main PID: 13019 (etcd) Tasks: 9 CGroup: /system.slice/etcd.service └─13019 /usr/bin/etcd --config-file /etc/etcd/etcd.conf Sep 08 23:01:51 node1 etcd[13019]: {"level":"info","ts":"2023-09-08T23:01:51.717154+0800","caller":"rafthttp/stream.go:274...660b1"} Sep 08 23:01:51 node1 etcd[13019]: {"level":"info","ts":"2023-09-08T23:01:51.717209+0800","caller":"rafthttp/stream.go:249...pp v2"} Sep 08 23:01:51 node1 etcd[13019]: {"level":"info","ts":"2023-09-08T23:01:51.717221+0800","caller":"rafthttp/stream.go:274...660b1"} Sep 08 23:01:51 node1 etcd[13019]: {"level":"info","ts":"2023-09-08T23:01:51.724005+0800","caller":"rafthttp/stream.go:412...660b1"} Sep 08 23:01:51 node1 etcd[13019]: {"level":"info","ts":"2023-09-08T23:01:51.725469+0800","caller":"rafthttp/stream.go:412...660b1"} Sep 08 23:01:52 node1 etcd[13019]: {"level":"warn","ts":"2023-09-08T23:01:52.246682+0800","caller":"rafthttp/probing_statu...fused"} Sep 08 23:01:52 node1 etcd[13019]: {"level":"warn","ts":"2023-09-08T23:01:52.248644+0800","caller":"rafthttp/probing_status.go:68... Sep 08 23:01:52 node1 etcd[13019]: {"level":"info","ts":"2023-09-08T23:01:52.756795+0800","caller":"etcdserver/server.go:2...:"3.5"} Sep 08 23:01:52 node1 etcd[13019]: {"level":"info","ts":"2023-09-08T23:01:52.757564+0800","caller":"membership/cluster.go:...:"3.5"} Sep 08 23:01:52 node1 etcd[13019]: {"level":"info","ts":"2023-09-08T23:01:52.757664+0800","caller":"etcdserver/server.go:2...:"3.5"} Hint: Some lines were ellipsized, use -l to show in full. [root@node1 etcd]# etcdctl member list 2babb66633c7e1d8, started, etcd2, http://192.168.17.21:2380, http://192.168.17.21:2379, false 9ca0e7738d03bf5e, started, etcd1, http://192.168.17.20:2380, http://192.168.17.20:2379, false c33b92e8758660b1, started, etcd3, http://192.168.17.22:2380, http://192.168.17.22:2379, false [root@node1 etcd]# etcdctl endpoint status --write-out=table --endpoints=192.168.17.20:2379,192.168.17.21:2379,192.168.17.22:2379 +--------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+ --------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS | +--------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+ --------+ | 192.168.17.20:2379 | 9ca0e7738d03bf5e | 3.5.9 | 20 kB | true | false | 2 | 9 | 9 | | | 192.168.17.21:2379 | 2babb66633c7e1d8 | 3.5.9 | 20 kB | false | false | 2 | 9 | 9 | | | 192.168.17.22:2379 | c33b92e8758660b1 | 3.5.9 | 20 kB | false | false | 2 | 9 | 9 | | +--------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+ --------+ [root@node1 etcd]# [root@node2 ~]# cd [root@node2 ~]# yum install -y etcd-3.5.9-1.rhel7.x86_64.rpm Loaded plugins: fastestmirror, langpacks Examining etcd-3.5.9-1.rhel7.x86_64.rpm: etcd-3.5.9-1.rhel7.x86_64 Marking etcd-3.5.9-1.rhel7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package etcd.x86_64 0:3.5.9-1.rhel7 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================== Installing: etcd x86_64 3.5.9-1.rhel7 /etcd-3.5.9-1.rhel7.x86_64 51 M Transaction Summary ==================================================================================================================================== Install 1 Package Total size: 51 M Installed size: 51 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : etcd-3.5.9-1.rhel7.x86_64 1/1 Verifying : etcd-3.5.9-1.rhel7.x86_64 1/1 Installed: etcd.x86_64 0:3.5.9-1.rhel7 Complete! [root@node2 ~]# cd /etc/etcd/ [root@node2 etcd]# mkdir data [root@node2 etcd]# mv etcd.conf etcd.conf.bak [root@node2 etcd]# cat >> etcd.conf << EOF > name: etcd2 > data-dir: /etc/etcd/data > listen-client-urls: http://0.0.0.0:2379 > advertise-client-urls: http://192.168.17.21:2379 > listen-peer-urls: http://0.0.0.0:2380 > initial-adverties-peer-urls: http://192.168.17.21:2380 > initial-cluster: etcd1=http://192.168.17.20:2380,etcd2=http://192.168.17.21:2380,etcd3=http://192.168.17.22:2380 > initial-cluster-token: etcd-cluster > initial-cluster-state: new > enable-v2: true > > EOF [root@node2 etcd]# cat /etc/etcd/etcd.conf name: etcd2 data-dir: /etc/etcd/data listen-client-urls: http://0.0.0.0:2379 advertise-client-urls: http://192.168.17.21:2379 listen-peer-urls: http://0.0.0.0:2380 initial-adverties-peer-urls: http://192.168.17.21:2380 initial-cluster: etcd1=http://192.168.17.20:2380,etcd2=http://192.168.17.21:2380,etcd3=http://192.168.17.22:2380 initial-cluster-token: etcd-cluster initial-cluster-state: new enable-v2: true [root@node2 etcd]# cat >> /etc/systemd/system/etcd.service << EOF > [Unit] > Description=Etcd Server > After=network.target > After=network-online.target > Wants=network-online.target > > [Service] > Type=notify > WorkingDirectory=/etc/etcd > ExecStart=/usr/bin/etcd --config-file /etc/etcd/etcd.conf > Restart=on-failure > LimitNOFILE=65536 > > [Install] > WantedBy=multi-user.target > > EOF [root@node2 etcd]# systemctl daemon-reload [root@node2 etcd]# systemctl start etcd.service [root@node2 etcd]# systemctl status etcd.service ● etcd.service - Etcd Server Loaded: loaded (/etc/systemd/system/etcd.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2023-09-08 23:00:28 CST; 1min 39s ago Main PID: 12938 (etcd) Tasks: 9 CGroup: /system.slice/etcd.service └─12938 /usr/bin/etcd --config-file /etc/etcd/etcd.conf Sep 08 23:01:47 node2 etcd[12938]: {"level":"warn","ts":"2023-09-08T23:01:47.545905+0800","caller":"rafthttp/probing_statu...fused"} Sep 08 23:01:47 node2 etcd[12938]: {"level":"warn","ts":"2023-09-08T23:01:47.545954+0800","caller":"rafthttp/probing_status.go:68... Sep 08 23:01:51 node2 etcd[12938]: {"level":"info","ts":"2023-09-08T23:01:51.425378+0800","caller":"rafthttp/stream.go:249...ssage"} Sep 08 23:01:51 node2 etcd[12938]: {"level":"info","ts":"2023-09-08T23:01:51.425406+0800","caller":"rafthttp/peer_status.g...660b1"} Sep 08 23:01:51 node2 etcd[12938]: {"level":"info","ts":"2023-09-08T23:01:51.425418+0800","caller":"rafthttp/stream.go:274...660b1"} Sep 08 23:01:51 node2 etcd[12938]: {"level":"info","ts":"2023-09-08T23:01:51.425462+0800","caller":"rafthttp/stream.go:249...pp v2"} Sep 08 23:01:51 node2 etcd[12938]: {"level":"info","ts":"2023-09-08T23:01:51.425475+0800","caller":"rafthttp/stream.go:274...660b1"} Sep 08 23:01:51 node2 etcd[12938]: {"level":"info","ts":"2023-09-08T23:01:51.439767+0800","caller":"rafthttp/stream.go:412...660b1"} Sep 08 23:01:51 node2 etcd[12938]: {"level":"info","ts":"2023-09-08T23:01:51.439802+0800","caller":"rafthttp/stream.go:412...660b1"} Sep 08 23:01:52 node2 etcd[12938]: {"level":"info","ts":"2023-09-08T23:01:52.466405+0800","caller":"membership/cluster.go:...:"3.5"} Hint: Some lines were ellipsized, use -l to show in full. [root@node2 etcd]# etcdctl member list 2babb66633c7e1d8, started, etcd2, http://192.168.17.21:2380, http://192.168.17.21:2379, false 9ca0e7738d03bf5e, started, etcd1, http://192.168.17.20:2380, http://192.168.17.20:2379, false c33b92e8758660b1, started, etcd3, http://192.168.17.22:2380, http://192.168.17.22:2379, false [root@node2 etcd]# etcdctl endpoint status --write-out=table --endpoints=192.168.17.20:2379,192.168.17.21:2379,192.168.17.22:2379 +--------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+ --------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS | +--------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+ --------+ | 192.168.17.20:2379 | 9ca0e7738d03bf5e | 3.5.9 | 20 kB | true | false | 2 | 9 | 9 | | | 192.168.17.21:2379 | 2babb66633c7e1d8 | 3.5.9 | 20 kB | false | false | 2 | 9 | 9 | | | 192.168.17.22:2379 | c33b92e8758660b1 | 3.5.9 | 20 kB | false | false | 2 | 9 | 9 | | +--------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+ --------+ [root@node2 etcd]# [root@node3 ~]# cd [root@node3 ~]# yum install -y etcd-3.5.9-1.rhel7.x86_64.rpm Loaded plugins: fastestmirror, langpacks Examining etcd-3.5.9-1.rhel7.x86_64.rpm: etcd-3.5.9-1.rhel7.x86_64 Marking etcd-3.5.9-1.rhel7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package etcd.x86_64 0:3.5.9-1.rhel7 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================== Installing: etcd x86_64 3.5.9-1.rhel7 /etcd-3.5.9-1.rhel7.x86_64 51 M Transaction Summary ==================================================================================================================================== Install 1 Package Total size: 51 M Installed size: 51 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : etcd-3.5.9-1.rhel7.x86_64 1/1 Verifying : etcd-3.5.9-1.rhel7.x86_64 1/1 Installed: etcd.x86_64 0:3.5.9-1.rhel7 Complete! [root@node3 ~]# cd /etc/etcd/ [root@node3 etcd]# mkdir data [root@node3 etcd]# mv etcd.conf etcd.conf.bak [root@node3 etcd]# cat >> etcd.conf << EOF > name: etcd3 > data-dir: /etc/etcd/data > listen-client-urls: http://0.0.0.0:2379 > advertise-client-urls: http://192.168.17.22:2379 > listen-peer-urls: http://0.0.0.0:2380 > initial-adverties-peer-urls: http://192.168.17.22:2380 > initial-cluster: etcd1=http://192.168.17.20:2380,etcd2=http://192.168.17.21:2380,etcd3=http://192.168.17.22:2380 > initial-cluster-token: etcd-cluster > initial-cluster-state: new > enable-v2: true > > EOF [root@node3 etcd]# cat /etc/etcd/etcd.conf name: etcd3 data-dir: /etc/etcd/data listen-client-urls: http://0.0.0.0:2379 advertise-client-urls: http://192.168.17.22:2379 listen-peer-urls: http://0.0.0.0:2380 initial-adverties-peer-urls: http://192.168.17.22:2380 initial-cluster: etcd1=http://192.168.17.20:2380,etcd2=http://192.168.17.21:2380,etcd3=http://192.168.17.22:2380 initial-cluster-token: etcd-cluster initial-cluster-state: new enable-v2: true [root@node3 etcd]# cat >> /etc/systemd/system/etcd.service << EOF > [Unit] > Description=Etcd Server > After=network.target > After=network-online.target > Wants=network-online.target > > [Service] > Type=notify > WorkingDirectory=/etc/etcd > ExecStart=/usr/bin/etcd --config-file /etc/etcd/etcd.conf > Restart=on-failure > LimitNOFILE=65536 > > [Install] > WantedBy=multi-user.target > > EOF [root@node3 etcd]# systemctl daemon-reload [root@node3 etcd]# systemctl start etcd.service [root@node3 etcd]# systemctl status etcd.service ● etcd.service - Etcd Server Loaded: loaded (/etc/systemd/system/etcd.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2023-09-08 23:01:51 CST; 16s ago Main PID: 12980 (etcd) Tasks: 9 CGroup: /system.slice/etcd.service └─12980 /usr/bin/etcd --config-file /etc/etcd/etcd.conf Sep 08 23:01:51 node3 etcd[12980]: {"level":"info","ts":"2023-09-08T23:01:51.462193+0800","caller":"rafthttp/stream.go:249...pp v2"} Sep 08 23:01:51 node3 etcd[12980]: {"level":"info","ts":"2023-09-08T23:01:51.462219+0800","caller":"rafthttp/stream.go:274...3bf5e"} Sep 08 23:01:51 node3 etcd[12980]: {"level":"info","ts":"2023-09-08T23:01:51.46221+0800","caller":"rafthttp/stream.go:249"...ssage"} Sep 08 23:01:51 node3 etcd[12980]: {"level":"info","ts":"2023-09-08T23:01:51.462251+0800","caller":"rafthttp/stream.go:274...3bf5e"} Sep 08 23:01:51 node3 etcd[12980]: {"level":"info","ts":"2023-09-08T23:01:51.469227+0800","caller":"rafthttp/stream.go:249...pp v2"} Sep 08 23:01:51 node3 etcd[12980]: {"level":"info","ts":"2023-09-08T23:01:51.469255+0800","caller":"rafthttp/stream.go:274...7e1d8"} Sep 08 23:01:51 node3 etcd[12980]: {"level":"info","ts":"2023-09-08T23:01:51.469234+0800","caller":"rafthttp/stream.go:249...ssage"} Sep 08 23:01:51 node3 etcd[12980]: {"level":"info","ts":"2023-09-08T23:01:51.469267+0800","caller":"rafthttp/stream.go:274...7e1d8"} Sep 08 23:01:51 node3 etcd[12980]: {"level":"info","ts":"2023-09-08T23:01:51.507705+0800","caller":"etcdserver/server.go:777","ms... Sep 08 23:01:52 node3 etcd[12980]: {"level":"info","ts":"2023-09-08T23:01:52.49601+0800","caller":"membership/cluster.go:5...:"3.5"} Hint: Some lines were ellipsized, use -l to show in full. [root@node3 etcd]# etcdctl member list 2babb66633c7e1d8, started, etcd2, http://192.168.17.21:2380, http://192.168.17.21:2379, false 9ca0e7738d03bf5e, started, etcd1, http://192.168.17.20:2380, http://192.168.17.20:2379, false c33b92e8758660b1, started, etcd3, http://192.168.17.22:2380, http://192.168.17.22:2379, false [root@node3 etcd]# etcdctl endpoint status --write-out=table --endpoints=192.168.17.20:2379,192.168.17.21:2379,192.168.17.22:2379 +--------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+ --------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS | +--------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+ --------+ | 192.168.17.20:2379 | 9ca0e7738d03bf5e | 3.5.9 | 20 kB | true | false | 2 | 9 | 9 | | | 192.168.17.21:2379 | 2babb66633c7e1d8 | 3.5.9 | 20 kB | false | false | 2 | 9 | 9 | | | 192.168.17.22:2379 | c33b92e8758660b1 | 3.5.9 | 20 kB | false | false | 2 | 9 | 9 | | +--------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+ --------+ [root@node3 etcd]#

安装watchdog

yum install -y watchdog sed -ri 's/#watchdog-device/watchdog-device/' /etc/watchdog.conf mknod /dev/watchdog c 10 130 modprobe softdog chown postgres /dev/watchdog

3台主机都要操作

[root@node1 etcd]# yum install -y watchdog Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package watchdog.x86_64 0:5.13-12.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================== Installing: watchdog x86_64 5.13-12.el7 base 79 k Transaction Summary ==================================================================================================================================== Install 1 Package Total download size: 79 k Installed size: 160 k Downloading packages: watchdog-5.13-12.el7.x86_64.rpm | 79 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : watchdog-5.13-12.el7.x86_64 1/1 Verifying : watchdog-5.13-12.el7.x86_64 1/1 Installed: watchdog.x86_64 0:5.13-12.el7 Complete! [root@node1 etcd]# sed -ri 's/#watchdog-device/watchdog-device/' /etc/watchdog.conf [root@node1 etcd]# mknod /dev/watchdog c 10 130 [root@node1 etcd]# modprobe softdog [root@node1 etcd]# chown postgres /dev/watchdog [root@node1 etcd]# [root@node2 etcd]# yum install -y watchdog Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package watchdog.x86_64 0:5.13-12.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================== Installing: watchdog x86_64 5.13-12.el7 base 79 k Transaction Summary ==================================================================================================================================== Install 1 Package Total download size: 79 k Installed size: 160 k Downloading packages: watchdog-5.13-12.el7.x86_64.rpm | 79 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : watchdog-5.13-12.el7.x86_64 1/1 Verifying : watchdog-5.13-12.el7.x86_64 1/1 Installed: watchdog.x86_64 0:5.13-12.el7 Complete! [root@node2 etcd]# sed -ri 's/#watchdog-device/watchdog-device/' /etc/watchdog.conf [root@node2 etcd]# mknod /dev/watchdog c 10 130 [root@node2 etcd]# modprobe softdog [root@node2 etcd]# chown postgres /dev/watchdog [root@node2 etcd]# [root@node3 etcd]# yum install -y watchdog Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package watchdog.x86_64 0:5.13-12.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================== Installing: watchdog x86_64 5.13-12.el7 base 79 k Transaction Summary ==================================================================================================================================== Install 1 Package Total download size: 79 k Installed size: 160 k Downloading packages: watchdog-5.13-12.el7.x86_64.rpm | 79 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : watchdog-5.13-12.el7.x86_64 1/1 Verifying : watchdog-5.13-12.el7.x86_64 1/1 Installed: watchdog.x86_64 0:5.13-12.el7 Complete! [root@node3 etcd]# sed -ri 's/#watchdog-device/watchdog-device/' /etc/watchdog.conf [root@node3 etcd]# mknod /dev/watchdog c 10 130 [root@node3 etcd]# modprobe softdog [root@node3 etcd]# chown postgres /dev/watchdog [root@node3 etcd]#

安装patroni

yum install -y python3 python3-devel python3-pip gcc libpq-devel export PGPORT=5432 export PGUSER=postgres export PGHOME=/opt/pgsql export PGDATA=/opt/pgdata export LD_LIBRARY_PATH=$PGHOME/lib export PATH=$PGHOME/bin:$PATH pip3 install patroni[etcd] pip3 install psycopg2-binary

3台主机都要操作

[root@node1 etcd]# yum install -y python3 python3-devel python3-pip gcc libpq-devel Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Package gcc-4.8.5-44.el7.x86_64 already installed and latest version No package libpq-devel available. Resolving Dependencies --> Running transaction check ---> Package python3.x86_64 0:3.6.8-19.el7_9 will be installed --> Processing Dependency: python3-libs(x86-64) = 3.6.8-19.el7_9 for package: python3-3.6.8-19.el7_9.x86_64 --> Processing Dependency: python3-setuptools for package: python3-3.6.8-19.el7_9.x86_64 --> Processing Dependency: libpython3.6m.so.1.0()(64bit) for package: python3-3.6.8-19.el7_9.x86_64 ---> Package python3-devel.x86_64 0:3.6.8-19.el7_9 will be installed --> Processing Dependency: redhat-rpm-config for package: python3-devel-3.6.8-19.el7_9.x86_64 --> Processing Dependency: python3-rpm-macros for package: python3-devel-3.6.8-19.el7_9.x86_64 --> Processing Dependency: python3-rpm-generators for package: python3-devel-3.6.8-19.el7_9.x86_64 --> Processing Dependency: python-rpm-macros for package: python3-devel-3.6.8-19.el7_9.x86_64 ---> Package python3-pip.noarch 0:9.0.3-8.el7 will be installed --> Running transaction check ---> Package python-rpm-macros.noarch 0:3-34.el7 will be installed --> Processing Dependency: python-srpm-macros for package: python-rpm-macros-3-34.el7.noarch ---> Package python3-libs.x86_64 0:3.6.8-19.el7_9 will be installed ---> Package python3-rpm-generators.noarch 0:6-2.el7 will be installed ---> Package python3-rpm-macros.noarch 0:3-34.el7 will be installed ---> Package python3-setuptools.noarch 0:39.2.0-10.el7 will be installed ---> Package redhat-rpm-config.noarch 0:9.1.0-88.el7.centos will be installed --> Processing Dependency: dwz >= 0.4 for package: redhat-rpm-config-9.1.0-88.el7.centos.noarch --> Processing Dependency: perl-srpm-macros for package: redhat-rpm-config-9.1.0-88.el7.centos.noarch --> Running transaction check ---> Package dwz.x86_64 0:0.11-3.el7 will be installed ---> Package perl-srpm-macros.noarch 0:1-8.el7 will be installed ---> Package python-srpm-macros.noarch 0:3-34.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================== Installing: python3 x86_64 3.6.8-19.el7_9 updates 70 k python3-devel x86_64 3.6.8-19.el7_9 updates 217 k python3-pip noarch 9.0.3-8.el7 base 1.6 M Installing for dependencies: dwz x86_64 0.11-3.el7 base 99 k perl-srpm-macros noarch 1-8.el7 base 4.6 k python-rpm-macros noarch 3-34.el7 base 9.1 k python-srpm-macros noarch 3-34.el7 base 8.8 k python3-libs x86_64 3.6.8-19.el7_9 updates 6.9 M python3-rpm-generators noarch 6-2.el7 base 20 k python3-rpm-macros noarch 3-34.el7 base 8.1 k python3-setuptools noarch 39.2.0-10.el7 base 629 k redhat-rpm-config noarch 9.1.0-88.el7.centos base 81 k Transaction Summary ==================================================================================================================================== Install 3 Packages (+9 Dependent packages) Total download size: 9.7 M Installed size: 48 M Downloading packages: (1/12): perl-srpm-macros-1-8.el7.noarch.rpm | 4.6 kB 00:00:00 (2/12): python-rpm-macros-3-34.el7.noarch.rpm | 9.1 kB 00:00:00 (3/12): dwz-0.11-3.el7.x86_64.rpm | 99 kB 00:00:00 (4/12): python-srpm-macros-3-34.el7.noarch.rpm | 8.8 kB 00:00:00 (5/12): python3-3.6.8-19.el7_9.x86_64.rpm | 70 kB 00:00:00 (6/12): python3-devel-3.6.8-19.el7_9.x86_64.rpm | 217 kB 00:00:00 (7/12): python3-libs-3.6.8-19.el7_9.x86_64.rpm | 6.9 MB 00:00:00 (8/12): python3-rpm-generators-6-2.el7.noarch.rpm | 20 kB 00:00:00 (9/12): python3-rpm-macros-3-34.el7.noarch.rpm | 8.1 kB 00:00:00 (10/12): python3-pip-9.0.3-8.el7.noarch.rpm | 1.6 MB 00:00:00 (11/12): python3-setuptools-39.2.0-10.el7.noarch.rpm | 629 kB 00:00:00 (12/12): redhat-rpm-config-9.1.0-88.el7.centos.noarch.rpm | 81 kB 00:00:00 ------------------------------------------------------------------------------------------------------------------------------------ Total 5.6 MB/s | 9.7 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : python3-setuptools-39.2.0-10.el7.noarch 1/12 Installing : python3-pip-9.0.3-8.el7.noarch 2/12 Installing : python3-libs-3.6.8-19.el7_9.x86_64 3/12 Installing : python3-3.6.8-19.el7_9.x86_64 4/12 Installing : python-srpm-macros-3-34.el7.noarch 5/12 Installing : python-rpm-macros-3-34.el7.noarch 6/12 Installing : python3-rpm-generators-6-2.el7.noarch 7/12 Installing : python3-rpm-macros-3-34.el7.noarch 8/12 Installing : dwz-0.11-3.el7.x86_64 9/12 Installing : perl-srpm-macros-1-8.el7.noarch 10/12 Installing : redhat-rpm-config-9.1.0-88.el7.centos.noarch 11/12 Installing : python3-devel-3.6.8-19.el7_9.x86_64 12/12 Verifying : python3-devel-3.6.8-19.el7_9.x86_64 1/12 Verifying : python3-rpm-generators-6-2.el7.noarch 2/12 Verifying : perl-srpm-macros-1-8.el7.noarch 3/12 Verifying : python3-3.6.8-19.el7_9.x86_64 4/12 Verifying : python-rpm-macros-3-34.el7.noarch 5/12 Verifying : dwz-0.11-3.el7.x86_64 6/12 Verifying : python3-rpm-macros-3-34.el7.noarch 7/12 Verifying : python3-setuptools-39.2.0-10.el7.noarch 8/12 Verifying : python3-pip-9.0.3-8.el7.noarch 9/12 Verifying : python-srpm-macros-3-34.el7.noarch 10/12 Verifying : python3-libs-3.6.8-19.el7_9.x86_64 11/12 Verifying : redhat-rpm-config-9.1.0-88.el7.centos.noarch 12/12 Installed: python3.x86_64 0:3.6.8-19.el7_9 python3-devel.x86_64 0:3.6.8-19.el7_9 python3-pip.noarch 0:9.0.3-8.el7 Dependency Installed: dwz.x86_64 0:0.11-3.el7 perl-srpm-macros.noarch 0:1-8.el7 python-rpm-macros.noarch 0:3-34.el7 python-srpm-macros.noarch 0:3-34.el7 python3-libs.x86_64 0:3.6.8-19.el7_9 python3-rpm-generators.noarch 0:6-2.el7 python3-rpm-macros.noarch 0:3-34.el7 python3-setuptools.noarch 0:39.2.0-10.el7 redhat-rpm-config.noarch 0:9.1.0-88.el7.centos Complete! [root@node1 etcd]# echo $LD_LIBRARY_PATH [root@node1 etcd]# export PGPORT=5432 [root@node1 etcd]# export PGUSER=postgres [root@node1 etcd]# export PGHOME=/opt/pgsql [root@node1 etcd]# export PGDATA=/opt/pgdata [root@node1 etcd]# export LD_LIBRARY_PATH=$PGHOME/lib [root@node1 etcd]# export PATH=$PGHOME/bin:$PATH [root@node1 etcd]# pip3 install patroni[etcd] WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead. Collecting patroni[etcd] Downloading https://files.pythonhosted.org/packages/b4/06/bca54e288a9db50fdf7dbd42a7024c439a87eef8501287919743bd49f714/patroni-3.1 .0-py3-none-any.whl (286kB) 100% |████████████████████████████████| 286kB 832kB/s Collecting ydiff>=1.2.0 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/1e/ed/e25e1f4fffbdfd0446f1c45504759e54676da0cde5a844d201181583fce4/ydiff-1.2.t ar.gz (42kB) 100% |████████████████████████████████| 51kB 427kB/s Collecting PyYAML (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/cd/e5/af35f7ea75cf72f2cd079c95ee16797de7cd71f29ea7c68ae5ce7be1eda0/PyYAML-6.0. 1.tar.gz (125kB) 100% |████████████████████████████████| 133kB 614kB/s Collecting prettytable>=0.7 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/9e/6d/40a24eaa03ea4418129708fd3f0f17eda73d568f16d4d4fd412566168b4c/prettytable -2.5.0-py3-none-any.whl Collecting urllib3!=1.21,>=1.19.1 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/c5/05/c214b32d21c0b465506f95c4f28ccbcba15022e000b043b72b3df7728471/urllib3-1.2 6.16-py2.py3-none-any.whl (143kB) 100% |████████████████████████████████| 143kB 566kB/s Collecting python-dateutil (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/36/7a/87837f39d0296e723bb9b62bbb257d0355c7f6128853c78955f57342a56d/python_date util-2.8.2-py2.py3-none-any.whl (247kB) 100% |████████████████████████████████| 256kB 450kB/s Collecting click>=4.1 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/4a/a8/0b2ced25639fb20cc1c9784de90a8c25f9504a7f18cd8b5397bd61696d7d/click-8.0.4 -py3-none-any.whl (97kB) 100% |████████████████████████████████| 102kB 459kB/s Collecting psutil>=2.0.0 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/d6/0f/96b7309212a926c1448366e9ce69b081ea79d63265bde33f11cc9cfc2c07/psutil-5.9. 5.tar.gz (493kB) 100% |████████████████████████████████| 501kB 486kB/s Collecting python-etcd<0.5,>=0.4.3; extra == "etcd" (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/a1/da/616a4d073642da5dd432e5289b7c1cb0963cc5dde23d1ecb8d726821ab41/python-etcd -0.4.5.tar.gz Collecting wcwidth (from prettytable>=0.7->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/20/f4/c0584a25144ce20bfcf1aecd041768b8c762c1eb0aa77502a3f0baa83f11/wcwidth-0.2 .6-py2.py3-none-any.whl Collecting importlib-metadata; python_version < "3.8" (from prettytable>=0.7->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/a0/a1/b153a0a4caf7a7e3f15c2cd56c7702e2cf3d89b1b359d1f1c5e59d68f4ce/importlib_m etadata-4.8.3-py3-none-any.whl Collecting six>=1.5 (from python-dateutil->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0- py2.py3-none-any.whl Collecting dnspython>=1.13.0 (from python-etcd<0.5,>=0.4.3; extra == "etcd"->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/9b/ed/28fb14146c7033ba0e89decd92a4fa16b0b69b84471e2deab3cc4337cc35/dnspython-2 .2.1-py3-none-any.whl (269kB) 100% |████████████████████████████████| 276kB 454kB/s Collecting typing-extensions>=3.6.4; python_version < "3.8" (from importlib-metadata; python_version < "3.8"->prettytable>=0.7->patr oni[etcd]) Downloading https://files.pythonhosted.org/packages/45/6b/44f7f8f1e110027cf88956b59f2fad776cca7e1704396d043f89effd3a0e/typing_exte nsions-4.1.1-py3-none-any.whl Collecting zipp>=0.5 (from importlib-metadata; python_version < "3.8"->prettytable>=0.7->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/bd/df/d4a4974a3e3957fd1c1fa3082366d7fff6e428ddb55f074bf64876f8e8ad/zipp-3.6.0- py3-none-any.whl Installing collected packages: ydiff, PyYAML, wcwidth, typing-extensions, zipp, importlib-metadata, prettytable, urllib3, six, pytho n-dateutil, click, psutil, dnspython, python-etcd, patroni Running setup.py install for ydiff ... done Running setup.py install for PyYAML ... done Running setup.py install for psutil ... done Running setup.py install for python-etcd ... done Successfully installed PyYAML-6.0.1 click-8.0.4 dnspython-2.2.1 importlib-metadata-4.8.3 patroni-3.1.0 prettytable-2.5.0 psutil-5.9. 5 python-dateutil-2.8.2 python-etcd-0.4.5 six-1.16.0 typing-extensions-4.1.1 urllib3-1.26.16 wcwidth-0.2.6 ydiff-1.2 zipp-3.6.0 [root@node1 etcd]# pip3 install psycopg2-binary WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead. Collecting psycopg2-binary Downloading https://files.pythonhosted.org/packages/45/f4/4da1e7f836de4fa3ddb294bb1d4c08daa5cd7b261a6b9a5b50a653a1a29f/psycopg2-bi nary-2.9.7.tar.gz (383kB) 100% |████████████████████████████████| 389kB 876kB/s Installing collected packages: psycopg2-binary Running setup.py install for psycopg2-binary ... done Successfully installed psycopg2-binary-2.9.7 [root@node1 etcd]# [root@node2 etcd]# yum install -y python3 python3-devel python3-pip gcc libpq-devel Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Package gcc-4.8.5-44.el7.x86_64 already installed and latest version No package libpq-devel available. Resolving Dependencies --> Running transaction check ---> Package python3.x86_64 0:3.6.8-19.el7_9 will be installed --> Processing Dependency: python3-libs(x86-64) = 3.6.8-19.el7_9 for package: python3-3.6.8-19.el7_9.x86_64 --> Processing Dependency: python3-setuptools for package: python3-3.6.8-19.el7_9.x86_64 --> Processing Dependency: libpython3.6m.so.1.0()(64bit) for package: python3-3.6.8-19.el7_9.x86_64 ---> Package python3-devel.x86_64 0:3.6.8-19.el7_9 will be installed --> Processing Dependency: redhat-rpm-config for package: python3-devel-3.6.8-19.el7_9.x86_64 --> Processing Dependency: python3-rpm-macros for package: python3-devel-3.6.8-19.el7_9.x86_64 --> Processing Dependency: python3-rpm-generators for package: python3-devel-3.6.8-19.el7_9.x86_64 --> Processing Dependency: python-rpm-macros for package: python3-devel-3.6.8-19.el7_9.x86_64 ---> Package python3-pip.noarch 0:9.0.3-8.el7 will be installed --> Running transaction check ---> Package python-rpm-macros.noarch 0:3-34.el7 will be installed --> Processing Dependency: python-srpm-macros for package: python-rpm-macros-3-34.el7.noarch ---> Package python3-libs.x86_64 0:3.6.8-19.el7_9 will be installed ---> Package python3-rpm-generators.noarch 0:6-2.el7 will be installed ---> Package python3-rpm-macros.noarch 0:3-34.el7 will be installed ---> Package python3-setuptools.noarch 0:39.2.0-10.el7 will be installed ---> Package redhat-rpm-config.noarch 0:9.1.0-88.el7.centos will be installed --> Processing Dependency: dwz >= 0.4 for package: redhat-rpm-config-9.1.0-88.el7.centos.noarch --> Processing Dependency: perl-srpm-macros for package: redhat-rpm-config-9.1.0-88.el7.centos.noarch --> Running transaction check ---> Package dwz.x86_64 0:0.11-3.el7 will be installed ---> Package perl-srpm-macros.noarch 0:1-8.el7 will be installed ---> Package python-srpm-macros.noarch 0:3-34.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================== Installing: python3 x86_64 3.6.8-19.el7_9 updates 70 k python3-devel x86_64 3.6.8-19.el7_9 updates 217 k python3-pip noarch 9.0.3-8.el7 base 1.6 M Installing for dependencies: dwz x86_64 0.11-3.el7 base 99 k perl-srpm-macros noarch 1-8.el7 base 4.6 k python-rpm-macros noarch 3-34.el7 base 9.1 k python-srpm-macros noarch 3-34.el7 base 8.8 k python3-libs x86_64 3.6.8-19.el7_9 updates 6.9 M python3-rpm-generators noarch 6-2.el7 base 20 k python3-rpm-macros noarch 3-34.el7 base 8.1 k python3-setuptools noarch 39.2.0-10.el7 base 629 k redhat-rpm-config noarch 9.1.0-88.el7.centos base 81 k Transaction Summary ==================================================================================================================================== Install 3 Packages (+9 Dependent packages) Total download size: 9.7 M Installed size: 48 M Downloading packages: (1/12): perl-srpm-macros-1-8.el7.noarch.rpm | 4.6 kB 00:00:00 (2/12): python-rpm-macros-3-34.el7.noarch.rpm | 9.1 kB 00:00:00 (3/12): dwz-0.11-3.el7.x86_64.rpm | 99 kB 00:00:00 (4/12): python-srpm-macros-3-34.el7.noarch.rpm | 8.8 kB 00:00:00 (5/12): python3-3.6.8-19.el7_9.x86_64.rpm | 70 kB 00:00:00 (6/12): python3-devel-3.6.8-19.el7_9.x86_64.rpm | 217 kB 00:00:00 (7/12): python3-rpm-generators-6-2.el7.noarch.rpm | 20 kB 00:00:00 (8/12): python3-libs-3.6.8-19.el7_9.x86_64.rpm | 6.9 MB 00:00:00 (9/12): python3-rpm-macros-3-34.el7.noarch.rpm | 8.1 kB 00:00:00 (10/12): python3-setuptools-39.2.0-10.el7.noarch.rpm | 629 kB 00:00:00 (11/12): python3-pip-9.0.3-8.el7.noarch.rpm | 1.6 MB 00:00:00 (12/12): redhat-rpm-config-9.1.0-88.el7.centos.noarch.rpm | 81 kB 00:00:00 ------------------------------------------------------------------------------------------------------------------------------------ Total 6.2 MB/s | 9.7 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : python3-setuptools-39.2.0-10.el7.noarch 1/12 Installing : python3-pip-9.0.3-8.el7.noarch 2/12 Installing : python3-libs-3.6.8-19.el7_9.x86_64 3/12 Installing : python3-3.6.8-19.el7_9.x86_64 4/12 Installing : python-srpm-macros-3-34.el7.noarch 5/12 Installing : python-rpm-macros-3-34.el7.noarch 6/12 Installing : python3-rpm-generators-6-2.el7.noarch 7/12 Installing : python3-rpm-macros-3-34.el7.noarch 8/12 Installing : dwz-0.11-3.el7.x86_64 9/12 Installing : perl-srpm-macros-1-8.el7.noarch 10/12 Installing : redhat-rpm-config-9.1.0-88.el7.centos.noarch 11/12 Installing : python3-devel-3.6.8-19.el7_9.x86_64 12/12 Verifying : python3-devel-3.6.8-19.el7_9.x86_64 1/12 Verifying : python3-rpm-generators-6-2.el7.noarch 2/12 Verifying : perl-srpm-macros-1-8.el7.noarch 3/12 Verifying : python3-3.6.8-19.el7_9.x86_64 4/12 Verifying : python-rpm-macros-3-34.el7.noarch 5/12 Verifying : dwz-0.11-3.el7.x86_64 6/12 Verifying : python3-rpm-macros-3-34.el7.noarch 7/12 Verifying : python3-setuptools-39.2.0-10.el7.noarch 8/12 Verifying : python3-pip-9.0.3-8.el7.noarch 9/12 Verifying : python-srpm-macros-3-34.el7.noarch 10/12 Verifying : python3-libs-3.6.8-19.el7_9.x86_64 11/12 Verifying : redhat-rpm-config-9.1.0-88.el7.centos.noarch 12/12 Installed: python3.x86_64 0:3.6.8-19.el7_9 python3-devel.x86_64 0:3.6.8-19.el7_9 python3-pip.noarch 0:9.0.3-8.el7 Dependency Installed: dwz.x86_64 0:0.11-3.el7 perl-srpm-macros.noarch 0:1-8.el7 python-rpm-macros.noarch 0:3-34.el7 python-srpm-macros.noarch 0:3-34.el7 python3-libs.x86_64 0:3.6.8-19.el7_9 python3-rpm-generators.noarch 0:6-2.el7 python3-rpm-macros.noarch 0:3-34.el7 python3-setuptools.noarch 0:39.2.0-10.el7 redhat-rpm-config.noarch 0:9.1.0-88.el7.centos Complete! [root@node2 etcd]# echo $LD_LIBRARY_PATH [root@node2 etcd]# export PGPORT=5432 [root@node2 etcd]# export PGUSER=postgres [root@node2 etcd]# export PGHOME=/opt/pgsql [root@node2 etcd]# export PGDATA=/opt/pgdata [root@node2 etcd]# export LD_LIBRARY_PATH=$PGHOME/lib [root@node2 etcd]# export PATH=$PGHOME/bin:$PATH [root@node2 etcd]# pip3 install patroni[etcd] WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead. Collecting patroni[etcd] Downloading https://files.pythonhosted.org/packages/b4/06/bca54e288a9db50fdf7dbd42a7024c439a87eef8501287919743bd49f714/patroni-3.1 .0-py3-none-any.whl (286kB) 100% |████████████████████████████████| 286kB 389kB/s Collecting prettytable>=0.7 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/9e/6d/40a24eaa03ea4418129708fd3f0f17eda73d568f16d4d4fd412566168b4c/prettytable -2.5.0-py3-none-any.whl Collecting python-dateutil (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/36/7a/87837f39d0296e723bb9b62bbb257d0355c7f6128853c78955f57342a56d/python_date util-2.8.2-py2.py3-none-any.whl (247kB) 100% |████████████████████████████████| 256kB 906kB/s Collecting ydiff>=1.2.0 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/1e/ed/e25e1f4fffbdfd0446f1c45504759e54676da0cde5a844d201181583fce4/ydiff-1.2.t ar.gz (42kB) 100% |████████████████████████████████| 51kB 1.2MB/s Collecting click>=4.1 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/4a/a8/0b2ced25639fb20cc1c9784de90a8c25f9504a7f18cd8b5397bd61696d7d/click-8.0.4 -py3-none-any.whl (97kB) 100% |████████████████████████████████| 102kB 721kB/s Collecting psutil>=2.0.0 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/d6/0f/96b7309212a926c1448366e9ce69b081ea79d63265bde33f11cc9cfc2c07/psutil-5.9. 5.tar.gz (493kB) 100% |████████████████████████████████| 501kB 702kB/s Collecting urllib3!=1.21,>=1.19.1 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/c5/05/c214b32d21c0b465506f95c4f28ccbcba15022e000b043b72b3df7728471/urllib3-1.2 6.16-py2.py3-none-any.whl (143kB) 100% |████████████████████████████████| 143kB 693kB/s Collecting PyYAML (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/cd/e5/af35f7ea75cf72f2cd079c95ee16797de7cd71f29ea7c68ae5ce7be1eda0/PyYAML-6.0. 1.tar.gz (125kB) 100% |████████████████████████████████| 133kB 578kB/s Collecting python-etcd<0.5,>=0.4.3; extra == "etcd" (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/a1/da/616a4d073642da5dd432e5289b7c1cb0963cc5dde23d1ecb8d726821ab41/python-etcd -0.4.5.tar.gz Collecting wcwidth (from prettytable>=0.7->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/20/f4/c0584a25144ce20bfcf1aecd041768b8c762c1eb0aa77502a3f0baa83f11/wcwidth-0.2 .6-py2.py3-none-any.whl Collecting importlib-metadata; python_version < "3.8" (from prettytable>=0.7->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/a0/a1/b153a0a4caf7a7e3f15c2cd56c7702e2cf3d89b1b359d1f1c5e59d68f4ce/importlib_m etadata-4.8.3-py3-none-any.whl Collecting six>=1.5 (from python-dateutil->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0- py2.py3-none-any.whl Collecting dnspython>=1.13.0 (from python-etcd<0.5,>=0.4.3; extra == "etcd"->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/9b/ed/28fb14146c7033ba0e89decd92a4fa16b0b69b84471e2deab3cc4337cc35/dnspython-2 .2.1-py3-none-any.whl (269kB) 100% |████████████████████████████████| 276kB 256kB/s Collecting typing-extensions>=3.6.4; python_version < "3.8" (from importlib-metadata; python_version < "3.8"->prettytable>=0.7->patr oni[etcd]) Downloading https://files.pythonhosted.org/packages/45/6b/44f7f8f1e110027cf88956b59f2fad776cca7e1704396d043f89effd3a0e/typing_exte nsions-4.1.1-py3-none-any.whl Collecting zipp>=0.5 (from importlib-metadata; python_version < "3.8"->prettytable>=0.7->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/bd/df/d4a4974a3e3957fd1c1fa3082366d7fff6e428ddb55f074bf64876f8e8ad/zipp-3.6.0- py3-none-any.whl Installing collected packages: wcwidth, typing-extensions, zipp, importlib-metadata, prettytable, six, python-dateutil, ydiff, click , psutil, urllib3, PyYAML, dnspython, python-etcd, patroni Running setup.py install for ydiff ... done Running setup.py install for psutil ... done Running setup.py install for PyYAML ... done Running setup.py install for python-etcd ... done Successfully installed PyYAML-6.0.1 click-8.0.4 dnspython-2.2.1 importlib-metadata-4.8.3 patroni-3.1.0 prettytable-2.5.0 psutil-5.9. 5 python-dateutil-2.8.2 python-etcd-0.4.5 six-1.16.0 typing-extensions-4.1.1 urllib3-1.26.16 wcwidth-0.2.6 ydiff-1.2 zipp-3.6.0 [root@node2 etcd]# pip3 install psycopg2-binary WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead. Collecting psycopg2-binary Downloading https://files.pythonhosted.org/packages/45/f4/4da1e7f836de4fa3ddb294bb1d4c08daa5cd7b261a6b9a5b50a653a1a29f/psycopg2-bi nary-2.9.7.tar.gz (383kB) 100% |████████████████████████████████| 389kB 821kB/s Installing collected packages: psycopg2-binary Running setup.py install for psycopg2-binary ... done Successfully installed psycopg2-binary-2.9.7 [root@node2 etcd]# [root@node3 etcd]# yum install -y python3 python3-devel python3-pip gcc libpq-devel Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Package gcc-4.8.5-44.el7.x86_64 already installed and latest version No package libpq-devel available. Resolving Dependencies --> Running transaction check ---> Package python3.x86_64 0:3.6.8-19.el7_9 will be installed --> Processing Dependency: python3-libs(x86-64) = 3.6.8-19.el7_9 for package: python3-3.6.8-19.el7_9.x86_64 --> Processing Dependency: python3-setuptools for package: python3-3.6.8-19.el7_9.x86_64 --> Processing Dependency: libpython3.6m.so.1.0()(64bit) for package: python3-3.6.8-19.el7_9.x86_64 ---> Package python3-devel.x86_64 0:3.6.8-19.el7_9 will be installed --> Processing Dependency: redhat-rpm-config for package: python3-devel-3.6.8-19.el7_9.x86_64 --> Processing Dependency: python3-rpm-macros for package: python3-devel-3.6.8-19.el7_9.x86_64 --> Processing Dependency: python3-rpm-generators for package: python3-devel-3.6.8-19.el7_9.x86_64 --> Processing Dependency: python-rpm-macros for package: python3-devel-3.6.8-19.el7_9.x86_64 ---> Package python3-pip.noarch 0:9.0.3-8.el7 will be installed --> Running transaction check ---> Package python-rpm-macros.noarch 0:3-34.el7 will be installed --> Processing Dependency: python-srpm-macros for package: python-rpm-macros-3-34.el7.noarch ---> Package python3-libs.x86_64 0:3.6.8-19.el7_9 will be installed ---> Package python3-rpm-generators.noarch 0:6-2.el7 will be installed ---> Package python3-rpm-macros.noarch 0:3-34.el7 will be installed ---> Package python3-setuptools.noarch 0:39.2.0-10.el7 will be installed ---> Package redhat-rpm-config.noarch 0:9.1.0-88.el7.centos will be installed --> Processing Dependency: dwz >= 0.4 for package: redhat-rpm-config-9.1.0-88.el7.centos.noarch --> Processing Dependency: perl-srpm-macros for package: redhat-rpm-config-9.1.0-88.el7.centos.noarch --> Running transaction check ---> Package dwz.x86_64 0:0.11-3.el7 will be installed ---> Package perl-srpm-macros.noarch 0:1-8.el7 will be installed ---> Package python-srpm-macros.noarch 0:3-34.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================== Installing: python3 x86_64 3.6.8-19.el7_9 updates 70 k python3-devel x86_64 3.6.8-19.el7_9 updates 217 k python3-pip noarch 9.0.3-8.el7 base 1.6 M Installing for dependencies: dwz x86_64 0.11-3.el7 base 99 k perl-srpm-macros noarch 1-8.el7 base 4.6 k python-rpm-macros noarch 3-34.el7 base 9.1 k python-srpm-macros noarch 3-34.el7 base 8.8 k python3-libs x86_64 3.6.8-19.el7_9 updates 6.9 M python3-rpm-generators noarch 6-2.el7 base 20 k python3-rpm-macros noarch 3-34.el7 base 8.1 k python3-setuptools noarch 39.2.0-10.el7 base 629 k redhat-rpm-config noarch 9.1.0-88.el7.centos base 81 k Transaction Summary ==================================================================================================================================== Install 3 Packages (+9 Dependent packages) Total download size: 9.7 M Installed size: 48 M Downloading packages: (1/12): perl-srpm-macros-1-8.el7.noarch.rpm | 4.6 kB 00:00:00 (2/12): python-rpm-macros-3-34.el7.noarch.rpm | 9.1 kB 00:00:00 (3/12): dwz-0.11-3.el7.x86_64.rpm | 99 kB 00:00:00 (4/12): python-srpm-macros-3-34.el7.noarch.rpm | 8.8 kB 00:00:00 (5/12): python3-3.6.8-19.el7_9.x86_64.rpm | 70 kB 00:00:00 (6/12): python3-devel-3.6.8-19.el7_9.x86_64.rpm | 217 kB 00:00:00 (7/12): python3-rpm-generators-6-2.el7.noarch.rpm | 20 kB 00:00:00 (8/12): python3-libs-3.6.8-19.el7_9.x86_64.rpm | 6.9 MB 00:00:00 (9/12): python3-rpm-macros-3-34.el7.noarch.rpm | 8.1 kB 00:00:00 (10/12): python3-pip-9.0.3-8.el7.noarch.rpm | 1.6 MB 00:00:00 (11/12): python3-setuptools-39.2.0-10.el7.noarch.rpm | 629 kB 00:00:00 (12/12): redhat-rpm-config-9.1.0-88.el7.centos.noarch.rpm | 81 kB 00:00:00 ------------------------------------------------------------------------------------------------------------------------------------ Total 8.3 MB/s | 9.7 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : python3-setuptools-39.2.0-10.el7.noarch 1/12 Installing : python3-pip-9.0.3-8.el7.noarch 2/12 Installing : python3-libs-3.6.8-19.el7_9.x86_64 3/12 Installing : python3-3.6.8-19.el7_9.x86_64 4/12 Installing : python-srpm-macros-3-34.el7.noarch 5/12 Installing : python-rpm-macros-3-34.el7.noarch 6/12 Installing : python3-rpm-generators-6-2.el7.noarch 7/12 Installing : python3-rpm-macros-3-34.el7.noarch 8/12 Installing : dwz-0.11-3.el7.x86_64 9/12 Installing : perl-srpm-macros-1-8.el7.noarch 10/12 Installing : redhat-rpm-config-9.1.0-88.el7.centos.noarch 11/12 Installing : python3-devel-3.6.8-19.el7_9.x86_64 12/12 Verifying : python3-devel-3.6.8-19.el7_9.x86_64 1/12 Verifying : python3-rpm-generators-6-2.el7.noarch 2/12 Verifying : perl-srpm-macros-1-8.el7.noarch 3/12 Verifying : python3-3.6.8-19.el7_9.x86_64 4/12 Verifying : python-rpm-macros-3-34.el7.noarch 5/12 Verifying : dwz-0.11-3.el7.x86_64 6/12 Verifying : python3-rpm-macros-3-34.el7.noarch 7/12 Verifying : python3-setuptools-39.2.0-10.el7.noarch 8/12 Verifying : python3-pip-9.0.3-8.el7.noarch 9/12 Verifying : python-srpm-macros-3-34.el7.noarch 10/12 Verifying : python3-libs-3.6.8-19.el7_9.x86_64 11/12 Verifying : redhat-rpm-config-9.1.0-88.el7.centos.noarch 12/12 Installed: python3.x86_64 0:3.6.8-19.el7_9 python3-devel.x86_64 0:3.6.8-19.el7_9 python3-pip.noarch 0:9.0.3-8.el7 Dependency Installed: dwz.x86_64 0:0.11-3.el7 perl-srpm-macros.noarch 0:1-8.el7 python-rpm-macros.noarch 0:3-34.el7 python-srpm-macros.noarch 0:3-34.el7 python3-libs.x86_64 0:3.6.8-19.el7_9 python3-rpm-generators.noarch 0:6-2.el7 python3-rpm-macros.noarch 0:3-34.el7 python3-setuptools.noarch 0:39.2.0-10.el7 redhat-rpm-config.noarch 0:9.1.0-88.el7.centos Complete! [root@node3 etcd]# echo $LD_LIBRARY_PATH [root@node3 etcd]# export PGPORT=5432 [root@node3 etcd]# export PGUSER=postgres [root@node3 etcd]# export PGHOME=/opt/pgsql [root@node3 etcd]# export PGDATA=/opt/pgdata [root@node3 etcd]# export LD_LIBRARY_PATH=$PGHOME/lib [root@node3 etcd]# export PATH=$PGHOME/bin:$PATH [root@node3 etcd]# pip3 install patroni[etcd] WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead. Collecting patroni[etcd] Downloading https://files.pythonhosted.org/packages/b4/06/bca54e288a9db50fdf7dbd42a7024c439a87eef8501287919743bd49f714/patroni-3.1 .0-py3-none-any.whl (286kB) 100% |████████████████████████████████| 286kB 3.6MB/s Collecting urllib3!=1.21,>=1.19.1 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/c5/05/c214b32d21c0b465506f95c4f28ccbcba15022e000b043b72b3df7728471/urllib3-1.2 6.16-py2.py3-none-any.whl (143kB) 100% |████████████████████████████████| 143kB 7.6MB/s Collecting PyYAML (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/cd/e5/af35f7ea75cf72f2cd079c95ee16797de7cd71f29ea7c68ae5ce7be1eda0/PyYAML-6.0. 1.tar.gz (125kB) 100% |████████████████████████████████| 133kB 7.5MB/s Collecting python-dateutil (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/36/7a/87837f39d0296e723bb9b62bbb257d0355c7f6128853c78955f57342a56d/python_date util-2.8.2-py2.py3-none-any.whl (247kB) 100% |████████████████████████████████| 256kB 5.5MB/s Collecting prettytable>=0.7 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/9e/6d/40a24eaa03ea4418129708fd3f0f17eda73d568f16d4d4fd412566168b4c/prettytable -2.5.0-py3-none-any.whl Collecting ydiff>=1.2.0 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/1e/ed/e25e1f4fffbdfd0446f1c45504759e54676da0cde5a844d201181583fce4/ydiff-1.2.t ar.gz (42kB) 100% |████████████████████████████████| 51kB 13.1MB/s Collecting click>=4.1 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/4a/a8/0b2ced25639fb20cc1c9784de90a8c25f9504a7f18cd8b5397bd61696d7d/click-8.0.4 -py3-none-any.whl (97kB) 100% |████████████████████████████████| 102kB 13.1MB/s Collecting psutil>=2.0.0 (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/d6/0f/96b7309212a926c1448366e9ce69b081ea79d63265bde33f11cc9cfc2c07/psutil-5.9. 5.tar.gz (493kB) 100% |████████████████████████████████| 501kB 4.1MB/s Collecting python-etcd<0.5,>=0.4.3; extra == "etcd" (from patroni[etcd]) Downloading https://files.pythonhosted.org/packages/a1/da/616a4d073642da5dd432e5289b7c1cb0963cc5dde23d1ecb8d726821ab41/python-etcd -0.4.5.tar.gz Collecting six>=1.5 (from python-dateutil->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0- py2.py3-none-any.whl Collecting wcwidth (from prettytable>=0.7->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/20/f4/c0584a25144ce20bfcf1aecd041768b8c762c1eb0aa77502a3f0baa83f11/wcwidth-0.2 .6-py2.py3-none-any.whl Collecting importlib-metadata; python_version < "3.8" (from prettytable>=0.7->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/a0/a1/b153a0a4caf7a7e3f15c2cd56c7702e2cf3d89b1b359d1f1c5e59d68f4ce/importlib_m etadata-4.8.3-py3-none-any.whl Collecting dnspython>=1.13.0 (from python-etcd<0.5,>=0.4.3; extra == "etcd"->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/9b/ed/28fb14146c7033ba0e89decd92a4fa16b0b69b84471e2deab3cc4337cc35/dnspython-2 .2.1-py3-none-any.whl (269kB) 100% |████████████████████████████████| 276kB 6.7MB/s Collecting zipp>=0.5 (from importlib-metadata; python_version < "3.8"->prettytable>=0.7->patroni[etcd]) Downloading https://files.pythonhosted.org/packages/bd/df/d4a4974a3e3957fd1c1fa3082366d7fff6e428ddb55f074bf64876f8e8ad/zipp-3.6.0- py3-none-any.whl Collecting typing-extensions>=3.6.4; python_version < "3.8" (from importlib-metadata; python_version < "3.8"->prettytable>=0.7->patr oni[etcd]) Downloading https://files.pythonhosted.org/packages/45/6b/44f7f8f1e110027cf88956b59f2fad776cca7e1704396d043f89effd3a0e/typing_exte nsions-4.1.1-py3-none-any.whl Installing collected packages: urllib3, PyYAML, six, python-dateutil, wcwidth, zipp, typing-extensions, importlib-metadata, prettyta ble, ydiff, click, psutil, dnspython, python-etcd, patroni Running setup.py install for PyYAML ... done Running setup.py install for ydiff ... done Running setup.py install for psutil ... done Running setup.py install for python-etcd ... done Successfully installed PyYAML-6.0.1 click-8.0.4 dnspython-2.2.1 importlib-metadata-4.8.3 patroni-3.1.0 prettytable-2.5.0 psutil-5.9. 5 python-dateutil-2.8.2 python-etcd-0.4.5 six-1.16.0 typing-extensions-4.1.1 urllib3-1.26.16 wcwidth-0.2.6 ydiff-1.2 zipp-3.6.0 [root@node3 etcd]# pip3 install psycopg2-binary WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead. Collecting psycopg2-binary Downloading https://files.pythonhosted.org/packages/45/f4/4da1e7f836de4fa3ddb294bb1d4c08daa5cd7b261a6b9a5b50a653a1a29f/psycopg2-bi nary-2.9.7.tar.gz (383kB) 100% |████████████████████████████████| 389kB 861kB/s Installing collected packages: psycopg2-binary Running setup.py install for psycopg2-binary ... done Successfully installed psycopg2-binary-2.9.7 [root@node3 etcd]#

配置patroni

mkdir -p /etc/patroni/ cd /etc/patroni/ cat >> patroni.yml << EOF scope: pg_cluster namespace: /service/ name: pg1 restapi: listen: 0.0.0.0:8008 connect_address: 192.168.17.20:8008 etcd: hosts: 192.168.17.20:2379,192.168.17.21:2379,192.168.17.22:2379 bootstrap: dcs: ttl: 30 loop_wait: 10 retry_timeout: 10 maximum_lag_on_failover: 1048576 postgresql: use_pg_rewind: true use_slots: true parameters: initdb: - encoding: UTF8 - data-checksums pg_hba: - host replication replicator 127.0.0.1/32 md5 - host replication replicator 192.168.17.20/32 md5 - host replication replicator 192.168.17.21/32 md5 - host replication replicator 192.168.17.22/32 md5 - host all all 0.0.0.0/0 md5 users: admin: password: admin options: - createrole - createdb postgresql: listen: 192.168.17.20:5432 connect_address: 192.168.17.20:5432 data_dir: /opt/pgdata bin_dir: /opt/pgsql/bin pgpass: /tmp/pgpass authentication: replication: username: replicator password: replicator superuser: username: postgres password: postgres watchdog: mode: required device: /dev/watchdog safety_margin: 5 tags: nofailover: false noloadbalance: false clonefrom: false nosync: false EOF cat >> /etc/systemd/system/patroni.service << EOF [Unit] Description=patroni - a high-availability PostgreSQL Documentation=https://patroni.readthedocs.io/en/latest/index.html After=syslog.target network.target etcd.target Wants=network-online.target [Service] Type=simple User=postgres Group=postgres PermissionsStartOnly=true Environment="LD_LIBRARY_PATH=/opt/pgsql/lib" ExecStart=/usr/local/bin/patroni /etc/patroni/patroni.yml ExecReload=/bin/kill -HUP $MAINPID LimitNOFILE=65536 KillMode=process KillSignal=SIGINT Restart=on-abnormal RestartSec=30s TimeoutSec=0 [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl start patroni.service systemctl status patroni.service su - postgres patronictl -c /etc/patroni/patroni.yml list

3台机器都要操作,注意patroni.yml每个节点的IP地址和name都要修改

[root@node1 etcd]# mkdir -p /etc/patroni/ [root@node1 etcd]# cd /etc/patroni/ [root@node1 patroni]# cat >> patroni.yml << EOF > scope: pg_cluster > namespace: /service/ > name: pg1 > > restapi: > listen: 0.0.0.0:8008 > connect_address: 192.168.17.20:8008 > > etcd: > hosts: 192.168.17.20:2379,192.168.17.21:2379,192.168.17.22:2379 > > bootstrap: > dcs: > ttl: 30 > loop_wait: 10 > retry_timeout: 10 > maximum_lag_on_failover: 1048576 > postgresql: > use_pg_rewind: true > use_slots: true > parameters: > > initdb: > - encoding: UTF8 > - data-checksums > > pg_hba: > - host replication replicator 127.0.0.1/32 md5 > - host replication replicator 192.168.17.20/32 md5 > - host replication replicator 192.168.17.21/32 md5 > - host replication replicator 192.168.17.22/32 md5 > - host all all 0.0.0.0/0 md5 > > users: > admin: > password: admin > options: > - createrole > - createdb > > postgresql: > listen: 192.168.17.20:5432 > connect_address: 192.168.17.20:5432 > data_dir: /opt/pgdata > bin_dir: /opt/pgsql/bin > pgpass: /tmp/pgpass > authentication: > replication: > username: replicator > password: replicator > superuser: > username: postgres > password: postgres > > watchdog: > mode: required > device: /dev/watchdog > safety_margin: 5 > > tags: > nofailover: false > noloadbalance: false > clonefrom: false > nosync: false > > EOF [root@node1 patroni]# cat >> /etc/systemd/system/patroni.service << EOF > [Unit] > Description=patroni - a high-availability PostgreSQL > Documentation=https://patroni.readthedocs.io/en/latest/index.html > After=syslog.target network.target etcd.target > Wants=network-online.target > > [Service] > Type=simple > User=postgres > Group=postgres > PermissionsStartOnly=true > Environment="LD_LIBRARY_PATH=/opt/pgsql/lib" > ExecStart=/usr/local/bin/patroni /etc/patroni/patroni.yml > ExecReload=/bin/kill -HUP $MAINPID > LimitNOFILE=65536 > KillMode=process > KillSignal=SIGINT > Restart=on-abnormal > RestartSec=30s > TimeoutSec=0 > > [Install] > WantedBy=multi-user.target > > EOF [root@node1 patroni]# systemctl daemon-reload [root@node1 patroni]# systemctl start patroni.service [root@node1 patroni]# systemctl status patroni.service ● patroni.service - patroni - a high-availability PostgreSQL Loaded: loaded (/etc/systemd/system/patroni.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2023-09-08 23:38:02 CST; 41s ago Docs: https://patroni.readthedocs.io/en/latest/index.html Main PID: 14038 (patroni) Tasks: 15 CGroup: /system.slice/patroni.service ├─14038 /usr/bin/python3 /usr/local/bin/patroni /etc/patroni/patroni.yml ├─14079 /opt/pgsql/bin/postgres -D /opt/pgdata --config-file=/opt/pgdata/postgresql.conf --listen_addresses=192.168.17.20 --port=5432 --cluster_name=pg_cluster --wal_level=replica --hot_standby=on --max_connections=100 --max_wal_senders=10 --max_prepared_... ├─14081 postgres: pg_cluster: checkpointer ├─14082 postgres: pg_cluster: background writer ├─14083 postgres: pg_cluster: walwriter ├─14084 postgres: pg_cluster: autovacuum launcher ├─14085 postgres: pg_cluster: stats collector ├─14086 postgres: pg_cluster: logical replication launcher ├─14091 postgres: pg_cluster: postgres postgres 192.168.17.20(46620) idle ├─14103 postgres: pg_cluster: walsender replicator 192.168.17.21(47634) streaming 0/4000060 └─14104 postgres: pg_cluster: walsender replicator 192.168.17.22(48736) streaming 0/4000060 Sep 08 23:38:09 node1 patroni[14038]: 2023-09-08 23:38:09.964 CST [14097] STATEMENT: START_REPLICATION SLOT "pg2" 0/3000000 TIMELINE 1 Sep 08 23:38:09 node1 patroni[14038]: 2023-09-08 23:38:09.971 CST [14098] ERROR: replication slot "pg2" does not exist Sep 08 23:38:09 node1 patroni[14038]: 2023-09-08 23:38:09.971 CST [14098] STATEMENT: START_REPLICATION SLOT "pg2" 0/3000000 TIMELINE 1 Sep 08 23:38:12 node1 patroni[14038]: 2023-09-08 23:38:12.418 CST [14101] ERROR: replication slot "pg3" does not exist Sep 08 23:38:12 node1 patroni[14038]: 2023-09-08 23:38:12.418 CST [14101] STATEMENT: START_REPLICATION SLOT "pg3" 0/4000000 TIMELINE 1 Sep 08 23:38:12 node1 patroni[14038]: 2023-09-08 23:38:12.425 CST [14102] ERROR: replication slot "pg3" does not exist Sep 08 23:38:12 node1 patroni[14038]: 2023-09-08 23:38:12.425 CST [14102] STATEMENT: START_REPLICATION SLOT "pg3" 0/4000000 TIMELINE 1 Sep 08 23:38:14 node1 patroni[14038]: 2023-09-08 23:38:14,847 INFO: no action. I am (pg1), the leader with the lock Sep 08 23:38:24 node1 patroni[14038]: 2023-09-08 23:38:24,844 INFO: no action. I am (pg1), the leader with the lock Sep 08 23:38:34 node1 patroni[14038]: 2023-09-08 23:38:34,842 INFO: no action. I am (pg1), the leader with the lock [root@node1 patroni]# su - postgres Last login: Fri Sep 8 23:14:26 CST 2023 on pts/1 [postgres@node1 ~]$ patronictl -c /etc/patroni/patroni.yml list + Cluster: pg_cluster ---+---------+-----------+----+-----------+ | Member | Host | Role | State | TL | Lag in MB | +--------+---------------+---------+-----------+----+-----------+ | pg1 | 192.168.17.20 | Leader | running | 1 | | | pg2 | 192.168.17.21 | Replica | streaming | 1 | 0 | | pg3 | 192.168.17.22 | Replica | streaming | 1 | 0 | +--------+---------------+---------+-----------+----+-----------+ [postgres@node1 ~]$ [root@node2 etcd]# mkdir -p /etc/patroni/ [root@node2 etcd]# cd /etc/patroni/ [root@node2 patroni]# cat >> patroni.yml << EOF > scope: pg_cluster > namespace: /service/ > name: pg2 > > restapi: > listen: 0.0.0.0:8008 > connect_address: 192.168.17.21:8008 > > etcd: > hosts: 192.168.17.20:2379,192.168.17.21:2379,192.168.17.22:2379 > > bootstrap: > dcs: > ttl: 30 > loop_wait: 10 > retry_timeout: 10 > maximum_lag_on_failover: 1048576 > postgresql: > use_pg_rewind: true > use_slots: true > parameters: > > initdb: > - encoding: UTF8 > - data-checksums > > pg_hba: > - host replication replicator 127.0.0.1/32 md5 > - host replication replicator 192.168.17.20/32 md5 > - host replication replicator 192.168.17.21/32 md5 > - host replication replicator 192.168.17.22/32 md5 > - host all all 0.0.0.0/0 md5 > > users: > admin: > password: admin > options: > - createrole > - createdb > > postgresql: > listen: 192.168.17.21:5432 > connect_address: 192.168.17.21:5432 > data_dir: /opt/pgdata > bin_dir: /opt/pgsql/bin > pgpass: /tmp/pgpass > authentication: > replication: > username: replicator > password: replicator > superuser: > username: postgres > password: postgres > > watchdog: > mode: required > device: /dev/watchdog > safety_margin: 5 > > tags: > nofailover: false > noloadbalance: false > clonefrom: false > nosync: false > > EOF [root@node2 patroni]# [root@node2 patroni]# cat >> /etc/systemd/system/patroni.service << EOF > [Unit] > Description=patroni - a high-availability PostgreSQL > Documentation=https://patroni.readthedocs.io/en/latest/index.html > After=syslog.target network.target etcd.target > Wants=network-online.target > > [Service] > Type=simple > User=postgres > Group=postgres > PermissionsStartOnly=true > Environment="LD_LIBRARY_PATH=/opt/pgsql/lib" > ExecStart=/usr/local/bin/patroni /etc/patroni/patroni.yml > ExecReload=/bin/kill -HUP $MAINPID > LimitNOFILE=65536 > KillMode=process > KillSignal=SIGINT > Restart=on-abnormal > RestartSec=30s > TimeoutSec=0 > > [Install] > WantedBy=multi-user.target > > EOF [root@node2 patroni]# [root@node2 patroni]# systemctl daemon-reload [root@node2 patroni]# systemctl start patroni.service [root@node2 patroni]# systemctl status patroni.service ● patroni.service - patroni - a high-availability PostgreSQL Loaded: loaded (/etc/systemd/system/patroni.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2023-09-08 23:38:08 CST; 48s ago Docs: https://patroni.readthedocs.io/en/latest/index.html Main PID: 66290 (patroni) Tasks: 12 CGroup: /system.slice/patroni.service ├─66290 /usr/bin/python3 /usr/local/bin/patroni /etc/patroni/patroni.yml ├─66330 /opt/pgsql/bin/postgres -D /opt/pgdata --config-file=/opt/pgdata/postgresql.conf --listen_addresses=192.168.17.21 --port=5432 --cluster_name=pg_cluster --wal_level=replica --hot_standby=on --max_connections=100 --max_wal_senders=10 --max_prepared_... ├─66332 postgres: pg_cluster: startup recovering 000000010000000000000004 ├─66336 postgres: pg_cluster: checkpointer ├─66337 postgres: pg_cluster: background writer ├─66338 postgres: pg_cluster: stats collector ├─66344 postgres: pg_cluster: postgres postgres 192.168.17.21(33360) idle └─66346 postgres: pg_cluster: walreceiver streaming 0/4000060 Sep 08 23:38:10 node2 patroni[66290]: 192.168.17.21:5432 - accepting connections Sep 08 23:38:10 node2 patroni[66290]: 2023-09-08 23:38:10,678 INFO: Lock owner: pg1; I am pg2 Sep 08 23:38:10 node2 patroni[66290]: 2023-09-08 23:38:10,678 INFO: establishing a new patroni connection to the postgres cluster Sep 08 23:38:10 node2 patroni[66290]: 2023-09-08 23:38:10,695 INFO: no action. I am (pg2), a secondary, and following a leader (pg1) Sep 08 23:38:14 node2 patroni[66290]: 2023-09-08 23:38:14,564 INFO: no action. I am (pg2), a secondary, and following a leader (pg1) Sep 08 23:38:14 node2 patroni[66290]: 2023-09-08 23:38:14.698 CST [66346] LOG: started streaming WAL from primary at 0/3000000 on timeline 1 Sep 08 23:38:24 node2 patroni[66290]: 2023-09-08 23:38:24,563 INFO: no action. I am (pg2), a secondary, and following a leader (pg1) Sep 08 23:38:34 node2 patroni[66290]: 2023-09-08 23:38:34,563 INFO: no action. I am (pg2), a secondary, and following a leader (pg1) Sep 08 23:38:44 node2 patroni[66290]: 2023-09-08 23:38:44,562 INFO: no action. I am (pg2), a secondary, and following a leader (pg1) Sep 08 23:38:54 node2 patroni[66290]: 2023-09-08 23:38:54,562 INFO: no action. I am (pg2), a secondary, and following a leader (pg1) [root@node2 patroni]# [root@node3 etcd]# mkdir -p /etc/patroni/ [root@node3 etcd]# cd /etc/patroni/ [root@node3 patroni]# cat >> patroni.yml << EOF > scope: pg_cluster > namespace: /service/ > name: pg3 > > restapi: > listen: 0.0.0.0:8008 > connect_address: 192.168.17.22:8008 > > etcd: > hosts: 192.168.17.20:2379,192.168.17.21:2379,192.168.17.22:2379 > > bootstrap: > dcs: > ttl: 30 > loop_wait: 10 > retry_timeout: 10 > maximum_lag_on_failover: 1048576 > postgresql: > use_pg_rewind: true > use_slots: true > parameters: > > initdb: > - encoding: UTF8 > - data-checksums > > pg_hba: > - host replication replicator 127.0.0.1/32 md5 > - host replication replicator 192.168.17.20/32 md5 > - host replication replicator 192.168.17.21/32 md5 > - host replication replicator 192.168.17.22/32 md5 > - host all all 0.0.0.0/0 md5 > > users: > admin: > password: admin > options: > - createrole > - createdb > > postgresql: > listen: 192.168.17.22:5432 > connect_address: 192.168.17.22:5432 > data_dir: /opt/pgdata > bin_dir: /opt/pgsql/bin > pgpass: /tmp/pgpass > authentication: > replication: > username: replicator > password: replicator > superuser: > username: postgres > password: postgres > > watchdog: > mode: required > device: /dev/watchdog > safety_margin: 5 > > tags: > nofailover: false > noloadbalance: false > clonefrom: false > nosync: false > > EOF [root@node3 patroni]# [root@node3 patroni]# cat >> /etc/systemd/system/patroni.service << EOF > [Unit] > Description=patroni - a high-availability PostgreSQL > Documentation=https://patroni.readthedocs.io/en/latest/index.html > After=syslog.target network.target etcd.target > Wants=network-online.target > > [Service] > Type=simple > User=postgres > Group=postgres > PermissionsStartOnly=true > Environment="LD_LIBRARY_PATH=/opt/pgsql/lib" > ExecStart=/usr/local/bin/patroni /etc/patroni/patroni.yml > ExecReload=/bin/kill -HUP $MAINPID > LimitNOFILE=65536 > KillMode=process > KillSignal=SIGINT > Restart=on-abnormal > RestartSec=30s > TimeoutSec=0 > > [Install] > WantedBy=multi-user.target > > EOF [root@node3 patroni]# [root@node3 patroni]# systemctl daemon-reload [root@node3 patroni]# systemctl start patroni.service [root@node3 patroni]# systemctl status patroni.service ● patroni.service - patroni - a high-availability PostgreSQL Loaded: loaded (/etc/systemd/system/patroni.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2023-09-08 23:38:11 CST; 49s ago Docs: https://patroni.readthedocs.io/en/latest/index.html Main PID: 66275 (patroni) Tasks: 12 CGroup: /system.slice/patroni.service ├─66275 /usr/bin/python3 /usr/local/bin/patroni /etc/patroni/patroni.yml ├─66315 /opt/pgsql/bin/postgres -D /opt/pgdata --config-file=/opt/pgdata/postgresql.conf --listen_addresses=192.168.17.22 --port=5432 --cluster_name=pg_cluster --wal_level=replica --hot_standby=on --max_connections=100 --max_wal_senders=10 --max_prepared_... ├─66316 postgres: pg_cluster: startup recovering 000000010000000000000004 ├─66317 postgres: pg_cluster: checkpointer ├─66318 postgres: pg_cluster: background writer ├─66319 postgres: pg_cluster: stats collector ├─66327 postgres: pg_cluster: postgres postgres 192.168.17.22(60362) idle └─66337 postgres: pg_cluster: walreceiver streaming 0/4000060 Sep 08 23:38:12 node3 patroni[66275]: 2023-09-08 23:38:12,158 INFO: Lock owner: pg1; I am pg3 Sep 08 23:38:12 node3 patroni[66275]: 2023-09-08 23:38:12,159 INFO: establishing a new patroni connection to the postgres cluster Sep 08 23:38:12 node3 patroni[66275]: 2023-09-08 23:38:12.163 CST [66326] FATAL: could not start WAL streaming: ERROR: replication slot "pg3" does not exist Sep 08 23:38:12 node3 patroni[66275]: 2023-09-08 23:38:12,177 INFO: no action. I am (pg3), a secondary, and following a leader (pg1) Sep 08 23:38:14 node3 patroni[66275]: 2023-09-08 23:38:14,594 INFO: no action. I am (pg3), a secondary, and following a leader (pg1) Sep 08 23:38:17 node3 patroni[66275]: 2023-09-08 23:38:17.170 CST [66337] LOG: started streaming WAL from primary at 0/4000000 on timeline 1 Sep 08 23:38:24 node3 patroni[66275]: 2023-09-08 23:38:24,593 INFO: no action. I am (pg3), a secondary, and following a leader (pg1) Sep 08 23:38:34 node3 patroni[66275]: 2023-09-08 23:38:34,593 INFO: no action. I am (pg3), a secondary, and following a leader (pg1) Sep 08 23:38:44 node3 patroni[66275]: 2023-09-08 23:38:44,592 INFO: no action. I am (pg3), a secondary, and following a leader (pg1) Sep 08 23:38:54 node3 patroni[66275]: 2023-09-08 23:38:54,592 INFO: no action. I am (pg3), a secondary, and following a leader (pg1) [root@node3 patroni]#

至此安装patroni+etcd过程已经完成

测试

手动切换测试

在守护者集群中,当领导节点因意外原因不可用时,会自动执行故障转移。如果要手动测试守护者集群故障转移,可以使用以下命令启动到副本节点的故障转移

su - postgres #查询当前集群状态 patronictl -c /etc/patroni/patroni.yml list #手动切换,选择新的领导节点 patronictl -c /etc/patroni/patroni.yml failover #再次查询当前集群状态 patronictl -c /etc/patroni/patroni.yml list

测试如下:

[root@node1 patroni]# su - postgres Last login: Fri Sep 8 23:39:48 CST 2023 on pts/0 [postgres@node1 ~]$ patronictl -c /etc/patroni/patroni.yml list + Cluster: pg_cluster ---+---------+-----------+----+-----------+ | Member | Host | Role | State | TL | Lag in MB | +--------+---------------+---------+-----------+----+-----------+ | pg1 | 192.168.17.20 | Leader | running | 1 | | | pg2 | 192.168.17.21 | Replica | streaming | 1 | 0 | | pg3 | 192.168.17.22 | Replica | streaming | 1 | 0 | +--------+---------------+---------+-----------+----+-----------+ [postgres@node1 ~]$ patronictl -c /etc/patroni/patroni.yml failover Current cluster topology + Cluster: pg_cluster ---+---------+-----------+----+-----------+ | Member | Host | Role | State | TL | Lag in MB | +--------+---------------+---------+-----------+----+-----------+ | pg1 | 192.168.17.20 | Leader | running | 1 | | | pg2 | 192.168.17.21 | Replica | streaming | 1 | 0 | | pg3 | 192.168.17.22 | Replica | streaming | 1 | 0 | +--------+---------------+---------+-----------+----+-----------+ Candidate ['pg2', 'pg3'] []: pg2 Are you sure you want to failover cluster pg_cluster, demoting current leader pg1? [y/N]: y 2023-09-08 23:49:23.31022 Successfully failed over to "pg2" + Cluster: pg_cluster ---+---------+-----------+----+-----------+ | Member | Host | Role | State | TL | Lag in MB | +--------+---------------+---------+-----------+----+-----------+ | pg1 | 192.168.17.20 | Replica | stopped | | unknown | | pg2 | 192.168.17.21 | Leader | running | 1 | | | pg3 | 192.168.17.22 | Replica | streaming | 1 | 0 | +--------+---------------+---------+-----------+----+-----------+ [postgres@node1 ~]$ patronictl -c /etc/patroni/patroni.yml list + Cluster: pg_cluster ---+---------+-----------+----+-----------+ | Member | Host | Role | State | TL | Lag in MB | +--------+---------------+---------+-----------+----+-----------+ | pg1 | 192.168.17.20 | Replica | streaming | 2 | 0 | | pg2 | 192.168.17.21 | Leader | running | 2 | | | pg3 | 192.168.17.22 | Replica | streaming | 2 | 0 | +--------+---------------+---------+-----------+----+-----------+ [postgres@node1 ~]$

查询所有历史的切换操作

[postgres@node1 ~]$ patronictl -c /etc/patroni/patroni.yml history +----+----------+------------------------------+----------------------------------+------------+ | TL | LSN | Reason | Timestamp | New Leader | +----+----------+------------------------------+----------------------------------+------------+ | 1 | 67109488 | no recovery target specified | 2023-09-08T23:49:22.321969+08:00 | pg2 | +----+----------+------------------------------+----------------------------------+------------+ [postgres@node1 ~]$

测试同步

创建数据库testdb,在testdb里创建表t,查询从库是否同步

[postgres@node1 ~]$ psql -h node2
Password for user postgres:
psql (14.9)
Type "help" for help.

postgres=# create database testdb;
CREATE DATABASE
postgres=# \c testdb
You are now connected to database "testdb" as user "postgres".
testdb=# create table t (id int);
CREATE TABLE
testdb=# insert into t values(1),(2),(3);
INSERT 0 3
testdb=# select * from t;
 id
----
  1
  2
  3
(3 rows)

testdb=# \q
[postgres@node1 ~]$ psql -h node3 -d testdb -c "select * from t;"
Password for user postgres:
 id
----
  1
  2
  3
(3 rows)

[postgres@node1 ~]$

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论