[英]How do I get pcp to automatically attach nodes to postgres pgpool?
I'm using postgres 9.4.9, pgpool 3.5.4 on centos 6.8.我在 centos 6.8 上使用 postgres 9.4.9,pgpool 3.5.4。
I'm having a major hard time getting pgpool to automatically detect when nodes are up (it often detects the first node but rarely detects the secondary) but if I use pcp_attach_node to tell it what nodes are up, then everything is hunky dory.我很难让 pgpool 自动检测节点何时启动(它通常检测到第一个节点但很少检测到辅助节点)但是如果我使用 pcp_attach_node 告诉它哪些节点已启动,那么一切都很好。
So I figured until I could properly sort the issue out, I would write a little script to check the status of the nodes and attach them as appropriate, but I'm having trouble with the password prompt.所以我想在我能正确解决问题之前,我会写一个小脚本来检查节点的状态并适当地附加它们,但是我在密码提示方面遇到了问题。 According to the documentation, I should be able to issue commands like
根据文档,我应该能够发出类似的命令
pcp_attach_node 10 localhost 9898 pgpool mypass 1
but that just complains但这只是抱怨
pcp_attach_node: Warning: extra command-line argument "localhost" ignored pcp_attach_node: Warning: extra command-line argument "9898" ignored pcp_attach_node: Warning: extra command-line argument "pgpool" ignored pcp_attach_node: Warning: extra command-line argument "mypass" ignored pcp_attach_node: Warning: extra command-line argument "1" ignored pcp_attach_node:警告:忽略了额外的命令行参数“localhost” pcp_attach_node:警告:忽略了额外的命令行参数“9898” pcp_attach_node:警告:忽略了额外的命令行参数“pgpool” pcp_attach_node:警告:额外的命令行参数“mypass” “忽略了 pcp_attach_node:警告:忽略了额外的命令行参数“1”
it'll only work when I use parameters like它只会在我使用像这样的参数时起作用
pcp_attach_node -U pgpool -h localhost -p 9898 -n 1
and there's no parameter for the password, I have to manually enter it at the prompt.而且密码没有参数,我必须在提示时手动输入。
Any suggestions for sorting this other than using Expect?除了使用 Expect 之外,还有其他对此进行排序的建议吗?
You have to create PCPPASSFILE . 您必须创建PCPPASSFILE 。 Search pgpool documentation for more info.
搜索pgpool 文档以获取更多信息。
Example 1: 范例1:
create PCPPASSFILE for logged user ( vi ~/.pcppass
), file content is 127.0.0.1:9897:user:pass (hostname:port:username:password), set file permissions 0600 ( chmod 0600 ~/.pcppass
) 为登录的用户创建PCPPASSFILE(
vi ~/.pcppass
),文件内容为127.0.0.1:9897:user:pass(主机名:端口:用户名:密码),设置文件权限0600( chmod 0600 ~/.pcppass
)
command should run without asking for password 命令应在不要求输入密码的情况下运行
pcp_attach_node -h 127.0.0.1 -U user -p 9897 -w -n 1
Example 2: 范例2:
create PCPPASSFILE ( vi /usr/local/etc/.pcppass
), file content is 127.0.0.1:9897:user:pass (hostname:port:username:password), set file permissions 0600 ( chmod 0600 /usr/local/etc/.pcppass
), set variable PCPPASSFILE ( export PCPPASSFILE=/usr/local/etc/.pcppass
) 创建PCPPASSFILE(
vi /usr/local/etc/.pcppass
),文件内容为127.0.0.1:9897:user:pass(主机名:端口:用户名:密码),设置文件权限0600( chmod 0600 /usr/local/etc/.pcppass
),设置变量PCPPASSFILE( export PCPPASSFILE=/usr/local/etc/.pcppass
)
command should run without asking for password 命令应在不要求输入密码的情况下运行
pcp_attach_node -h 127.0.0.1 -U user -p 9897 -w -n 1
Script for auto attach the node 自动附加节点的脚本
You can schedule this script with for example crontab. 您可以使用例如crontab安排此脚本。
#!/bin/bash
#pgpool status
#0 - This state is only used during the initialization. PCP will never display it.
#1 - Node is up. No connections yet.
#2 - Node is up. Connections are pooled.
#3 - Node is down.
source $HOME/.bash_profile
export PCPPASSFILE=/appl/scripts/.pcppass
STATUS_0=$(/usr/local/bin/pcp_node_info -h 127.0.0.1 -U postgres -p 9897 -n 0 -w | cut -d " " -f 3)
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [INFO] NODE 0 status "$STATUS_0;
if (( $STATUS_0 == 3 ))
then
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [WARN] NODE 0 is down - attaching node"
TMP=$(/usr/local/bin/pcp_attach_node -h 127.0.0.1 -U postgres -p 9897 -n 0 -w -v)
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [INFO] "$TMP
fi
STATUS_1=$(/usr/local/bin/pcp_node_info -h 127.0.0.1 -U postgres -p 9897 -n 1 -w | cut -d " " -f 3)
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [INFO] NODE 1 status "$STATUS_1;
if (( $STATUS_1 == 3 ))
then
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [WARN] NODE 1 is down - attaching node"
TMP=$(/usr/local/bin/pcp_attach_node -h 127.0.0.1 -U postgres -p 9897 -n 1 -w -v)
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [INFO] "$TMP
fi
exit 0
是的,您可以使用自定义的failover_command(/etc/pgpool 中的failover.sh)触发此命令的执行
Automated way to up your pgpool down node:
自动启动你的 pgpool down 节点的方法:
- copy this script into a file with execute permission to your desired location with postgres ownership into all nodes.
将此脚本复制到一个文件中,该文件具有对所有节点的 postgres 所有权的所需位置的执行权限。
- run
crontab -e
comamnd under postgres user在 postgres 用户下运行
crontab -e
comamnd- Finally set that script to run every minute at crontab.
最后将该脚本设置为在 crontab 中每分钟运行一次。 But to execute it for every second you may create your own service and run it.
但是要每秒执行一次,您可以创建自己的服务并运行它。
#!/bin/bash
# This script will up all pgpool down node
#************************
#******NODE STATUS*******
#************************
# 0 - This state is only used during the initialization.
# 1 - Node is up. No connection yet.
# 2 - Node is up and connection is pooled.
# 3 - Node is down
#************************
#******SCRIPT*******
#************************
server_node_list=(0 1 2)
for server_node in ${server_node_list[@]}
do
source $HOME/.bash_profile
export PCPPASSFILE=/var/lib/pgsql/.pcppass
node_status=$(pcp_node_info -p 9898 -h localhost -U pgpool -n $server_node -w | cut -d ' ' -f 3);
if [[ $node_status == 3 ]]
then
pcp_attach_node -n $server_node -U pgpool -p 9898 -w -v
fi
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.