MongoDBが急に起動できなくなった時の対処法

なぜだか分からないけど急にmongoシェルが起動できなくなっていた。
OSはCentOS 6.7

```bash
$ mongo
MongoDB shell version: 2.6.11
connecting to: test
2015-12-17T22:20:51.737+0900 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-12-17T22:20:51.738+0900 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/
```
mongodが落ちたらしい。
起動しようとすると失敗するのでログを探ってみると。

```bash
$ sudo service mongod start
Starting mongod:                                           [FAILED]
$ sudo tail /var/log/mongodb/mongod.log
2015-12-17T22:13:46.302+0900 ***** SERVER RESTARTED *****
2015-12-17T22:13:46.308+0900 [initandlisten] MongoDB starting : pid=32733 port=27017 dbpath=/var/lib/mongo 64-bit host=tk2-228-23968.vs.sakura.ne.jp
2015-12-17T22:13:46.308+0900 [initandlisten] db version v2.6.11
2015-12-17T22:13:46.308+0900 [initandlisten] git version: d00c1735675c457f75a12d530bee85421f0c5548
2015-12-17T22:13:46.308+0900 [initandlisten] build info: Linux build4.ny.cbi.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2015-12-17T22:13:46.308+0900 [initandlisten] allocator: tcmalloc
2015-12-17T22:13:46.308+0900 [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1" }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/var/lib/mongo" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2015-12-17T22:13:46.312+0900 [initandlisten] journal dir=/var/lib/mongo/journal
2015-12-17T22:13:46.312+0900 [initandlisten] recover : no journal files present, no recovery needed
2015-12-17T22:13:46.360+0900 [initandlisten] couldn't open /var/lib/mongo/local.ns errno:13 Permission denied
2015-12-17T22:13:46.360+0900 [initandlisten] error couldn't open file /var/lib/mongo/local.ns terminating
2015-12-17T22:13:46.360+0900 [initandlisten] dbexit:
2015-12-17T22:13:46.360+0900 [initandlisten] shutdown: going to close listening sockets...
2015-12-17T22:13:46.360+0900 [initandlisten] shutdown: going to flush diaglog...
2015-12-17T22:13:46.360+0900 [initandlisten] shutdown: going to close sockets...
2015-12-17T22:13:46.360+0900 [initandlisten] shutdown: waiting for fs preallocator...
2015-12-17T22:13:46.360+0900 [initandlisten] shutdown: lock for final commit...
2015-12-17T22:13:46.360+0900 [initandlisten] shutdown: final commit...
2015-12-17T22:13:46.360+0900 [initandlisten] shutdown: closing all files...
2015-12-17T22:13:46.360+0900 [initandlisten] closeAllFiles() finished
2015-12-17T22:13:46.360+0900 [initandlisten] journalCleanup...
2015-12-17T22:13:46.360+0900 [initandlisten] removeJournalFiles
2015-12-17T22:13:46.361+0900 [initandlisten] shutdown: removing fs lock...
2015-12-17T22:13:46.361+0900 [initandlisten] dbexit: really exiting now
```

どうやらパーミッションの問題らしいことが分かった。
参考URLによると、mongodbのディレクトリの中身のはmongodユーザでアクセスするらしいので、オーナーを全部mongodにした。

```bash
$ sudo chown -R mongod:mongod /var/lib/mongo
```

とりあえずこれで直った。

```bash
$ sudo service mongod start
Starting mongod:                                           [  OK  ]
```
なぜこんなことが起こってしまったのか原因は不明(´・ω・｀)



###参考
[can't start mongodb as sudo - Stack Overflow](http://stackoverflow.com/questions/6819852/cant-start-mongodb-as-sudo)