gpt4 book ai didi

postgresql(远程)连接被拒绝

转载 作者:行者123 更新时间:2023-11-29 12:10:37 24 4
gpt4 key购买 nike

我的错误:

# psql -U postgres -h 10.230.5.51
psql: could not connect to server: Connection refused
Is the server running on host "10.230.5.51" and accepting
TCP/IP connections on port 5432?

在 postgresql.conf 中:

listen_addresses = '*'
port = 5432 # (change requires restart)

我在pg_hba.conf中添加了客户端服务器(用户名/数据库用X代替)

host    X          X          10.230.5.21             md5
host X X 10.230.5.22 md5

在我将它们添加到 pg_hba.conf 之前,它给了我这个错误:

# psql -U postgres -h 10.230.5.51
psql: FATAL: no pg_hba.conf entry for host "10.230.5.22", user "X", database "X", SSL on
FATAL: no pg_hba.conf entry for host "10.230.5.22", user "X", database "X", SSL off

所以我假设我采取的第一步是正确的?

我觉得我可能缺少的最后一步可能是 iptables。它们看起来像这样:

-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 ! -i lo -j REJECT --reject-with icmp-port-unreachable
-A INPUT -s 10.230.4.0/22 -j LOCAL
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8010 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 10443 -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -p gre -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-port-unreachable
-A LOCAL -p udp -m state --state NEW -m udp --dport 53 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 53 -j ACCEPT
-A LOCAL -p udp -m state --state NEW -m udp --dport 123 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 2181 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 2888 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 3888 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 7000 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 7001 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 9042 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 9160 -j ACCEPT

iptables 好吗?我可以看到端口 5432 在列表中。在此之前连接是否被另一条规则拒绝? iptable 命令很奇怪。

一般信息:

两台电脑都运行 linux。我最初没有设置数据库。数据库运行良好,但仅在本地运行,即使在使用 postgres 数据库的服务器上运行命令时发生了这种情况:

# psql -U postgres -h localhost
psql: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?

最佳答案

我在 PostgreSQL 9.6 中遇到了同样的问题,我通过以下方式解决了。

  1. sudo nano/etc/postgresql/9.6/main/postgresql.conf

  2. 在下一行中用“*”代替 localhost 并删除注释符号 (#)

    listen_addresses = '*'
  3. pg_hba.conf

    中添加以下行

    #TYPE 数据库用户 CIDR 地址方法

    host  all  all 0.0.0.0/0 md5
  4. 重启服务:
    (Ubuntu) sudo service postgresql restart

关于postgresql(远程)连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37809663/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com