MongoDB - 无法连接到127.0.0.1:27017,原因:错误:111连接被拒绝

时间:2017-03-29 09:46:16

标签: node.js mongodb express

之前我遇到过这个问题,并通过重新启动mongo来修复:

$ sudo systemctl start mongodb

但我又遇到了这个问题,我试图像以前一样重新启动它。但这次不会奏效!

$ mongo
MongoDB shell version: 3.2.6
connecting to: test
2017-03-29T10:48:44.306+0100 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2017-03-29T10:48:44.307+0100 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6

exception: connect failed

我也试过了:

1)删除.lock文件

sudo rm /var/lib/mongodb/mongod.lock 

2)修复mongodb

mongod –repair

3)启动mongodb

$ sudo systemctl start mongodb

4)启动mongo客户端

$ mongo

... i get the same error above!

任何想法我还能做些什么?

修改

$ sudo systemctl status mongodb.service
● mongodb.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/usr/lib/systemd/system/mongodb.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2017-03-29 10:48:38 BST; 27min ago
  Process: 31841 ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf (code=exited, status=1/FAILURE)
 Main PID: 31841 (code=exited, status=1/FAILURE)

Mar 29 10:48:38 li1371-52.members.linode.com systemd[1]: Started High-performance, schema-free document-oriented database.
Mar 29 10:48:38 li1371-52.members.linode.com systemd[1]: mongodb.service: Main process exited, code=exited, status=1/FAILURE
Mar 29 10:48:38 li1371-52.members.linode.com systemd[1]: mongodb.service: Unit entered failed state.
Mar 29 10:48:38 li1371-52.members.linode.com systemd[1]: mongodb.service: Failed with result 'exit-code'.

编辑2:

$ mongod
2017-03-29T11:59:15.178+0100 I CONTROL  [initandlisten] MongoDB starting : pid=1014 port=27017 dbpath=/data/db 64-bit host=li1371-52.members.linode.com
2017-03-29T11:59:15.178+0100 I CONTROL  [initandlisten] db version v3.2.6
2017-03-29T11:59:15.178+0100 I CONTROL  [initandlisten] git version: 05552b562c7a0b3143a729aaa0838e558dc49b25
2017-03-29T11:59:15.178+0100 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2h  3 May 2016
2017-03-29T11:59:15.178+0100 I CONTROL  [initandlisten] allocator: tcmalloc
2017-03-29T11:59:15.178+0100 I CONTROL  [initandlisten] modules: none
2017-03-29T11:59:15.178+0100 I CONTROL  [initandlisten] build environment:
2017-03-29T11:59:15.178+0100 I CONTROL  [initandlisten]     distarch: x86_64
2017-03-29T11:59:15.178+0100 I CONTROL  [initandlisten]     target_arch: x86_64
2017-03-29T11:59:15.178+0100 I CONTROL  [initandlisten] options: {}
2017-03-29T11:59:15.204+0100 E NETWORK  [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2017-03-29T11:59:15.204+0100 I -        [initandlisten] Fatal Assertion 28578
2017-03-29T11:59:15.204+0100 I -        [initandlisten] 

***aborting after fassert() failure

编辑3:

$ sudo mongod
2017-03-29T12:05:54.159+0100 I CONTROL  [initandlisten] MongoDB starting : pid=4075 port=27017 dbpath=/data/db 64-bit host=li1371-52.members.linode.com
2017-03-29T12:05:54.159+0100 I CONTROL  [initandlisten] db version v3.2.6
2017-03-29T12:05:54.159+0100 I CONTROL  [initandlisten] git version: 05552b562c7a0b3143a729aaa0838e558dc49b25
2017-03-29T12:05:54.159+0100 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2h  3 May 2016
2017-03-29T12:05:54.159+0100 I CONTROL  [initandlisten] allocator: tcmalloc
2017-03-29T12:05:54.159+0100 I CONTROL  [initandlisten] modules: none
2017-03-29T12:05:54.159+0100 I CONTROL  [initandlisten] build environment:
2017-03-29T12:05:54.159+0100 I CONTROL  [initandlisten]     distarch: x86_64
2017-03-29T12:05:54.159+0100 I CONTROL  [initandlisten]     target_arch: x86_64
2017-03-29T12:05:54.159+0100 I CONTROL  [initandlisten] options: {}
2017-03-29T12:05:54.185+0100 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2017-03-29T12:05:54.185+0100 I CONTROL  [initandlisten] dbexit:  rc: 100

1 个答案:

答案 0 :(得分:3)

我使用mongodb重新启动了brew服务,它有所帮助:

brew services stop mongodb
brew services start mongodb