You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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重载配置。
  • 确认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。
  • 验证pg_hba.conf配置:

    • 确保da1的pg_hba.conf里有针对repmgr用户和子网的规则,比如:
      host    repmgr     repmgr     10.0.30.0/24     scram-sha-256
      
      (认证方式根据你的实际配置调整,比如md5)
    • 修改后重载配置:sudo systemctl reload postgresql或psql -c "SELECT pg_reload_conf();"。
    • 直接用psql测试连接:在da2上执行psql -h 10.0.30.7 -U repmgr -d repmgr,输入密码看能否登录,这能直接验证PostgreSQL的访问配置是否生效。
  • 排查路由问题(如果上述步骤都无效):

    • 在da2上执行ip route,确认到10.0.30.7的路由走的是10.0.30.0/24子网对应的网卡。
    • 在da1上执行ip route,确认能正常回达10.0.30.6。

内容的提问来源于stack exchange,提问作者eman Feah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 15:42:18