jingxinxin / tiankeng

记录程序猿开发过程中已经遇到的各种坑,再记录解决方法 / Record the various pits that have been encountered during the development process, and then record the solution.
2 stars 0 forks source link

Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js #4

Open jingxinxin opened 6 years ago

jingxinxin commented 6 years ago
[jack@iZ114ypdot6Z ~]$ mongo
MongoDB shell version: 2.6.12
connecting to: test
2017-10-20T15:06:10.345+0800 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2017-10-20T15:06:10.346+0800 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146

▽
exception: connect failed

首先明白就是链接失败,是否是服务器重启,mongo服务没有设置自动启动,可以首先启动mongo服务再试试

启动MongoDB

$ sudo systemctl start mongod.service

查看是否启动成功

$ sudo systemctl status mongod.service

若显示 active(running)则启动成功!或者

$ sudo cat /var/log/mongodb/mongod.log

如出现 [thread1] waitingforconnectionsonport

其中的默认为27017,在 /etc/mongod.conf中配置,则启动成功!