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
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
====================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================
Installing:
watchdog x86_64 5.13-12.el7 base 79 k
====================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================
Installing:
watchdog x86_64 5.13-12.el7 base 79 k
====================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================
Installing:
watchdog x86_64 5.13-12.el7 base 79 k
[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
[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
[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
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]#
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]#
[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)