gpt4 book ai didi

postgresql - 在 Ubuntu 中打开端口

转载 作者:行者123 更新时间:2023-11-29 11:09:02 28 4
gpt4 key购买 nike

所以我正在使用 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。每当我尝试时,我都会收到以下错误:

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

如何才能打开端口以便外部服务器可以访问它?提前致谢 =) 让我知道您是否需要任何其他数据。

编辑:如下所述,我测试了远程登录,我能够远程登录到本地主机,但是当从外部尝试时,我得到:

$ 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到您的传出接口(interface)或全部。重启 postgresql:sudo service postgresql restart .

关于postgresql - 在 Ubuntu 中打开端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17838613/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com