2017-03-08 194 views
1

我正在使用Linux VM(Ubuntu 15.10)启动Postgres数据库,据我所知,一切都应该配置正确。无法让PostgreSQL 9.4侦听端口5432

我的防火墙被禁用:

[email protected]:~$ sudo ufw status numbered Status: inactive 

但它只是在端口22上

[email protected]:~$ netstat -an | grep "LISTEN " 
tcp  0  0 0.0.0.0:22    0.0.0.0:*    LISTEN 
tcp6  0  0 :::22     :::*     LISTEN 

听取如果我启用防火墙,并告诉它来听5432,它显示了在规则:

[email protected]:~$ sudo ufw status verbose 
Status: active 
Logging: on (low) 
Default: deny (incoming), allow (outgoing), disabled (routed) 
New profiles: skip 

To       Action  From 
--       ------  ---- 
22       ALLOW IN Anywhere 
22/tcp      ALLOW IN Anywhere 
5432/tcp     ALLOW IN Anywhere 
5432      ALLOW IN Anywhere 
22 (v6)     ALLOW IN Anywhere (v6) 
22/tcp (v6)    ALLOW IN Anywhere (v6) 
5432/tcp (v6)    ALLOW IN Anywhere (v6) 
5432 (v6)     ALLOW IN Anywhere (v6) 

但是我得到了和上面的netstat相同的结果。

据我可以告诉从研究的问题,我有正确的价值观在我的postgresql.conf文件:

#------------------------------------------------------------------------------ 
# CONNECTIONS AND AUTHENTICATION 
#------------------------------------------------------------------------------ 

# - Connection Settings - 

listen_addresses = '*'   # what IP address(es) to listen on; 
             # comma-separated list of addresses; 
             # defaults to 'localhost'; use '*' for all 
             # (change requires restart) 
port = 5432        # (change requires restart) 

,我都试过IP范围和特定IP地址作为pg_hba信任.conf文件。

# Database administrative login by Unix domain socket 
local all    postgres        ident sameuser 

# TYPE DATABASE  USER   ADDRESS     METHOD 

# "local" is for Unix domain socket connections only 
local 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  postgres        peer 
#host replication  postgres  127.0.0.1/32   md5 
#host replication  postgres  ::1/128    md5 

host all    all    10.0.0.0/255   trust 
host all    all    10.11.0.0/255   trust 
host all    all    0.0.0.0/0    trust 

最后,Postgres的运行过程中,每

[email protected]:~$ sudo service postgresql status 
● postgresql.service - PostgreSQL RDBMS 
    Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled) 
    Active: active (exited) since Wed 2017-03-08 11:09:57 CST; 57min ago 
    Process: 787 ExecStart=/bin/true (code=exited, status=0/SUCCESS) 
Main PID: 787 (code=exited, status=0/SUCCESS) 
    CGroup: /system.slice/postgresql.service 

Mar 08 11:09:57 UBUNTUMACHINEsystemd[1]: Starting PostgreSQL RDBMS... 
Mar 08 11:09:57 UBUNTUMACHINEsystemd[1]: Started PostgreSQL RDBMS. 
Mar 08 11:32:21 UBUNTUMACHINEsystemd[1]: Started PostgreSQL RDBMS. 
Mar 08 11:32:26 UBUNTUMACHINEsystemd[1]: Started PostgreSQL RDBMS. 
+0

你能告诉我们错误信息吗? –

+0

我不确定你在找什么;按照我提交的第二个代码块,它不会显示为在端口5432上侦听。 –

+0

'netstat -ltn'说什么? – wildplasser

回答

1
  • 日志告诉我无效CIDR掩码地址10.0.0.0/255
  • :: 255可能会大于32

Postgres拒绝启动,因为它拒绝了网络掩码/255它大于可能的数目(32位)IP地址中的位。您可以认为这对.hba解析器有点挑剔,但也可以考虑配置错误。

在任何情况下:通过一些合理的替代/255,像/24(或/16,因为你有两个这些条目)和:通过一些更安全的替代trust,这似乎工作岗位。