KingbaseES V8R6版本 数据库自动故障转移失败(Automatic Database Failover Fails)
适用于:
KingbaseES V8R6 版本。
repmgr配置信息:
首先检查repmgr.conf配置文件,确保数据库主节点,数据库备节点参数:failover='automatic'、recovery='standby'一致
故障现象:
- 数据库自动故障转移失败,也就是failover切换失败。
- 其他的正常可用的备节点未被选择(切换)成为新的主数据节点。
- 在KingbaseES数据库hamgr.log日志,可以看到类似于以下的信息条目。
[2023-02-10 10:34:01] [DETAIL] PQping() returned "PQPING_NO_RESPONSE"
[2023-02-10 10:34:01] [INFO] sleeping up to 6 seconds until next reconnection attempt
[2023-02-10 10:34:07] [INFO] checking state of node "node21" (ID: 2), 10 of 10 attempts
[2023-02-10 10:34:07] [WARNING] unable to reconnect to node "node21" (ID: 2) after 10 attempts
[2023-02-10 10:34:07] [NOTICE] repmgrd on this node is paused
[2023-02-10 10:34:07] [DETAIL] no failover will be carried out
[2023-02-10 10:34:07] [HINT] execute "repmgr service unpause" to resume normal failover mode
[2023-02-10 10:34:07] [WARNING] unable to ping "host=10.10.10.21 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3"
[2023-02-10 10:37:38] [DETAIL] PQping() returned "PQPING_NO_RESPONSE"
[2023-02-10 10:37:38] [INFO] node "node20" (ID: 1) monitoring upstream node "node21" (ID: 2) in degraded state
[2023-02-10 10:37:38] [DETAIL] repmgrd paused by administrator
[2023-02-10 10:37:38] [HINT] execute "repmgr service unpause" to resume normal failover mode
[2023-02-10 10:37:40] [WARNING] unable to ping "host=10.51.1.21 user=esrep dbname=esrep port=5432 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3"
- 在KingbaseES数据库kbha.log日志,可以看到如下信息条目
--- 10.10.10.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1019ms
rtt min/avg/max/mdev = 0.729/0.737/0.745/0.008 ms
[2023-02-13 13:32:34] [DEBUG] PID file "/home/kingbase/cluster/SWJ/swj/kingbase/etc/hamgrd.pid" exists and seems to contain a valid PID
[2023-02-13 13:32:34] [DEBUG] repmgrd is running, can not start another one.
[2023-02-13 13:32:37] [NOTICE] PING 10.10.10.1 (10.10.10.1) 56(84) bytes of data.
--- 10.10.10.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1029ms
rtt min/avg/max/mdev = 0.729/0.745/0.761/0.016 ms
[2023-02-13 13:32:37] [DEBUG] PID file "/home/kingbase/etc/hamgrd.pid" exists and seems to contain a valid PID
[2023-02-13 13:32:37] [DEBUG] repmgrd is running, can not start another one.
[2023-02-13 13:32:37] [DEBUG] the thread 428402432 is still running
ping: socket: 不允许的操作
[2023-02-13 13:32:38] [NOTICE]
[2023-02-13 13:32:38] [WARNING] ping host"10.10.10.1" failed
[2023-02-13 13:32:38] [DETAIL] average RTT value is not greater than zero
[2023-02-13 13:32:38] [DEBUG] ping process end early. usleep(1978998).
ping: socket: 不允许的操作
注意:前面的日志摘录只是示例。 日期、时间和环境变量可能因不同环境而异。
故障原因:
KingbaseES数据库主备切换过程:
- KingbaseES数据库集群当集群主节点发生故障时,备节点启动repmrd进程进行监控、检测,当检测到上游节点连接错误,会重试reconnect_attempts次,重试间隔reconnect_interval秒。
- KingbaseES数据库集群判断主节点是否故障时,通过网络连接超时,才能判断主节点故障。重试reconnect_attempts次后判断上游节点确定故障,然后判断上游节点是主节点还是备节点。
- 当KingbaseES确认主节点故障后,备节点杀掉wal_receiver进程(所有的备节点都会杀掉wal_receiver进程),开始进行升主操作。集群通过可用的备节点选择需要提升为主节点的备节点,执行升主语句,升主成功(failover切换成功)。
- 切换过程:假设本地节点选举成功,检测信任网关(如果配置了vip,会执行卸载集群旧的主节点vip, 并在集群新的主节点加载vip的操作,这个操作会使用到ping命令并且会ping两次vip),然后执行真正的升主语句,升主成功(failover切换成功)。
故障具体原因:
通过以上KingbaseES数据库主备切换过程及kbha.log日志确定问题是由于ping命令权限被修改导致。ping命令在运行中采用ICMP协议,需要发送ICMP报文,但只有root用户才能建立ICMP报文。
正常情况下,ping命令的权限应为-rwsr-xr-x,即带有suid的文件,一旦该权限被修改,则普通用户无法正常使用该命令。
$ ls -l /bin/ping
-rwxr-xr-x. 1 root root 67680 Feb 23 2021 /bin/ping
解决方法:
使用root用户执行以下命令
# 以下命令选择执行其中一条就可以
chmod u+x /bin/ping
# 或者
chmod 4755 /bin/ping
# 权限正确的ping
$ ls -l /bin/ping
-rwsr-xr-x. 1 root root 67680 Feb 23 2021 /bin/ping
再次验证,手动关闭主节点,可以正常完成数据库故障自动切换。