ThingWorx 高可用性 > 使用 Pgpool-II 部署 PostgreSQL HA 的示例 > 5. 将用于流式复制的数据库配置为 node1
5. 将用于流式复制的数据库配置为 node1
确保已创建 /db/node0archive/db/node1archive/db/node2archive 文件夹,并在三个节点之间进行了共享。
步骤 1
创建用户复制程序 (与 node0 的操作相同)。
步骤 2
将 node1 的 postgres.conf 编辑为使用 node0 的 postgres.conf 参数,但行 #10 除外,该行应改用以下值:
参数
节点
10
synchronous_standby_names
'node0,node2'
步骤 3
node1 应具有与 node0 相同的 start_replication.sh 脚本。
步骤 4
重新定位 node1 的 Master.sh 脚本。
创建脚本 retargetMaster.sh
vim /db/bin/retargetMaster.sh
其中包含以下内容 (与 node0 版本稍有不同):
#!/bin/bash -x
NEW_MASTER_HOSTNAME=$1
NEW_ARCHIVE_FOLDER=$2
if grep -q "$1" /db/postgres/recovery.conf
then
echo $1 is current target,server does not need a restart, done!
else
#service postgresql stop
/usr/pgsql-10.x/bin/pg_ctl -D /db/postgres stop -m fast
#/db/bin/start_replication.sh $NEW_MASTER_HOSTNAME
# Write out new recovery.conf file
rm /db/postgres/recovery.conf
echo "standby_mode = 'on'" >> /db/postgres/recovery.conf
echo "primary_conninfo = 'port=5432 host=$NEW_MASTER_HOSTNAME user=replicator password=trUf6yuz2?_Gub sslmode=disable sslcompression=1 application_name=node1'" >> /db/postgres/recovery.conf
echo "trigger_file='/db/trigger'" >> /db/postgres/recovery.conf
echo "restore_command = 'cp -f $NEW_ARCHIVE_FOLDER/%f %p>/db/postgres/recovery.conf
echo "archive_cleanup_command = '/usr/bin/pg_archivecleanup $NEW_ARCHIVE_FOLDER %r>/db/postgres/recovery.conf
echo "recovery_target_timeline = 'latest'" >> /db/postgres/recovery.conf
/usr/pgsql-10.x/bin/pg_ctl -D /db/postgres -l /db/postgres.log start
echo target is $1 now
fi
然后,将这些脚本设置为可执行脚本:
chmod a+x /db/bin/start_replication.sh
chmod a+x /db/bin/reargetMaster.sh
步骤 5
更新 pg_hba.conf (与 node0 的操作相同)。