rpm安装mongodb后根据网上的方法,进行操作开启远程登录:
(1)sudo vim /etc/mongod.conf
把BindIp:127.0.0.1这行注释,之后systemctl start mongod.service重启mongodb
(2)linux虚机防火墙关闭后开放27017端口
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT
之后在另外一台linux机器上执行 mongo IP:27017,还是登录不成功:
[root@localhost mongodb]# mongo 1xx.9x.1x.1xx:27017
MongoDB shell version v4.2.18
connecting to: mongodb://1xx.9x.1x.1xx:27017/test?compressors=disabled&gssapiServiceName=mongodb
2022-08-24T11:36:18.553+0800 E QUERY [js] Error: couldn't connect to server 1xx.9x.1x.1xx:27017, connection attempt failed: SocketException: Error connecting to 1xx.9x.1x.1xx:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:353:17
@(connect):2:6
2022-08-24T11:36:18.555+0800 F - [main] exception: connect failed
2022-08-24T11:36:18.555+0800 E - [main] exiting with code 1
求解惑
注释掉并不代表取消掉,试试
BindIp:0.0.0.0
谢谢!不用注释的方式直接修改之后可以了!!但之前我也试过这种方式,就很迷......