2016-06-14 501 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 = '*'

重啓服務