更改端口时出现错误“ psql:无法连接到服务器”

时间:2020-01-30 14:32:29

标签: psql haproxy

我试图通过标准的其他端口连接到服务器,并且出现以下错误:

[root@pgsql01 ~]# sudo su - postgres -c '/usr/pgsql-11/bin/psql -t -U postgres -p 5000 -c "select pg_is_in_recovery()"'
psql: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5000"?

[root@postgresql01 ~]# telnet pgsql01 5000
Trying 172.16.16.171...
Connected to pgsql01.
Escape character is '^]'.
Connection closed by foreign host.

授权设置似乎正确:

[root@pgsql01 ~]# cat /var/lib/pgsql/11/data/pg_hba.conf | grep trust | grep post
host    postgres       postgres       172.16.16.171/32        trust
host    postgres       postgres       172.16.16.172/32        trust





[root@pgsql01 ~]# netstat -putan | grep LISTEN | egrep '5432|500'
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      128476/postmaster
tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      137571/haproxy
tcp        0      0 0.0.0.0:5001            0.0.0.0:*               LISTEN      137571/haproxy
tcp6       0      0 :::5432                 :::*                    LISTEN      128476/postmaster

我正在使用HAProxy访问服务器:

/etc/haproxy/haproxy.cfg

listen ReadWrite
    bind *:5000
    option httpchk
    http-check expect status 206
    default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
    server pgsql01 pgsql01:5432 maxconn 100 check port 23267
    server pgsql02 pgsql02:5432 maxconn 100 check port 23267
listen ReadOnly
    bind *:5001
    option httpchk
    http-check expect status 206
    default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
    server pgsql01 pgsql01:5432 maxconn 100 check port 23267
    server pgsql02 pgsql02:5432 maxconn 100 check port 23267


[root@pgsql01 ~]# cat /etc/services | grep pgsqlchk
pgsqlchk        23267/tcp               # pgsqlchk

[root@pgsql01 ~]# cat /etc/xinetd.d/pgsqlchk
service pgsqlchk
{
        flags           = REUSE
        socket_type     = stream
        port            = 23267
        wait            = no
        user            = nobody
        server          = /opt/pgsqlchk
        log_on_failure  += USERID
        disable         = no
        only_from       = 0.0.0.0/0
        per_source      = UNLIMITED
}

是否需要授权访问特定端口,否则会发生什么? (我没有启用防火墙或iptables)

谢谢!

0 个答案:

没有答案
相关问题