LoginSignup
36
30

More than 5 years have passed since last update.

mongodbが起動しない

Last updated at Posted at 2015-07-06

mongodbに接続できなくなった

$ mongo
MongoDB shell version: 2.6.3
connecting to: test
2015-07-06T16:37:10.218+0900 warning: Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2015-07-06T16:37:10.219+0900 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

強制終了とかすると mongod.lock というファイルが残り、起動できなくなるらしい

解決法

mongod.lock を削除して mongod --repair を実行する

解決できなかった

$ sudo mongod --repair
~
*********************************************************************
 ERROR: dbpath (/data/db) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
2015-07-06T17:04:45.439+0900 [initandlisten] dbexit: 
2015-07-06T17:04:45.439+0900 [initandlisten] shutdown: going to close listening sockets...
2015-07-06T17:04:45.439+0900 [initandlisten] shutdown: going to flush diaglog...
2015-07-06T17:04:45.439+0900 [initandlisten] shutdown: going to close sockets...
2015-07-06T17:04:45.439+0900 [initandlisten] shutdown: waiting for fs preallocator...
2015-07-06T17:04:45.439+0900 [initandlisten] shutdown: closing all files...
2015-07-06T17:04:45.440+0900 [initandlisten] closeAllFiles() finished
2015-07-06T17:04:45.440+0900 [initandlisten] dbexit: really exiting now

/data/db がないよとエラーが出た
こちらを参考にもともとのデータがあった場所とシンボリックリンクを作成させた

mongod -dbpath /usr/local/var/mongodb

再度解決

mongod --repair させてmongod起動した後mongoコマンド実行したら接続できた

参考

http://azwoo.hatenablog.com/entry/2014/04/19/224644
http://qiita.com/hidesuke/items/56a87d827708c8c770da

36
30
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
36
30