使用互動式指令碼配置 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