- 首先连接不上,先查看云服务器上的安全组是否添加了对应的端口
- 如果打开了,那么久查看MongoDB是否允许远程连接
# mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # Where and how to store data. storage: dbPath: /var/lib/mongodb journal: enabled: true # engine: # mmapv1: # wiredTiger: # where to write logging data. systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log # network interfaces net: port: 27017 bindIp: 0.0.0.0 #processManagement: #security: #operationProfiling: #replication: #sharding: ## Enterprise-Only Options: #auditLog: #snmp:
重点查看net下的bindIp,如果是127.0.0.1的话就改成0.0.0.0
使用启动命令:
sudo systemctl start mongod
因为使用
sudo service mongodb start
会报错
查看MongoDB的日志:
cat /var/log/mongodb/mongod.log
如果报错是:
Detected unclean shutdown - /var/lib/mongodb/mongod.lock is not empty.
那就直接删除掉那个文件
rm -rf /var/lib/mongodb/mongod.lock
如果报错为:
Failed to unlink socket file /tmp/mongodb-27017.sock Operation not permitted
那就直接删除掉那个文件:
rm -rf /tmp/mongodb-27017.sock
如果报错为:
WiredTiger error (13) [1543829280:361502][14474:0x7f42abbdad00], file:WiredTiger.wt, connection: /var/lib/mongodb/WiredTiger.turtle: handle-open: open: Permission denied
那就提升权限:
sudo chown -R mongodb:mongodb /var/lib/mongodb
然后使用
sudo systemctl start mongod
启动即可