|
2025年5月份开始学习PG数据库,当时入门学习的第一本书就是赵老师postgres实战派,里面的实战案例很多,在使用pgautofailover扩展部署高可用集群总是失败,一时陷入了困境。后来在PG社区发了一个提问,波罗老师推荐了“小白学信创”公众号一篇文章,在此非常感谢波罗老师和“小白学信创”提供的帮助和部署思路。
首先介绍一下本次部署的所用各种软件工具和思路梳理,
1、使用YUM安装的方式安装PG17,但没有进行初始化,也没有设置数据库服务的启动类别。安装用的脚本如下,是从PG官网复制下来的,最好你的各个节点处于联网状态。
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql17-server
2、使用了三哥的SSH互信脚本进行部署postgres用户的互信,这个脚本大大减少了建立SSH互信的工作量,使用前记得关闭操作系统的防火墙和SELINUX的设置,也要记得所有节点都要安装expect和nc工具,三哥的脚本要用到那两个工具。集群是用SSH互相进行集群的管理和数据、日志维护,这个是重点。
3、使用冯若航大佬的开源工具pig,进行扩展的自动安装。冯哥的pig工具功能强大,集成了众多扩展,大约好几百个。如果大家要经常使用各种扩展,建议大家可以尝试一下。
注:编译安装数据库及扩展确实灵活性比较强,但由于要提前安装各种各样的依赖,有些依赖可能由于操作系统的原因根本找不到了。本次部署各节点我使用的操作系统是centos stream 9,数据库使用PG17。
下面我们梳理一下部署过程,先把一些前置准备工作做好。
Using username "root".
Last login: Sun Aug 24 08:34:52 2025 from 192.168.255.28
[root@localhost ~]# setenforce=0
sed -i '/^SELINUX=/c'SELINUX=disabled /etc/selinux/config
#关闭防火墙
systemctl disable firewalld
systemctl stop firewalld
上面的内容都是关于防火墙和SELINX的设置
[root@localhost ~]# curl -fsSL https://repo.pigsty.io/pig | bash
[INFO] kernel = Linux
[INFO] machine = x86_64
[INFO] package = rpm
[INFO] pkg_url = https://repo.pigsty.io/pkg/pig/v0.6.1/pig-0.6.1-1.x86_64.rpm
[INFO] get dst = /tmp/pig-0.6.1-1.x86_64.rpm
[INFO] downloading https://repo.pigsty.io/pkg/pig/v0.6.1/pig-0.6.1-1.x86_64.rpm to /tmp/pig-0.6.1-1.x86_64.rpm
curl -fSL https://repo.pigsty.io/pkg/pig/v0.6.1/pig-0.6.1-1.x86_64.rpm -o /tmp/pig-0.6.1-1.x86_64.rpm
######################################################################## 100.0%
[INFO] md5sums = 1a28b44dc53c3e5052f2227a7d76b860 /tmp/pig-0.6.1-1.x86_64.rpm
[INFO] sudo rpm -ivh /tmp/pig-0.6.1-1.x86_64.rpm
Verifying... ################################# [100%]
准备中... ################################# [100%]
正在升级/安装...
1:pig-0.6.1-1 ################################# [100%]
[INFO] pig v0.6.1 installed
check https://pigsty.io/ext/pig
以上内容是下载安装冯哥的pig rpm包,然后就可以安装各种扩展了。
[root@localhost ~]# cat>>/etc/sysctl.conf<<EOF
fs.file-max = 76724200
kernel.sem = 10000 10240000 10000 1024
kernel.shmmni = 4096
kernel.shmall = 253702
kernel.shmmax = 1039163392
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_max = 1048576
fs.aio-max-nr = 40960000
vm.dirty_ratio=20
vm.dirty_background_ratio=3
vm.dirty_writeback_centisecs=100
vm.dirty_expire_centisecs=500
vm.swappiness=10
vm.min_free_kbytes=524288
vm.swappiness=0
vm.overcommit_memory=2
vm.overcommit_ratio=75
net.ipv4.ip_local_port_range = 10000 65535
EOF
[root@localhost ~]# sysctl -p
fs.file-max = 76724200
kernel.sem = 10000 10240000 10000 1024
kernel.shmmni = 4096
kernel.shmall = 253702
kernel.shmmax = 1039163392
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_max = 1048576
fs.aio-max-nr = 40960000
vm.dirty_ratio = 20
vm.dirty_background_ratio = 3
vm.dirty_writeback_centisecs = 100
vm.dirty_expire_centisecs = 500
vm.swappiness = 10
vm.min_free_kbytes = 524288
vm.swappiness = 0
vm.overcommit_memory = 2
vm.overcommit_ratio = 75
net.ipv4.ip_local_port_range = 10000 65535
[root@localhost ~]# hostnamectl set-hostname node1
[root@localhost ~]# cat >>/etc/hosts<<EOF
192.168.200.124 node1
192.168.200.82 node2
192.168.200.61 node3
EOF
以上内容是关于操作系统内核参数的配置和/etc/hosts的配置,这个操作每个节点都要执行。
[root@node1 ~]# yum -y install 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* libicu libicu-devel ntp libcurl-devel wget unzip
CentOS Stream 9 - BaseOS 18 kB/s | 5.1 kB 00:00
CentOS Stream 9 - BaseOS 3.5 MB/s | 8.8 MB 00:02
CentOS Stream 9 - AppStream 345 B/s | 5.2 kB 00:15
CentOS Stream 9 - AppStream 5.0 MB/s | 25 MB 00:04
CentOS Stream 9 - Extras packages 390 B/s | 5.9 kB 00:15
CentOS Stream 9 - Extras packages 15 kB/s | 19 kB 00:01
Extra Packages for Enterprise Linux 9 - x86_64 3.7 MB/s | 20 MB 00:05
Extra Packages for Enterprise Linux 9 openh264 (From Cisc 1.3 kB/s | 2.5 kB 00:01
Extra Packages for Enterprise Linux 9 - Next - x86_64 214 kB/s | 289 kB 00:01
上次元数据过期检查:0:00:01 前,执行于 2025年08月29日 星期五 09时25分37秒。
软件包 readline-8.1-4.el9.x86_64 已安装。
软件包 zlib-1.2.11-41.el9.x86_64 已安装。
软件包 gettext-0.21-8.el9.x86_64 已安装。
软件包 openssl-1:3.2.2-7.el9.x86_64 已安装。
软件包 pam-1.5.1-23.el9.x86_64 已安装。
软件包 libxml2-2.9.13-9.el9.x86_64 已安装。
软件包 libxslt-1.1.34-12.el9.x86_64 已安装。
未找到匹配的参数: uuid-devel
未找到匹配的参数: ntp
软件包 wget-1.21.1-8.el9.x86_64 已安装。
错误:没有任何匹配: uuid-devel ntp
提前安装各种数据库依赖,这个操作各个节点都要执行。
[root@node1 ~]# yum install -y expect nc
上次元数据过期检查:0:00:32 前,执行于 2025年08月29日 星期五 09时25分37秒。
依赖关系解决。
==========================================================================================
软件包 架构 版本 仓库 大小
==========================================================================================
安装:
expect x86_64 5.45.4-16.el9 appstream 250 k
nmap-ncat x86_64 3:7.92-3.el9 appstream 225 k
安装依赖关系:
libibverbs x86_64 57.0-1.el9 baseos 454 k
libpcap x86_64 14:1.10.0-4.el9 baseos 173 k
tcl x86_64 1:8.6.10-7.el9 baseos 1.1 M
事务概要
==========================================================================================
安装 5 软件包
总下载:2.2 M
安装大小:6.7 M
下载软件包:
[MIRROR] libpcap-1.10.0-4.el9.x86_64.rpm: Curl error (7): Couldn't connect to server for http://mirrors.neusoft.edu.cn/centos-stream/9-stream/BaseOS/x86_64/os/Packages/libpcap-1.10.0-4.el9.x86_64.rpm [Failed to connect to mirrors.neusoft.edu.cn port 80: 拒绝连接]
[MIRROR] libibverbs-57.0-1.el9.x86_64.rpm: Curl error (7): Couldn't connect to server for http://mirrors.neusoft.edu.cn/centos-stream/9-stream/BaseOS/x86_64/os/Packages/libibverbs-57.0-1.el9.x86_64.rpm [Failed to connect to mirrors.neusoft.edu.cn port 80: 拒绝连接]
[MIRROR] tcl-8.6.10-7.el9.x86_64.rpm: Curl error (7): Couldn't connect to server for http://mirrors.neusoft.edu.cn/centos-stream/9-stream/BaseOS/x86_64/os/Packages/tcl-8.6.10-7.el9.x86_64.rpm [Failed to connect to mirrors.neusoft.edu.cn port 80: 拒绝连接]
[MIRROR] tcl-8.6.10-7.el9.x86_64.rpm: Curl error (7): Couldn't connect to server for https://mirrors.neusoft.edu.cn/centos-stream/9-stream/BaseOS/x86_64/os/Packages/tcl-8.6.10-7.el9.x86_64.rpm [Failed to connect to mirrors.neusoft.edu.cn port 443: 拒绝连接]
[MIRROR] libpcap-1.10.0-4.el9.x86_64.rpm: Curl error (7): Couldn't connect to server for https://mirrors.neusoft.edu.cn/centos-stream/9-stream/BaseOS/x86_64/os/Packages/libpcap-1.10.0-4.el9.x86_64.rpm [Failed to connect to mirrors.neusoft.edu.cn port 443: 拒绝连接]
[MIRROR] libibverbs-57.0-1.el9.x86_64.rpm: Curl error (7): Couldn't connect to server for https://mirrors.neusoft.edu.cn/centos-stream/9-stream/BaseOS/x86_64/os/Packages/libibverbs-57.0-1.el9.x86_64.rpm [Failed to connect to mirrors.neusoft.edu.cn port 443: 拒绝连接]
(1/5): libpcap-1.10.0-4.el9.x86_64.rpm 497 kB/s | 173 kB 00:00
(2/5): libibverbs-57.0-1.el9.x86_64.rpm 1.1 MB/s | 454 kB 00:00
(3/5): expect-5.45.4-16.el9.x86_64.rpm 2.1 MB/s | 250 kB 00:00
(4/5): tcl-8.6.10-7.el9.x86_64.rpm 2.1 MB/s | 1.1 MB 00:00
(5/5): nmap-ncat-7.92-3.el9.x86_64.rpm 1.8 MB/s | 225 kB 00:00
------------------------------------------------------------------------------------------
总计 136 kB/s | 2.2 MB 00:16
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : tcl-1:8.6.10-7.el9.x86_64 1/5
安装 : libibverbs-57.0-1.el9.x86_64 2/5
安装 : libpcap-14:1.10.0-4.el9.x86_64 3/5
安装 : nmap-ncat-3:7.92-3.el9.x86_64 4/5
运行脚本: nmap-ncat-3:7.92-3.el9.x86_64 4/5
安装 : expect-5.45.4-16.el9.x86_64 5/5
运行脚本: expect-5.45.4-16.el9.x86_64 5/5
验证 : libibverbs-57.0-1.el9.x86_64 1/5
验证 : libpcap-14:1.10.0-4.el9.x86_64 2/5
验证 : tcl-1:8.6.10-7.el9.x86_64 3/5
验证 : expect-5.45.4-16.el9.x86_64 4/5
验证 : nmap-ncat-3:7.92-3.el9.x86_64 5/5
已安装:
expect-5.45.4-16.el9.x86_64 libibverbs-57.0-1.el9.x86_64
libpcap-14:1.10.0-4.el9.x86_64 nmap-ncat-3:7.92-3.el9.x86_64
tcl-1:8.6.10-7.el9.x86_64
以上两个依赖是部署SSH互信要用到的,每个节点都要安装。
完毕!
[root@node1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.124 node1
192.168.200.82 node2
192.168.200.61 node3
[root@node1 ~]# sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql17-server
上次元数据过期检查:0:00:43 前,执行于 2025年08月29日 星期五 13时56分32秒。
pgdg-redhat-repo-latest.noarch.rpm 66 kB/s | 12 kB 00:00
依赖关系解决。
==========================================================================================
软件包 架构 版本 仓库 大小
==========================================================================================
安装:
pgdg-redhat-repo noarch 42.0-56PGDG @commandline 12 k
事务概要
==========================================================================================
安装 1 软件包
总计:12 k
安装大小:17 k
下载软件包:
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : pgdg-redhat-repo-42.0-56PGDG.noarch 1/1
验证 : pgdg-redhat-repo-42.0-56PGDG.noarch 1/1
已安装:
pgdg-redhat-repo-42.0-56PGDG.noarch
完毕!
导入 GPG 公钥 0x08B40D20:
Userid: "PostgreSQL RPM Repository "
指纹: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
来自: /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
导入 GPG 公钥 0x08B40D20:
Userid: "PostgreSQL RPM Repository "
指纹: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
来自: /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
导入 GPG 公钥 0x08B40D20:
Userid: "PostgreSQL RPM Repository "
指纹: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
来自: /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
导入 GPG 公钥 0x08B40D20:
Userid: "PostgreSQL RPM Repository "
指纹: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
来自: /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
导入 GPG 公钥 0x08B40D20:
Userid: "PostgreSQL RPM Repository "
指纹: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
来自: /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
导入 GPG 公钥 0x08B40D20:
Userid: "PostgreSQL RPM Repository "
指纹: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
来自: /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
上次元数据过期检查:0:00:06 前,执行于 2025年08月29日 星期五 13时57分35秒。
依赖关系解决。
==========================================================================================
软件包 架构 版本 仓库 大小
==========================================================================================
安装:
postgresql17-server x86_64 17.6-1PGDG.rhel9 pgdg17 6.9 M
安装依赖关系:
libicu x86_64 67.1-10.el9 baseos 9.6 M
postgresql17 x86_64 17.6-1PGDG.rhel9 pgdg17 1.9 M
postgresql17-libs x86_64 17.6-1PGDG.rhel9 pgdg17 341 k
事务概要
==========================================================================================
安装 4 软件包
总下载:19 M
安装大小:74 M
下载软件包:
(1/4): postgresql17-libs-17.6-1PGDG.rhel9.x86_64.rpm 905 kB/s | 341 kB 00:00
(2/4): postgresql17-17.6-1PGDG.rhel9.x86_64.rpm 2.8 MB/s | 1.9 MB 00:00
(3/4): libicu-67.1-10.el9.x86_64.rpm 3.7 MB/s | 9.6 MB 00:02
(4/4): postgresql17-server-17.6-1PGDG.rhel9.x86_64.rpm 1.1 MB/s | 6.9 MB 00:06
------------------------------------------------------------------------------------------
总计 864 kB/s | 19 MB 00:22
PostgreSQL 17 for RHEL / Rocky / AlmaLinux 9 - x86_64 1.6 MB/s | 2.4 kB 00:00
导入 GPG 公钥 0x08B40D20:
Userid: "PostgreSQL RPM Repository "
指纹: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
来自: /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : postgresql17-libs-17.6-1PGDG.rhel9.x86_64 1/4
运行脚本: postgresql17-libs-17.6-1PGDG.rhel9.x86_64 1/4
安装 : libicu-67.1-10.el9.x86_64 2/4
安装 : postgresql17-17.6-1PGDG.rhel9.x86_64 3/4
运行脚本: postgresql17-17.6-1PGDG.rhel9.x86_64 3/4
运行脚本: postgresql17-server-17.6-1PGDG.rhel9.x86_64 4/4
安装 : postgresql17-server-17.6-1PGDG.rhel9.x86_64 4/4
运行脚本: postgresql17-server-17.6-1PGDG.rhel9.x86_64 4/4
验证 : libicu-67.1-10.el9.x86_64 1/4
验证 : postgresql17-17.6-1PGDG.rhel9.x86_64 2/4
验证 : postgresql17-libs-17.6-1PGDG.rhel9.x86_64 3/4
验证 : postgresql17-server-17.6-1PGDG.rhel9.x86_64 4/4
已安装:
libicu-67.1-10.el9.x86_64 postgresql17-17.6-1PGDG.rhel9.x86_64
postgresql17-libs-17.6-1PGDG.rhel9.x86_64 postgresql17-server-17.6-1PGDG.rhel9.x86_64
完毕!
每个节点按上面的命令方式进行数据库安装,不要初始化,不要进行设置数据库服务器启动。
[root@node1 ~]# ps -ef | postgres
-bash: postgres:未找到命令
[root@node1 ~]# ls
anaconda-ks.cfg ssh_trust.sh
[root@node1 ~]# su -l postgres
[postgres@node1 ~]$ ls
17
[postgres@node1 ~]$ cd 17
[postgres@node1 17]$ ls
backups data
[postgres@node1 17]$ cd data
[postgres@node1 data]$ exit
注销
[root@node1 ~]# ps -ef | grep postgres
root 11879 1257 0 13:59 pts/0 00:00:00 grep --color=auto postgres
通常上面的检查,我们发现只是创建了数据库用户,数据库未启动。
[root@node1 ~]# passwd postgres
更改用户 postgres 的密码 。
新的密码:
无效的密码: 密码是一个回文
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。
把各个节点的数据库用户密码统一设置为111,后面做SSH互信要用到。
[root@node1 ~]# pig ext install pgautofailover
INFO[14:01:54] installing extensions: dnf install pg_auto_failover_17*
上次元数据过期检查:0:04:19 前,执行于 2025年08月29日 星期五 13时57分35秒。
依赖关系解决。
==========================================================================================
软件包 架构 版本 仓库 大小
==========================================================================================
安装:
pg_auto_failover_17 x86_64 2.2-1PGDG.rhel9 pgdg17 786 k
pg_auto_failover_17-llvmjit x86_64 2.2-1PGDG.rhel9 pgdg17 354 k
安装依赖关系:
llvm x86_64 20.1.8-3.el9 appstream 22 M
llvm-filesystem x86_64 20.1.8-3.el9 appstream 9.1 k
llvm-libs x86_64 20.1.8-3.el9 appstream 30 M
perl-AutoLoader noarch 5.74-483.el9 appstream 21 k
perl-B x86_64 1.80-483.el9 appstream 180 k
perl-Carp noarch 1.50-460.el9 appstream 30 k
perl-Class-Struct noarch 0.66-483.el9 appstream 22 k
perl-Data-Dumper x86_64 2.174-462.el9 appstream 56 k
perl-Digest noarch 1.19-4.el9 appstream 26 k
perl-Digest-MD5 x86_64 2.58-4.el9 appstream 37 k
perl-Encode x86_64 4:3.08-462.el9 appstream 1.7 M
perl-Errno x86_64 1.30-483.el9 appstream 15 k
perl-Exporter noarch 5.74-461.el9 appstream 32 k
perl-Fcntl x86_64 1.13-483.el9 appstream 20 k
perl-File-Basename noarch 2.85-483.el9 appstream 17 k
perl-File-Path noarch 2.18-4.el9 appstream 36 k
perl-File-Temp noarch 1:0.231.100-4.el9 appstream 60 k
perl-File-stat noarch 1.09-483.el9 appstream 17 k
perl-FileHandle noarch 2.03-483.el9 appstream 15 k
perl-Getopt-Long noarch 1:2.52-4.el9 appstream 61 k
perl-Getopt-Std noarch 1.12-483.el9 appstream 15 k
perl-HTTP-Tiny noarch 0.076-462.el9 appstream 54 k
perl-IO x86_64 1.43-483.el9 appstream 88 k
perl-IO-Socket-IP noarch 0.41-5.el9 appstream 43 k
perl-IO-Socket-SSL noarch 2.073-2.el9 appstream 217 k
perl-IPC-Open3 noarch 1.21-483.el9 appstream 22 k
perl-MIME-Base64 x86_64 3.16-4.el9 appstream 31 k
perl-Mozilla-CA noarch 20200520-6.el9 appstream 13 k
perl-Net-SSLeay x86_64 1.94-3.el9 appstream 414 k
perl-POSIX x86_64 1.94-483.el9 appstream 96 k
perl-PathTools x86_64 3.78-461.el9 appstream 88 k
perl-Pod-Escapes noarch 1:1.07-460.el9 appstream 21 k
perl-Pod-Perldoc noarch 3.28.01-461.el9 appstream 87 k
perl-Pod-Simple noarch 1:3.42-4.el9 appstream 225 k
perl-Pod-Usage noarch 4:2.01-4.el9 appstream 41 k
perl-Scalar-List-Utils x86_64 4:1.56-462.el9 appstream 71 k
perl-SelectSaver noarch 1.02-483.el9 appstream 11 k
perl-Socket x86_64 4:2.031-4.el9 appstream 56 k
perl-Storable x86_64 1:3.21-460.el9 appstream 96 k
perl-Symbol noarch 1.08-483.el9 appstream 14 k
perl-Term-ANSIColor noarch 5.01-461.el9 appstream 49 k
perl-Term-Cap noarch 1.17-460.el9 appstream 23 k
perl-Text-ParseWords noarch 3.30-460.el9 appstream 17 k
perl-Text-Tabs+Wrap noarch 2013.0523-460.el9 appstream 24 k
perl-Time-Local noarch 2:1.300-7.el9 appstream 34 k
perl-URI noarch 5.09-3.el9 appstream 121 k
perl-base noarch 2.27-483.el9 appstream 16 k
perl-constant noarch 1.33-461.el9 appstream 24 k
perl-if noarch 0.60.800-483.el9 appstream 14 k
perl-interpreter x86_64 4:5.32.1-483.el9 appstream 70 k
perl-libnet noarch 3.13-4.el9 appstream 130 k
perl-libs x86_64 4:5.32.1-483.el9 appstream 2.2 M
perl-mro x86_64 1.23-483.el9 appstream 28 k
perl-overload noarch 1.31-483.el9 appstream 45 k
perl-overloading noarch 0.02-483.el9 appstream 12 k
perl-parent noarch 1:0.238-460.el9 appstream 15 k
perl-podlators noarch 1:4.14-460.el9 appstream 114 k
perl-subs noarch 1.03-483.el9 appstream 11 k
perl-vars noarch 1.05-483.el9 appstream 13 k
postgresql17-contrib x86_64 17.6-1PGDG.rhel9 pgdg17 730 k
安装弱的依赖:
perl-NDBM_File x86_64 1.15-483.el9 appstream 22 k
事务概要
==========================================================================================
安装 63 软件包
总下载:61 M
安装大小:243 M
确定吗?[y/N]: y
下载软件包:
(1/63): llvm-filesystem-20.1.8-3.el9.x86_64.rpm 58 kB/s | 9.1 kB 00:00
(2/63): perl-AutoLoader-5.74-483.el9.noarch.rpm 199 kB/s | 21 kB 00:00
(3/63): perl-B-1.80-483.el9.x86_64.rpm 702 kB/s | 180 kB 00:00
(4/63): perl-Carp-1.50-460.el9.noarch.rpm 358 kB/s | 30 kB 00:00
(5/63): perl-Class-Struct-0.66-483.el9.noarch.rpm 37 kB/s | 22 kB 00:00
(6/63): perl-Data-Dumper-2.174-462.el9.x86_64.rpm 103 kB/s | 56 kB 00:00
(7/63): perl-Digest-1.19-4.el9.noarch.rpm 136 kB/s | 26 kB 00:00
(8/63): perl-Digest-MD5-2.58-4.el9.x86_64.rpm 142 kB/s | 37 kB 00:00
(9/63): perl-Encode-3.08-462.el9.x86_64.rpm 329 kB/s | 1.7 MB 00:05
(10/63): perl-Errno-1.30-483.el9.x86_64.rpm 177 kB/s | 15 kB 00:00
(11/63): perl-Exporter-5.74-461.el9.noarch.rpm 320 kB/s | 32 kB 00:00
(12/63): perl-Fcntl-1.13-483.el9.x86_64.rpm 217 kB/s | 20 kB 00:00
(13/63): perl-File-Basename-2.85-483.el9.noarch.rpm 181 kB/s | 17 kB 00:00
(14/63): perl-File-Path-2.18-4.el9.noarch.rpm 303 kB/s | 36 kB 00:00
(15/63): perl-File-Temp-0.231.100-4.el9.noarch.rpm 406 kB/s | 60 kB 00:00
(16/63): perl-File-stat-1.09-483.el9.noarch.rpm 175 kB/s | 17 kB 00:00
(17/63): perl-FileHandle-2.03-483.el9.noarch.rpm 173 kB/s | 15 kB 00:00
(18/63): perl-Getopt-Long-2.52-4.el9.noarch.rpm 408 kB/s | 61 kB 00:00
(19/63): llvm-20.1.8-3.el9.x86_64.rpm 2.6 MB/s | 22 MB 00:08
(20/63): perl-Getopt-Std-1.12-483.el9.noarch.rpm 167 kB/s | 15 kB 00:00
(21/63): perl-HTTP-Tiny-0.076-462.el9.noarch.rpm 591 kB/s | 54 kB 00:00
(22/63): perl-IO-1.43-483.el9.x86_64.rpm 507 kB/s | 88 kB 00:00
(23/63): perl-IO-Socket-IP-0.41-5.el9.noarch.rpm 476 kB/s | 43 kB 00:00
(24/63): perl-IPC-Open3-1.21-483.el9.noarch.rpm 320 kB/s | 22 kB 00:00
(25/63): perl-MIME-Base64-3.16-4.el9.x86_64.rpm 637 kB/s | 31 kB 00:00
(26/63): perl-IO-Socket-SSL-2.073-2.el9.noarch.rpm 945 kB/s | 217 kB 00:00
(27/63): perl-NDBM_File-1.15-483.el9.x86_64.rpm 482 kB/s | 22 kB 00:00
(28/63): perl-Mozilla-CA-20200520-6.el9.noarch.rpm 33 kB/s | 13 kB 00:00
(29/63): perl-Net-SSLeay-1.94-3.el9.x86_64.rpm 1.2 MB/s | 414 kB 00:00
(30/63): perl-POSIX-1.94-483.el9.x86_64.rpm 865 kB/s | 96 kB 00:00
(31/63): perl-Pod-Escapes-1.07-460.el9.noarch.rpm 214 kB/s | 21 kB 00:00
(32/63): perl-PathTools-3.78-461.el9.x86_64.rpm 702 kB/s | 88 kB 00:00
(33/63): perl-Pod-Perldoc-3.28.01-461.el9.noarch.rpm 783 kB/s | 87 kB 00:00
(34/63): perl-Pod-Usage-2.01-4.el9.noarch.rpm 471 kB/s | 41 kB 00:00
(35/63): perl-Pod-Simple-3.42-4.el9.noarch.rpm 1.1 MB/s | 225 kB 00:00
(36/63): perl-SelectSaver-1.02-483.el9.noarch.rpm 154 kB/s | 11 kB 00:00
(37/63): perl-Scalar-List-Utils-1.56-462.el9.x86_64.rpm 732 kB/s | 71 kB 00:00
(38/63): perl-Socket-2.031-4.el9.x86_64.rpm 564 kB/s | 56 kB 00:00
(39/63): perl-Storable-3.21-460.el9.x86_64.rpm 758 kB/s | 96 kB 00:00
(40/63): perl-Symbol-1.08-483.el9.noarch.rpm 181 kB/s | 14 kB 00:00
(41/63): perl-Term-ANSIColor-5.01-461.el9.noarch.rpm 510 kB/s | 49 kB 00:00
(42/63): perl-Term-Cap-1.17-460.el9.noarch.rpm 277 kB/s | 23 kB 00:00
(43/63): perl-Text-ParseWords-3.30-460.el9.noarch.rpm 183 kB/s | 17 kB 00:00
(44/63): perl-Text-Tabs+Wrap-2013.0523-460.el9.noarch.rpm 270 kB/s | 24 kB 00:00
(45/63): llvm-libs-20.1.8-3.el9.x86_64.rpm 2.9 MB/s | 30 MB 00:10
(46/63): perl-Time-Local-1.300-7.el9.noarch.rpm 143 kB/s | 34 kB 00:00
(47/63): perl-URI-5.09-3.el9.noarch.rpm 528 kB/s | 121 kB 00:00
(48/63): perl-base-2.27-483.el9.noarch.rpm 278 kB/s | 16 kB 00:00
(49/63): perl-if-0.60.800-483.el9.noarch.rpm 212 kB/s | 14 kB 00:00
(50/63): perl-constant-1.33-461.el9.noarch.rpm 349 kB/s | 24 kB 00:00
(51/63): perl-interpreter-5.32.1-483.el9.x86_64.rpm 1.0 MB/s | 70 kB 00:00
(52/63): perl-mro-1.23-483.el9.x86_64.rpm 436 kB/s | 28 kB 00:00
(53/63): perl-libnet-3.13-4.el9.noarch.rpm 928 kB/s | 130 kB 00:00
(54/63): perl-overload-1.31-483.el9.noarch.rpm 623 kB/s | 45 kB 00:00
(55/63): perl-overloading-0.02-483.el9.noarch.rpm 182 kB/s | 12 kB 00:00
(56/63): perl-parent-0.238-460.el9.noarch.rpm 226 kB/s | 15 kB 00:00
(57/63): perl-subs-1.03-483.el9.noarch.rpm 138 kB/s | 11 kB 00:00
(58/63): perl-podlators-4.14-460.el9.noarch.rpm 825 kB/s | 114 kB 00:00
(59/63): perl-vars-1.05-483.el9.noarch.rpm 169 kB/s | 13 kB 00:00
(60/63): pg_auto_failover_17-llvmjit-2.2-1PGDG.rhel9.x86_ 1.2 MB/s | 354 kB 00:00
(61/63): pg_auto_failover_17-2.2-1PGDG.rhel9.x86_64.rpm 2.0 MB/s | 786 kB 00:00
(62/63): postgresql17-contrib-17.6-1PGDG.rhel9.x86_64.rpm 5.4 MB/s | 730 kB 00:00
(63/63): perl-libs-5.32.1-483.el9.x86_64.rpm 2.1 MB/s | 2.2 MB 00:01
------------------------------------------------------------------------------------------
总计 5.2 MB/s | 61 MB 00:11
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : perl-Digest-1.19-4.el9.noarch 1/63
安装 : perl-Digest-MD5-2.58-4.el9.x86_64 2/63
安装 : perl-B-1.80-483.el9.x86_64 3/63
安装 : perl-FileHandle-2.03-483.el9.noarch 4/63
安装 : perl-Data-Dumper-2.174-462.el9.x86_64 5/63
安装 : perl-libnet-3.13-4.el9.noarch 6/63
安装 : perl-base-2.27-483.el9.noarch 7/63
安装 : perl-URI-5.09-3.el9.noarch 8/63
安装 : perl-AutoLoader-5.74-483.el9.noarch 9/63
安装 : perl-Mozilla-CA-20200520-6.el9.noarch 10/63
安装 : perl-if-0.60.800-483.el9.noarch 11/63
安装 : perl-IO-Socket-IP-0.41-5.el9.noarch 12/63
安装 : perl-Time-Local-2:1.300-7.el9.noarch 13/63
安装 : perl-File-Path-2.18-4.el9.noarch 14/63
安装 : perl-Pod-Escapes-1:1.07-460.el9.noarch 15/63
安装 : perl-Text-Tabs+Wrap-2013.0523-460.el9.noarch 16/63
安装 : perl-IO-Socket-SSL-2.073-2.el9.noarch 17/63
安装 : perl-Net-SSLeay-1.94-3.el9.x86_64 18/63
安装 : perl-Class-Struct-0.66-483.el9.noarch 19/63
安装 : perl-POSIX-1.94-483.el9.x86_64 20/63
安装 : perl-Term-ANSIColor-5.01-461.el9.noarch 21/63
安装 : perl-IPC-Open3-1.21-483.el9.noarch 22/63
安装 : perl-subs-1.03-483.el9.noarch 23/63
安装 : perl-File-Temp-1:0.231.100-4.el9.noarch 24/63
安装 : perl-Term-Cap-1.17-460.el9.noarch 25/63
安装 : perl-Pod-Simple-1:3.42-4.el9.noarch 26/63
安装 : perl-HTTP-Tiny-0.076-462.el9.noarch 27/63
安装 : perl-Socket-4:2.031-4.el9.x86_64 28/63
安装 : perl-SelectSaver-1.02-483.el9.noarch 29/63
安装 : perl-Symbol-1.08-483.el9.noarch 30/63
安装 : perl-File-stat-1.09-483.el9.noarch 31/63
安装 : perl-podlators-1:4.14-460.el9.noarch 32/63
安装 : perl-Pod-Perldoc-3.28.01-461.el9.noarch 33/63
安装 : perl-Fcntl-1.13-483.el9.x86_64 34/63
安装 : perl-Text-ParseWords-3.30-460.el9.noarch 35/63
安装 : perl-mro-1.23-483.el9.x86_64 36/63
安装 : perl-IO-1.43-483.el9.x86_64 37/63
安装 : perl-overloading-0.02-483.el9.noarch 38/63
安装 : perl-Pod-Usage-4:2.01-4.el9.noarch 39/63
安装 : perl-Errno-1.30-483.el9.x86_64 40/63
安装 : perl-File-Basename-2.85-483.el9.noarch 41/63
安装 : perl-Getopt-Std-1.12-483.el9.noarch 42/63
安装 : perl-MIME-Base64-3.16-4.el9.x86_64 43/63
安装 : perl-Scalar-List-Utils-4:1.56-462.el9.x86_64 44/63
安装 : perl-constant-1.33-461.el9.noarch 45/63
安装 : perl-Storable-1:3.21-460.el9.x86_64 46/63
安装 : perl-overload-1.31-483.el9.noarch 47/63
安装 : perl-parent-1:0.238-460.el9.noarch 48/63
安装 : perl-vars-1.05-483.el9.noarch 49/63
安装 : perl-Getopt-Long-1:2.52-4.el9.noarch 50/63
安装 : perl-Carp-1.50-460.el9.noarch 51/63
安装 : perl-Exporter-5.74-461.el9.noarch 52/63
安装 : perl-NDBM_File-1.15-483.el9.x86_64 53/63
安装 : perl-PathTools-3.78-461.el9.x86_64 54/63
安装 : perl-Encode-4:3.08-462.el9.x86_64 55/63
安装 : perl-libs-4:5.32.1-483.el9.x86_64 56/63
安装 : perl-interpreter-4:5.32.1-483.el9.x86_64 57/63
安装 : postgresql17-contrib-17.6-1PGDG.rhel9.x86_64 58/63
安装 : pg_auto_failover_17-2.2-1PGDG.rhel9.x86_64 59/63
安装 : llvm-filesystem-20.1.8-3.el9.x86_64 60/63
安装 : llvm-libs-20.1.8-3.el9.x86_64 61/63
安装 : llvm-20.1.8-3.el9.x86_64 62/63
安装 : pg_auto_failover_17-llvmjit-2.2-1PGDG.rhel9.x86_64 63/63
运行脚本: pg_auto_failover_17-llvmjit-2.2-1PGDG.rhel9.x86_64 63/63
验证 : llvm-20.1.8-3.el9.x86_64 1/63
验证 : llvm-filesystem-20.1.8-3.el9.x86_64 2/63
验证 : llvm-libs-20.1.8-3.el9.x86_64 3/63
验证 : perl-AutoLoader-5.74-483.el9.noarch 4/63
验证 : perl-B-1.80-483.el9.x86_64 5/63
验证 : perl-Carp-1.50-460.el9.noarch 6/63
验证 : perl-Class-Struct-0.66-483.el9.noarch 7/63
验证 : perl-Data-Dumper-2.174-462.el9.x86_64 8/63
验证 : perl-Digest-1.19-4.el9.noarch 9/63
验证 : perl-Digest-MD5-2.58-4.el9.x86_64 10/63
验证 : perl-Encode-4:3.08-462.el9.x86_64 11/63
验证 : perl-Errno-1.30-483.el9.x86_64 12/63
验证 : perl-Exporter-5.74-461.el9.noarch 13/63
验证 : perl-Fcntl-1.13-483.el9.x86_64 14/63
验证 : perl-File-Basename-2.85-483.el9.noarch 15/63
验证 : perl-File-Path-2.18-4.el9.noarch 16/63
验证 : perl-File-Temp-1:0.231.100-4.el9.noarch 17/63
验证 : perl-File-stat-1.09-483.el9.noarch 18/63
验证 : perl-FileHandle-2.03-483.el9.noarch 19/63
验证 : perl-Getopt-Long-1:2.52-4.el9.noarch 20/63
验证 : perl-Getopt-Std-1.12-483.el9.noarch 21/63
验证 : perl-HTTP-Tiny-0.076-462.el9.noarch 22/63
验证 : perl-IO-1.43-483.el9.x86_64 23/63
验证 : perl-IO-Socket-IP-0.41-5.el9.noarch 24/63
验证 : perl-IO-Socket-SSL-2.073-2.el9.noarch 25/63
验证 : perl-IPC-Open3-1.21-483.el9.noarch 26/63
验证 : perl-MIME-Base64-3.16-4.el9.x86_64 27/63
验证 : perl-Mozilla-CA-20200520-6.el9.noarch 28/63
验证 : perl-NDBM_File-1.15-483.el9.x86_64 29/63
验证 : perl-Net-SSLeay-1.94-3.el9.x86_64 30/63
验证 : perl-POSIX-1.94-483.el9.x86_64 31/63
验证 : perl-PathTools-3.78-461.el9.x86_64 32/63
验证 : perl-Pod-Escapes-1:1.07-460.el9.noarch 33/63
验证 : perl-Pod-Perldoc-3.28.01-461.el9.noarch 34/63
验证 : perl-Pod-Simple-1:3.42-4.el9.noarch 35/63
验证 : perl-Pod-Usage-4:2.01-4.el9.noarch 36/63
验证 : perl-Scalar-List-Utils-4:1.56-462.el9.x86_64 37/63
验证 : perl-SelectSaver-1.02-483.el9.noarch 38/63
验证 : perl-Socket-4:2.031-4.el9.x86_64 39/63
验证 : perl-Storable-1:3.21-460.el9.x86_64 40/63
验证 : perl-Symbol-1.08-483.el9.noarch 41/63
验证 : perl-Term-ANSIColor-5.01-461.el9.noarch 42/63
验证 : perl-Term-Cap-1.17-460.el9.noarch 43/63
验证 : perl-Text-ParseWords-3.30-460.el9.noarch 44/63
验证 : perl-Text-Tabs+Wrap-2013.0523-460.el9.noarch 45/63
验证 : perl-Time-Local-2:1.300-7.el9.noarch 46/63
验证 : perl-URI-5.09-3.el9.noarch 47/63
验证 : perl-base-2.27-483.el9.noarch 48/63
验证 : perl-constant-1.33-461.el9.noarch 49/63
验证 : perl-if-0.60.800-483.el9.noarch 50/63
验证 : perl-interpreter-4:5.32.1-483.el9.x86_64 51/63
验证 : perl-libnet-3.13-4.el9.noarch 52/63
验证 : perl-libs-4:5.32.1-483.el9.x86_64 53/63
验证 : perl-mro-1.23-483.el9.x86_64 54/63
验证 : perl-overload-1.31-483.el9.noarch 55/63
验证 : perl-overloading-0.02-483.el9.noarch 56/63
验证 : perl-parent-1:0.238-460.el9.noarch 57/63
验证 : perl-podlators-1:4.14-460.el9.noarch 58/63
验证 : perl-subs-1.03-483.el9.noarch 59/63
验证 : perl-vars-1.05-483.el9.noarch 60/63
验证 : pg_auto_failover_17-2.2-1PGDG.rhel9.x86_64 61/63
验证 : pg_auto_failover_17-llvmjit-2.2-1PGDG.rhel9.x86_64 62/63
验证 : postgresql17-contrib-17.6-1PGDG.rhel9.x86_64 63/63
已安装:
llvm-20.1.8-3.el9.x86_64
llvm-filesystem-20.1.8-3.el9.x86_64
llvm-libs-20.1.8-3.el9.x86_64
perl-AutoLoader-5.74-483.el9.noarch
perl-B-1.80-483.el9.x86_64
perl-Carp-1.50-460.el9.noarch
perl-Class-Struct-0.66-483.el9.noarch
perl-Data-Dumper-2.174-462.el9.x86_64
perl-Digest-1.19-4.el9.noarch
perl-Digest-MD5-2.58-4.el9.x86_64
perl-Encode-4:3.08-462.el9.x86_64
perl-Errno-1.30-483.el9.x86_64
perl-Exporter-5.74-461.el9.noarch
perl-Fcntl-1.13-483.el9.x86_64
perl-File-Basename-2.85-483.el9.noarch
perl-File-Path-2.18-4.el9.noarch
perl-File-Temp-1:0.231.100-4.el9.noarch
perl-File-stat-1.09-483.el9.noarch
perl-FileHandle-2.03-483.el9.noarch
perl-Getopt-Long-1:2.52-4.el9.noarch
perl-Getopt-Std-1.12-483.el9.noarch
perl-HTTP-Tiny-0.076-462.el9.noarch
perl-IO-1.43-483.el9.x86_64
perl-IO-Socket-IP-0.41-5.el9.noarch
perl-IO-Socket-SSL-2.073-2.el9.noarch
perl-IPC-Open3-1.21-483.el9.noarch
perl-MIME-Base64-3.16-4.el9.x86_64
perl-Mozilla-CA-20200520-6.el9.noarch
perl-NDBM_File-1.15-483.el9.x86_64
perl-Net-SSLeay-1.94-3.el9.x86_64
perl-POSIX-1.94-483.el9.x86_64
perl-PathTools-3.78-461.el9.x86_64
perl-Pod-Escapes-1:1.07-460.el9.noarch
perl-Pod-Perldoc-3.28.01-461.el9.noarch
perl-Pod-Simple-1:3.42-4.el9.noarch
perl-Pod-Usage-4:2.01-4.el9.noarch
perl-Scalar-List-Utils-4:1.56-462.el9.x86_64
perl-SelectSaver-1.02-483.el9.noarch
perl-Socket-4:2.031-4.el9.x86_64
perl-Storable-1:3.21-460.el9.x86_64
perl-Symbol-1.08-483.el9.noarch
perl-Term-ANSIColor-5.01-461.el9.noarch
perl-Term-Cap-1.17-460.el9.noarch
perl-Text-ParseWords-3.30-460.el9.noarch
perl-Text-Tabs+Wrap-2013.0523-460.el9.noarch
perl-Time-Local-2:1.300-7.el9.noarch
perl-URI-5.09-3.el9.noarch
perl-base-2.27-483.el9.noarch
perl-constant-1.33-461.el9.noarch
perl-if-0.60.800-483.el9.noarch
perl-interpreter-4:5.32.1-483.el9.x86_64
perl-libnet-3.13-4.el9.noarch
perl-libs-4:5.32.1-483.el9.x86_64
perl-mro-1.23-483.el9.x86_64
perl-overload-1.31-483.el9.noarch
perl-overloading-0.02-483.el9.noarch
perl-parent-1:0.238-460.el9.noarch
perl-podlators-1:4.14-460.el9.noarch
perl-subs-1.03-483.el9.noarch
perl-vars-1.05-483.el9.noarch
pg_auto_failover_17-2.2-1PGDG.rhel9.x86_64
pg_auto_failover_17-llvmjit-2.2-1PGDG.rhel9.x86_64
postgresql17-contrib-17.6-1PGDG.rhel9.x86_64
完毕!
用冯哥的pig工具进行扩展的安装,各个节点都要安装。
[root@node1 ~]# pg_autoctl --version
-bash: pg_autoctl:未找到命令
[root@node1 ~]# ls
anaconda-ks.cfg ssh_trust.sh
[root@node1 ~]# ./ssh_trust.sh -u postgres -p 111 -i '192.168.200.124,192.168.200.82,192.168.200.61'
[INFO] ============ SSH 互信配置开始 ============
[INFO] 执行用户: root
[INFO] 目标用户: postgres
[INFO] SSH端口: 22
[INFO] 目标主机: 192.168.200.124 192.168.200.82 192.168.200.61
[INFO] 检查现有互信配置...
[INFO] 正在检查 192.168.200.124...
[INFO] 192.168.200.124: 需要配置互信
[INFO] 正在检查 192.168.200.82...
[INFO] 192.168.200.82: 需要配置互信
[INFO] 正在检查 192.168.200.61...
[INFO] 192.168.200.61: 需要配置互信
[INFO] 需要配置互信的主机: 192.168.200.124 192.168.200.82 192.168.200.61
[INFO] 开始配置 SSH 互信...
[INFO] 准备用户 postgres 的 SSH 配置
[INFO] 生成 SSH 密钥对
[INFO] 收集所有目标主机的公钥到 known_hosts
[INFO] 收集 192.168.200.124:22 的公钥
[INFO] 收集 192.168.200.82:22 的公钥
[INFO] 收集 192.168.200.61:22 的公钥
[INFO] ➔ 正在配置主机: 192.168.200.124:22
[SUCCESS] ✓ 主机 192.168.200.124:22 配置成功
[INFO] ➔ 正在配置主机: 192.168.200.82:22
[SUCCESS] ✓ 主机 192.168.200.82:22 配置成功
[INFO] ➔ 正在配置主机: 192.168.200.61:22
[SUCCESS] ✓ 主机 192.168.200.61:22 配置成功
[INFO] ----------- 互信验证结果 -----------
[SUCCESS] ✓ 192.168.200.124 验证通过
[SUCCESS] ✓ 192.168.200.82 验证通过
[SUCCESS] ✓ 192.168.200.61 验证通过
[INFO] -----------------------------------
[INFO] 主机总数: 3
[SUCCESS] 成功数量: 3
[INFO] ===================================
[SUCCESS] 所有主机互信配置成功!
用三哥的SSH脚本工具进行互信的部署,一键完成。
[postgres@node1 ~]$ cat .bash_profile
[ -f /etc/profile ] && source /etc/profile
PGDATA=/var/lib/pgsql/17/data
export PGDATA
export PATH=$PATH:/usr/pgsql-17/bin
# If you want to customize your settings,
# Use the file below. This is not overridden
# by the RPMS.
[ -f /var/lib/pgsql/.pgsql_profile ] && source /var/lib/pgsql/.pgsql_profile
[postgres@node1 ~]$ pg_autoctl --version
pg_autoctl version
pg_autoctl extension version 2.2
compiled with PostgreSQL 17.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5), 64-bit
compatible with Postgres 13, 14, 15, 16 and 17
[postgres@node1 ~]$ exit
注销
把每个节点的环境变量设置一下
[root@node1 ~]# su -l postgres
上一次登录: 五 8月 29 14:07:17 CST 2025 pts/0 上
下面的操作是重点,思路是这样的,先配置monitor节点并启动之,这里我们选择node3为监控节点,监控节点用于观察主备节点的工作状态,主从节点要根据这个节点要创建出来,命令如下所示
pg_autoctl create monitor --pgdata /var/lib/pgsql/17/data --pgport 5432 --hostname node3 --auth trust --ssl-self-signed
pg_autoctl create monitor --pgdata /var/lib/pgsql/17/data --pgport 5432 --hostname node3 --auth trust --ssl-self-signed --run &
[postgres@node1 ~]$ pg_autoctl create postgres --hostname node1 --auth trust --ssl-self-signed --monitor 'postgres://autoctl_node@node3:5432/pg_auto_failover?sslmode=require' --run &
[1] 14011
[postgres@node1 ~]$ 14:29:16 14011 INFO Using default --ssl-mode "require"
14:29:16 14011 INFO Using --ssl-self-signed: pg_autoctl will create self-signed certificates, allowing for encrypted network traffic
14:29:16 14011 WARN Self-signed certificates provide protection against eavesdropping; this setup does NOT protect against Man-In-The-Middle attacks nor Impersonation attacks.
14:29:16 14011 WARN See https://www.postgresql.org/docs/current/libpq-ssl.html for details
14:29:16 14011 INFO Started pg_autoctl postgres service with pid 14013
14:29:16 14013 INFO /usr/pgsql-17/bin/pg_autoctl do service postgres --pgdata /var/lib/pgsql/17/data -v
14:29:16 14011 INFO Started pg_autoctl node-active service with pid 14014
14:29:16 14014 INFO Registered node 1 "node_1" (node1:5432) in formation "default", group 0, state "single"
14:29:16 14014 INFO Writing keeper state file at "/var/lib/pgsql/.local/share/pg_autoctl/var/lib/pgsql/17/data/pg_autoctl.state"
14:29:16 14014 INFO Writing keeper init state file at "/var/lib/pgsql/.local/share/pg_autoctl/var/lib/pgsql/17/data/pg_autoctl.init"
14:29:16 14014 INFO Successfully registered as "single" to the monitor.
14:29:16 14014 INFO FSM transition from "init" to "single": Start as a single node
14:29:16 14014 INFO Initialising postgres as a primary
14:29:16 14014 INFO Initialising a PostgreSQL cluster at "/var/lib/pgsql/17/data"
14:29:16 14014 INFO /usr/pgsql-17/bin/pg_ctl initdb -s -D /var/lib/pgsql/17/data --option '--auth=trust'
14:29:19 14014 WARN initdb: 无法为区域环境 "zh_CN.UTF-8" 找到合适的文本搜索配置
14:29:19 14014 INFO /usr/bin/openssl req -new -x509 -days 365 -nodes -text -out /var/lib/pgsql/17/data/server.crt -keyout /var/lib/pgsql/17/data/server.key -subj "/CN=node1"
14:29:19 14037 INFO /usr/pgsql-17/bin/postgres -D /var/lib/pgsql/17/data -p 5432 -h *
14:29:19 14013 INFO Postgres is now serving PGDATA "/var/lib/pgsql/17/data" on port 5432 with pid 14037
14:29:19 14014 INFO The user "postgres" already exists, skipping.
14:29:19 14014 INFO CREATE USER postgres
14:29:19 14014 INFO CREATE DATABASE postgres;
14:29:19 14014 INFO The database "postgres" already exists, skipping.
14:29:19 14014 INFO CREATE EXTENSION pg_stat_statements;
14:29:19 14014 INFO Disabling synchronous replication
14:29:19 14014 INFO Reloading Postgres configuration and HBA rules
14:29:19 14014 INFO /usr/bin/openssl req -new -x509 -days 365 -nodes -text -out /var/lib/pgsql/17/data/server.crt -keyout /var/lib/pgsql/17/data/server.key -subj "/CN=node1"
14:29:20 14014 INFO Contents of "/var/lib/pgsql/17/data/postgresql-auto-failover.conf" have changed, overwriting
14:29:20 14014 INFO Reloading Postgres configuration and HBA rules
14:29:20 14014 INFO Transition complete: current state is now "single"
14:29:20 14014 INFO keeper has been successfully initialized.
14:29:20 14014 INFO /usr/pgsql-17/bin/pg_autoctl do service node-active --pgdata /var/lib/pgsql/17/data -v
14:29:20 14014 INFO Reloaded the new configuration from "/var/lib/pgsql/.config/pg_autoctl/var/lib/pgsql/17/data/pg_autoctl.cfg"
14:29:20 14014 INFO Reloading Postgres configuration and HBA rules
14:29:21 14014 INFO pg_autoctl service is running, current state is "single"
14:29:22 14014 INFO New state for this node (node 1, "node_1") (node1:5432): single ➜ single
14:30:22 14014 INFO New state for node 2 "node_2" (node2:5432): wait_standby ➜ wait_standby
14:30:22 14014 INFO Fetched current list of 1 other nodes from the monitor to update HBA rules, including 1 changes.
14:30:22 14014 INFO Ensuring HBA rules for node 2 "node_2" (node2:5432)
14:30:22 14014 INFO Adding HBA rule: hostssl replication "pgautofailover_replicator" node2 trust
14:30:22 14014 INFO Adding HBA rule: hostssl "postgres" "pgautofailover_replicator" node2 trust
14:30:22 14014 INFO Writing new HBA rules in "/var/lib/pgsql/17/data/pg_hba.conf"
14:30:22 14014 INFO Reloading Postgres configuration and HBA rules
14:30:22 14014 INFO Monitor assigned new state "wait_primary"
14:30:22 14014 INFO Creating replication slot "pgautofailover_standby_2"
14:30:22 14014 INFO FSM transition from "single" to "wait_primary": A new secondary was added
14:30:22 14014 INFO Transition complete: current state is now "wait_primary"
14:30:22 14014 INFO New state for this node (node 1, "node_1") (node1:5432): single ➜ wait_primary
14:30:22 14014 INFO New state for this node (node 1, "node_1") (node1:5432): wait_primary ➜ wait_primary
14:30:22 14014 INFO New state for node 2 "node_2" (node2:5432): wait_standby ➜ catchingup
14:30:32 14014 INFO New state for node 2 "node_2" (node2:5432): wait_standby ➜ catchingup
14:30:37 14014 INFO New state for node 2 "node_2" (node2:5432): catchingup ➜ catchingup
14:30:38 14014 INFO New state for node 2 "node_2" (node2:5432): catchingup ➜ secondary
14:30:38 14014 INFO New state for node 2 "node_2" (node2:5432): secondary ➜ secondary
14:30:38 14014 INFO Monitor assigned new state "primary"
14:30:38 14014 INFO FSM transition from "wait_primary" to "primary": A healthy secondary appeared
14:30:38 14014 INFO Setting synchronous_standby_names to 'ANY 1 (pgautofailover_standby_2)'
14:30:38 14014 INFO Reloading Postgres configuration and HBA rules
14:30:38 14014 INFO Waiting until standby node has caught-up to LSN 0/3000000
14:30:38 14014 INFO Standby reached LSN 0/3000000, thus advanced past LSN 0/3000000
14:30:38 14014 INFO Transition complete: current state is now "primary"
14:30:38 14014 INFO New state for this node (node 1, "node_1") (node1:5432): wait_primary ➜ primary
以上是关于主节点node1的创建和启动
pg_autoctl create postgres --hostname node2 --auth trust --ssl-self-signed --monitor 'postgres://autoctl_node@node3:5432/pg_auto_failover?sslmode=require' --run &
以上是从节点的创建启动,
[postgres@node1 ~]$ pg_autoctl show state
Name | Node | Host:Port | TLI: LSN | Connection | Reported State | Assigned State
-------+-------+------------+----------------+--------------+---------------------+--------------------
node_1 | 1 | node1:5432 | 1: 0/3036DA8 | read-write | primary | primary
node_2 | 2 | node2:5432 | 1: 0/3036DA8 | read-only | secondary | secondary
以上是使用pg_autoctl对集群状态的显示
总结:由于本人不是开发出身,只能借助不少第三方工具做了不少的辅助工作,这一点有些自责。如果懂开发能自己写脚本,部署和维护工作可能更加智能化。另外在学习一些文章时,如果内容比较多且长,最好采用雷公打豆腐的方式,一次一小口的方式去哺,不要贪多求快,把每个知识点慢慢吃透。如果一次看不懂,那就经常翻出来看看。
合作电话:010-64087828
社区邮箱:greatsql@greatdb.com