在本教程中,我将讲解试用“看门狗”的简单方法。
你需要的是两台装有 pgpool-II 的 Linux 测试环境以及一个 PostgreSQL 安装在这些相同机器或者其他机器。 只需要一个后端(PostgreSQL)节点就够了。
你可以在任何模式中使用基于内存的查询缓存:复制模式,主/备模式和原始模式。
我使用 "osspc16" 作为活跃(Active)节点以及 "osspc20" 作为备用(Standby)节点。 "Someserver" 表示其中一台。
同时在活跃节点和备用节点中配置以下参数
首先,设置 "use_watchdog" 为 on 以启用看门狗。
use_watchdog = on # Activates watchdog
指定上游服务器(例如应用服务器)。留空就够了。
trusted_servers = '' # trusted server list which are used # to confirm network connection # (hostA,hostB,hostC,...)
指定看门狗的端口
wd_port = 9000 # port number for watchdog service
在 "delegate_IP" 中设置用于虚拟 IP 地址的 IP 地址,它不能被任何人使用。
delegate_IP = '133.137.177.143' # delegate IP address
下一步,为每个 pgpool 设置参数。
指定 "other_pgpool_hostname0","other_pgpool_port0" 和 "other_wd_port0",对应要监控的 pgpool 和看门狗。
[*] other_pgpool_hostname0 必须是 hostname 命令返回的值。
other_pgpool_hostname0 = 'osspc20' # Host name or IP address to connect to for other pgpool 0 other_pgpool_port0 = 9999 # Port number for othet pgpool 0 other_wd_port0 = 9000 # Port number for othet watchdog 0
other_pgpool_hostname0 = 'osspc16' # Host name or IP address to connect to for other pgpool 0 other_pgpool_port0 = 9999 # Port number for othet pgpool 0 other_wd_port0 = 9000 # Port number for othet watchdog 0
以 root 身份使用 "-n" 参数(表示以非守护进程模式)启动每个 pgpool-II 并重定向日志消息到 pgpool.log 中。
启动活跃节点上的 pgpool。
[user@osspc16]$ su - [root@osspc16]# {installed_dir}/bin/pgpool -n -f {installed_dir}/etc/pgpool.conf > pgpool.log 2>&1
日志显示 pgpool 获得了虚拟 IP 并启动了看门狗进程。
ERROR: wd_create_send_socket: connect() is failed(Connection refused) LOG: wd_escalation: eslcalated to master pgpool ERROR: wd_create_send_socket: connect() is failed(Connection refused) LOG: wd_escalation: escaleted to delegate_IP holder LOG: wd_init: start watchdog LOG: pgpool-II successfully started. version 3.2beta1 (namameboshi)
启动备用节点上的 pgpool。
[user@osspc20]$ su - [root@osspc20]# {installed_dir}/bin/pgpool -n -f {installed_dir}/etc/pgpool.conf > pgpool.log 2>&1
当 other_pgpool_hostname 列出的所有看门狗已经启动,存活检测启动。 在本例中,osspc16 是除了本节点之外的唯一的其他看门狗,因此存活检测已经启动了。
LOG: wd_init: start watchdog LOG: pgpool-II successfully started. version 3.2beta1 (namameboshi) LOG: watchdog: lifecheck started
在活跃节点中,存活检测也启动了。
LOG: watchdog: lifecheck started
通过 ping 确认虚拟 IP 地址。
[user@someserver]$ ping 133.137.177.142 PING 133.137.177.143 (133.137.177.143) 56(84) bytes of data. 64 bytes from 133.137.177.143: icmp_seq=1 ttl=64 time=0.328 ms 64 bytes from 133.137.177.143: icmp_seq=2 ttl=64 time=0.264 ms 64 bytes from 133.137.177.143: icmp_seq=3 ttl=64 time=0.412 ms
确定首先启动的活跃节点获得了虚拟 IP 地址。
[root@osspc16]# ifconfig eth0 ... eth0:0 inet addr:133.137.177.143 ... lo ...
确定不是最先启动的备用节点没有获得虚拟 IP 地址。
[root@osspc20]# ifconfig eth0 ... lo ...
尝试使用 "psql -h delegate_IP -p port" 连接到 PostgreSQL。
[user@someserver]$ psql -h 133.137.177.142 -p 9999 -l
确认在活跃节点无法提供服务的时候别用节点是如何工作的。
停止在活跃节点上的 pgpool。
[root@osspc16]# {installed_dir}/bin/pgpool stop
然后,备用服务器开始使用虚拟 IP。日志显示:
LOG: wd_escalation: eslcalated to master pgpool ERROR: wd_create_send_socket: connect() is failed(Connection refused) LOG: wd_escalation: escaleted to delegate_IP holder
通过 ping 这个 IP 地址以确认。
[user@someserver]$ ping 133.137.177.142 PING 133.137.177.143 (133.137.177.143) 56(84) bytes of data. 64 bytes from 133.137.177.143: icmp_seq=1 ttl=64 time=0.328 ms 64 bytes from 133.137.177.143: icmp_seq=2 ttl=64 time=0.264 ms 64 bytes from 133.137.177.143: icmp_seq=3 ttl=64 time=0.412 ms
确认原来活跃的服务器不在使用虚拟 IP 地址。
[root@osspc16]# ifconfig eth0 ... lo ...
确认原来的备用节点使用了虚拟 IP 地址。
[root@osspc20]# ifconfig eth0 ... eth0:0 inet addr:133.137.177.143 ... lo ...
尝试使用 "psql -h delegate_IP -p port" 连接到 PostgreSQL。
[user@someserver]$ psql -h 133.137.177.142 -p 9999 -l
以下为一些用于看门狗的监控的参数。
指定检测周期 "wd_interval",重试次数 "wd_life_point" 以及检测用的查询语句 "wd_lifecheck_query"。
wd_interval = 10 # lifecheck interval (sec) > 0 wd_life_point = 3 # lifecheck retry times wd_lifecheck_query = 'SELECT 1' # lifecheck query to pgpool from watchdog
以下为一些用于切换虚拟 IP 地址的参数。
指定切换命令 "if_up_cmd" 和 "if_down_cmd" 以及到这些命令的路径 "ifconfig_path", 以及在发生切换后发送 ARP 请求的命令 "arping_cmd" 以及到这个命令的路径 "arping_path"。
ifconfig_path = '/sbin' # ifconfig command path if_up_cmd = 'ifconfig eth0:0 inet $_IP_$ netmask 255.255.255.0' # startup delegate IP command if_down_cmd = 'ifconfig eth0:0 down' # shutdown delegate IP command arping_path = '/usr/sbin' # arping command path arping_cmd = 'arping -U $_IP_$ -w 1'