输入mongo,报如下错误:
root@instance-tbbjrcnc:/# mongo
MongoDB shell version v4.0.12
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2019-08-12T10:40:58.930+0800 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:344:17
@(connect):2:6
exception: connect failed
原因是mongo没有启动
解决方式一:
创建目录 /data/db
cd /
mkdir data
cd data
mkdir db
查找到mongo的安装路径
root@instance-tbbjrcnc:/# whereis mongo
mongo: /usr/bin/mongo
然后手动启动mongo
root@instance-tbbjrcnc:/# cd /usr/bin/
root@instance-tbbjrcnc:/usr/bin# sudo ./mongod -dbpath /data/db/
启动成功!
方法二:创建 service 启动,使用命令启动:service mongodb restart
https://blog.csdn.net/cocos2dGirl/article/details/99300471
方法三:
https://stackoverflow.com/questions/45691032/mongod-service-start-exits-with-code-100
参考:https://blog.csdn.net/qq_39729527/article/details/81285405