【发布时间】:2021-11-20 07:26:06
【问题描述】:
我正在尝试远程连接到 Postgresql (v9.6),但似乎无法连接。我的 Postgres 驻留在 CentOS 7 服务器上。从该服务器上,我为各种网站提供服务(在端口 80xx 上),并且我还在成功地使用端口 5050 上的服务。似乎只有端口 5432 有问题。例如:
$ lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.4.1708 (Core)
Release: 7.4.1708
Codename: Core
$ sudo firewall-cmd --zone=public --add-port=5432/tcp --permanent
Warning: ALREADY_ENABLED: 5432:tcp
success
$ sudo firewall-cmd --reload
success
$ sudo iptables -S | grep "5432"
-A IN_public_allow -p tcp -m tcp --dport 5432 -m conntrack --ctstate NEW -j ACCEPT
$ netstat -nlp | grep 5432
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN -
tcp6 0 0 ::1:5432 :::* LISTEN -
unix 2 [ ACC ] STREAM LISTENING 516044892 - /var/run/postgresql/.s.PGSQL.5432
unix 2 [ ACC ] STREAM LISTENING 516044894 - /tmp/.s.PGSQL.5432
这就是我的工作:
> psql -h xx.xx.xx.xx -p 5432 -U postgres
psql: could not connect to server: Connection refused
Is the server running on host "xx.xx.xx.xx" and accepting
TCP/IP connections on port 5432?
这是我的 pg_hba.conf
host all all 127.0.0.1/32 ident
host all all ::1/128 ident
host all all 172.17.0.0/24 trust
host all all 0.0.0.0/0 md5
我还修改了postgresql.conf,在5432端口监听'*'并重启了服务器。
我错过了什么?
PS:我可以在本地连接,因为我的一些 Web 应用程序正在使用此服务器来存储数据。
编辑:这样可以吗?
$ netstat -tulpn | awk 'NR==2 || /:5432/'
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN -
tcp6 0 0 ::1:5432 :::* LISTEN -
【问题讨论】:
标签: postgresql centos