1. 防火墙
1) ping不通,则一般是防火墙未开放IP。
2) 若可以ping通,但telnet不通,则是开放了IP段访问但未开放端口。
以上问题,要么就关闭防火墙。
systemctl stop firewalld.service && systemctl disable firewalld.service
要么就打开IP和端口的对外访问。
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.101.33" port protocol="tcp" port="80" accept"firewall-cmd --zone=public --add-port=5432/tcp --permanentfirewall-cmd --reload
记住,firewall一定要执行reload命令才生效。
2. PG数据库配置
1) postgres.conf未开启访问IP限制
检查改文件的listen_address选项
listen_addresses = 'localhost'
默认是如上的localhost,仅监听了本机的访问,需修改允许远程访问。
listen_addresses = '*'
记得重启数据库
systemctl restart postgresql.service
2) pg_hba.conf文件的登录限制
# TYPE DATABASE USER ADDRESS METHODlocal all all md5# IPv4 local connections:host all all 127.0.0.1/32 md5# IPv6 local connections:host all all ::1/128 md5# Allow replication connections from localhost, by a user with the# replication privilege.local replication all md5host replication all 127.0.0.1/32 md5host replication all ::1/128 md5
上面未允许其他IP对数据库的访问权限,所以在IPv4下,增加一行远程访问的权限。
# TYPE DATABASE USER ADDRESS METHODhost all all 0.0.0.0/0 md5
记得重启数据库:
systemctl restart postgresql.service
