使用交互式脚本配置 OpenResty Edge 数据库高可用
1. 前言
手动配置 OpenResty Edge 数据库高可用见文档:OpenResty Edge 数据库高可用
本文演示使用交互式脚本配置 OpenResty Edge 数据库的高可用。
2. 配置 Master
SSH 登录 PG Master 机器
下载配置脚本
curl -O https://openresty.com/client/oredge/openresty-edge-db-ha-master.sh
- 执行配置脚本
sudo bash openresty-edge-db-ha-master.sh
交互过程如下:
[+] Please enter the standby host(like 192.168.0.2): 192.168.122.1
[+] Info: ping 192.168.122.1 succeeded.
[+] Please enter PG data path of master(default '/var/postgres12/data'):
[+] Please enter a username for replication, will create if it doesn't exist (default 'replicator'):
[+] Please enter a password for the user replicator (default [Randomly generate]):
[+] Will restart PG, do you want to continue? [y/N] y
[+] Restarting the openresty-postgresql12 service
[!] Saving Master info to ./postgresql-master.info.20220511025907
------------------------------------
STANDBY_HOST="192.168.122.1"
MASTER_HOST="127.0.0.1"
MASTER_PORT=5432"
USERNAME="replicator"
PASSWORD="TcVch76UzWaUyMJ5-5sWI9mZW3M5zBiv"
PG_DATA_PATH="/var/postgres12/data"
PG_DATA_SIZE="2.8G"
------------------------------------
[+] Info: master setup successfully.
standby host:Standby 的地址,如 192.168.0.2
,用于配置访问控制。
master host:Master 的服务端口,如 5432
。
username:用于备份的用户,如 replicator
,如果不存在则创建。
password:用于备份的用户的密码,如 examplepwd
,如果用户已存在,则密码需自行获取。
3. 配置 Standby
SSH 登录 PG Master 机器
下载配置脚本
curl -O https://openresty.com/client/oredge/openresty-edge-db-ha-standby.sh
- 执行配置脚本
sudo bash openresty-edge-db-ha-standby.sh
交互过程如下:
[+] Please make sure you have enough free hard disk space, do you want to continue? [y/N] y
[+] Please enter PG data path of standby(default '/var/postgres12/data'): /mnt/data/test/postgres12/data4
[+] Please enter the standby port(default 5432): 5436
[+] Please enter the master host(like 192.168.0.1): 192.168.122.37
[+] Info: ping 192.168.122.37 succeeded.
[+] Please enter the master port(default 5432):
[+] Please enter a username for replication(same as master, default 'replicator'):
[+] Please enter the password of user replicator: TcVch76UzWaUyMJ5-5sWI9mZW3M5zBiv
[+] Info: syncing master data, it may take a long time, please wait patiently
[+] Info: wait for the standby server to start
[+] Info: standby setup successfully.
master host:MASTER 的服务地址,如 192.168.0.1
master port:MASTER 的服务端口,如 5432
username:用于备份的用户(和 Master 中配置的是同一个),如 replicator
password:用于备份的用户的密码(和 Master 中配置的是同一个),如 examplepwd
4. 验证
在 Master 机器上执行
/usr/local/openresty-postgresql12/bin/psql -x -c "select * from pg_stat_replication" -U postgres
执行结果类似下面则说明配置成功
-[ RECORD 1 ]----+------------------------------
pid | 29015
usesysid | 22228
usename | replicator
application_name | walreceiver
client_addr | 192.168.122.1
client_hostname |
client_port | 38440
backend_start | 2022-02-21 23:36:46.418257-08
backend_xmin | 5222925
state | streaming
sent_lsn | 2/C5151CE8
write_lsn | 2/C5151CE8
flush_lsn | 2/C5151CE8
replay_lsn | 2/C5151CE8
write_lag | 00:00:00.000435
flush_lag | 00:00:00.001187
replay_lag | 00:00:00.001394
sync_priority | 0
sync_state | async
reply_time | 2022-02-21 23:42:21.456685-08