gpt4 book ai didi

database - 打开ubuntu防火墙和mongod.conf后无法远程连接mongodb

转载 作者:行者123 更新时间:2023-12-04 18:36:17 25 4
gpt4 key购买 nike

在 Linode 上的 ubuntu 20.10 服务器上全新安装 mongodb 时无法远程连接到 mongodb。

root@localhost:~# sudo ufw status
Status: active

To Action From
-- ------ ----
22 ALLOW Anywhere
27017 ALLOW 0.0.0.0
22 (v6) ALLOW Anywhere (v6)
/etc/mongod.conf
net:
port: 27017
bindIp: 0.0.0.0
mongo 服务器已启动并正在运行
root@localhost:~# sudo service mongod status
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2021-04-04 18:34:05 UTC; 19min ago
Docs: https://docs.mongodb.org/manual
Main PID: 1332 (mongod)
Memory: 161.0M
CGroup: /system.slice/mongod.service
└─1332 /usr/bin/mongod --config /etc/mongod.conf

Apr 04 18:34:05 localhost systemd[1]: Started MongoDB Database Server.
运行 mongo 服务器的主机上的 netstat
root@localhost:~# sudo netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 1332/mongod
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 640/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 817/sshd: /usr/sbin
tcp6 0 0 :::22 :::* LISTEN 817/sshd: /usr/sbin
udp 0 0 127.0.0.53:53 0.0.0.0:* 640/systemd-resolve
nc -zv IP_ADDRESS 27017超时,所以 mongo -u $DB_USERNAME -p $DB_PASSWORD IP_ADDRESS/admin也会超时 nc -zv IP_ADDRESS 22按预期工作

最佳答案

通过执行 sudo ufw allow 27017 解决而不是 sudo ufw allow from 0.0.0.0 to any port 27017

root@localhost:~# sudo ufw status
Status: active

To Action From
-- ------ ----
22 ALLOW Anywhere
27017 ALLOW Anywhere
22 (v6) ALLOW Anywhere (v6)
27017 (v6) ALLOW Anywhere (v6)

关于database - 打开ubuntu防火墙和mongod.conf后无法远程连接mongodb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66944769/

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