所以我在使用AWS和EC2,并试图为Postgresql打开一个端口.在AWS中,我已经打开了它:

TCP
Port (Service)      Source                  Action
0 - 65535           sg-92aadda2 (default)   Delete
22 (SSH)            0.0.0.0/0               Delete
80 (HTTP)           0.0.0.0/0               Delete
5432                0.0.0.0/0               Delete

当我使用netstat时,端口似乎正在侦听:

# netstat -an | grep 5432
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN

在执行localhost nmap时,我会得到以下结果:

 Nmap scan report for localhost (127.0.0.1)
 Host is up (0.000010s latency).
 Not shown: 997 closed ports
 PORT      STATE SERVICE
 22/tcp    open  ssh
 80/tcp    open  http
 5432/tcp  open  postgresql

这就是乐趣的开始.当我从备用主机执行nmap时,我会得到以下结果:

PORT      STATE  SERVICE
22/tcp    open   ssh
80/tcp    open   http
5432/tcp  closed postgresql

我还查看了我的iptables,看看我是否遗漏了什么,但iptables看起来是空的(这应该意味着它们实际上做的不多)

$ iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
REJECT     all  --  anywhere             127.0.0.0/8          reject-with icmp-port-unreachable
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:https
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:postgresql
ACCEPT     icmp --  anywhere             anywhere
LOG        all  --  anywhere             anywhere             limit: avg 5/min burst 5 LOG level debug prefix "iptables denied: "
DROP       all  --  anywhere             anywhere

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
DROP       all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere

我是不是因为不知道如何访问ip而错过了什么.每当我try 时,都会出现以下错误:

Is the server running on host "xx.xx.xx.xx" and accepting TCP/IP connections on port 5432?

我如何才能打开端口,以便外部服务器可以访问它?如果你需要任何额外的数据,请告诉我.

EDIT:正如下面所问的,我测试了telnet,我能够将telnet连接到本地主机,但当从外部try 时,我得到:

$ telnet xx.xx.xx.xx 5432
Trying xx.xx.xx.xx...
telnet: Unable to connect to remote host: Connection refused

此外,我再次判断,并正确地将telnet连接到ssh:

$ telnet xx.xx.xx.xx 22
Trying xx.xx.xx.xx...
Connected to xx.xx.xx.xx.
Escape character is '^]'.
SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.1

推荐答案

编辑/etc/postgresql/<version>/main/postgresql.conf并将listen_addresses设置为传出界面或全部.重新启动postgresql:sudo service postgresql restart.

Postgresql相关问答推荐

Keycloak和PostgreSQL

Org.postgresql.util.PSQLException:错误:函数LOWER(BYTEA)不存在

PostgreSQL存储过程中不存在游标

使用postgres在go测试容器中使用tern迁移

EF Core和npgsql连接池已被耗尽

如何包装 record_out() 函数?

heroku、postgreSQL、django、comments、tastepie:没有运算符匹配给定的名称和参数类型

postgresql 更新错误ERROR: invalid input syntax for type boolean:

PostgreSQL:是否可以将枚举转换为整数?

INSERT RETURNING 是否保证以 right的顺序返回?

PostgreSQL 中的 JSON 外键

如何让 Rails 使用 SSL 连接到 PostgreSQL?

Rails 4 迁移: has_and_belongs_to_many table name

Postgres - 如果找不到记录,则在更新时返回错误

在 Windows 10 中执行时,Docker 容器关闭并给出data directory has wrong ownership错误

Rails:PG :: InsufficientPrivilege:错误:permission denied for relation schema_migrations

每个数据库提供程序类型允许的最大参数数是多少?

Postgres Hstore 与 Redis - 性能方面

PL/pgSQL 执行与执行

重命名 Amazon RDS 主用户名