2016-06-14 104 views
1

我的错误:PostgreSQL的(远程)连接被拒绝

# 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? 
+0

你是否介意从拒绝连接的实例中发布pg_hba.conf的完整内容?说实话,它看起来像是一个IPTABLES问题,但是应该允许localhost连接,IPTABLES不解释这个问题。 – d1ll1nger

+0

1)'数据库运行正常,但只能在本地......'什么是本地*,你怎么知道DBMS运行良好? 2)postgres日志文件中有什么?如果有任何连接尝试,它们将被记录。 – joop

回答

1

执行以下

更新/var/lib/pgsql/<version>/data/postgresql.conf

变化#listen_addresses = 'localhost' to listen_addresses = '*'

重启服务