使用repmgr搭建PostgreSQL高可用时遇No route to host连接错误
解决repmgr standby clone时"No route to host"(5432端口)问题
先测底层网络连通性:在da2上执行
telnet 10.0.30.7 5432或nc -zv 10.0.30.7 5432,如果连不上,说明是网络层面的阻断,和PostgreSQL配置无关。检查da1的防火墙规则:
- 用
ufw status或firewall-cmd --list-all查看当前规则,确认5432端口是否允许10.0.30.0/24子网的请求进入。 - 没开放的话添加规则:
- UFW:
ufw allow from 10.0.30.0/24 to any port 5432 - Firewalld:
firewall-cmd --add-rich-rule='rule family="ipv4" source address="10.0.30.0/24" port port="5432" protocol="tcp" accept' --permanent,再执行firewall-cmd --reload重载配置。
- UFW:
- 用
确认PostgreSQL监听状态:
- 在da1上执行
ss -tulpn | grep 5432,看输出是否有LISTEN状态,且监听地址是0.0.0.0或10.0.30.7(不能只监听127.0.0.1)。 - 如果监听地址不对,检查
postgresql.conf里的listen_addresses = '*',修改后重启PostgreSQL:sudo systemctl restart postgresql。
- 在da1上执行
验证pg_hba.conf配置:
- 确保da1的pg_hba.conf里有针对repmgr用户和子网的规则,比如:
(认证方式根据你的实际配置调整,比如md5)host repmgr repmgr 10.0.30.0/24 scram-sha-256 - 修改后重载配置:
sudo systemctl reload postgresql或psql -c "SELECT pg_reload_conf();"。 - 直接用psql测试连接:在da2上执行
psql -h 10.0.30.7 -U repmgr -d repmgr,输入密码看能否登录,这能直接验证PostgreSQL的访问配置是否生效。
- 确保da1的pg_hba.conf里有针对repmgr用户和子网的规则,比如:
排查路由问题(如果上述步骤都无效):
- 在da2上执行
ip route,确认到10.0.30.7的路由走的是10.0.30.0/24子网对应的网卡。 - 在da1上执行
ip route,确认能正常回达10.0.30.6。
- 在da2上执行
内容的提问来源于stack exchange,提问作者eman Feah
相关产品推荐
相关产品推荐

