第一范文网 - 专业文章范例文档资料分享平台

pgpool+postgresql异步流复制+数据库集群及负载的配置方法

来源:用户分享 时间:2025/5/16 9:52:17 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

# Failover command for streaming replication.

# This script assumes that DB node 0 is primary, and 1 is standby. #

# If standby goes down, do nothing. If primary goes down, create a # trigger file so that standby takes over primary node. #

# Arguments: $1: failed node id. $2: new master hostname. $3: path to # trigger file.

failed_node=$1 new_master=$2 trigger_file=$3

# Do nothing if standby goes down. if [ $failed_node = 1 ]; then fi

# Create the trigger file.

/usr/bin/ssh -T $new_master /bin/touch $trigger_file exit 0;

exit 0;

在主库的$PGDATA目录下面新建basebackup.sh

#! /bin/sh

# Recovery script for streaming replication. # This script assumes followings: #

# 1) Executed on the primary node by pgpool_recovery function. # 2) Executed as \# 3) \

# 4) can connect to \# password.

# 5) Password less access using ssh from the primary node to the # target node is possible. # 6) Arguments for the scripts are: # # # #

datadir=$1 desthost=$2 destdir=$3 port=$4

/usr/local/pgsql/bin/psql -p $port -c \postgres

rsync -C -a -c --delete -e ssh --exclude postgresql.conf --exclude postmaster.pid \\ --exclude postmaster.opts --exclude pg_log --exclude pg_xlog \\ --exclude recovery.conf $datadir/ $desthost:$destdir/

ssh -T $desthost mv $destdir/recovery.done $destdir/recovery.conf

/usr/local/pgsql/bin/psql -c \

$1: database cluster path on the primary node $2: hostname or IP address to be recovered $3: database cluster path on target node

$4: port number of of the primary database cluster

# 7) psql, rsync, ssh are available in the command search path.

在$PGDATA目录下面新建pgpool_remote_start文件(赋予可执行权限)

#! /bin/sh

if [ $# -ne 2 ] then

echo \ exit 1 fi DEST=$1 DESTDIR=$2

PGCTL=/usr/local/pgsql/bin/pg_ctl

ssh -T $DEST $PGCTL -w -D $DESTDIR -l /home/postgres/postgresql.log start

配置pool_hba.conf cd /usr/local/pgpool/etc/

cat /usr/local/pgsql/data/pg_hba.conf > pool_hba.conf

启动pgpool命令:

pgpool -n >/var/log/pgpool/pgpool.log 2>&1 & 停止pgpool命令: pgpool -m fast stop

登录pgpool命令:

psql -p 9999 -U postgres -d postgres

查看pgpool所有的节点信息: show pool_nodes;

status:

1:节点启动,还没有被连接 2:节点启动,已经被连接 3:节点down掉了

模拟节点down掉的情况:主库和备库一正常运行,备库二直接停止服务,当再重新启动备库二时,在主库上查看pool_nodes节点发现:

当用show pool_nodes;命令去查看的时候,发现有个节点的status为3的时候,说明这个节点已经down了,重新恢复的命令如下:(需要恢复的节点,数据库服务必须是停止状态) 节点恢复的命令:pcp_recovery_node -d 3600 172.16.144.145 9898 postgres 123456 2 172.16.144.145 pgpool(安装的主机IP) 9898:pgpool的端口号 postgres:用户名 123456:密码 2:节点ID

命令执行后成功发现:

此时status状态值由3变为2,代表这个节点正常了。

把一个新节点加入到pgpool中的命令:

pcp_attach_node -d 5 172.16.144.200 5432 postgres 123456 1 172.16.144.200要加入节点的数据库IP地址 5432:要加入节点的数据库端口号 postgres:要加入节点的数据库的用户名 123456:要加入节点的数据库密码

pgpool+postgresql异步流复制+数据库集群及负载的配置方法.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c9e6an3vs9c2v3bu3zrg2_6.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top