查看日志文件:
root@controller:/var/log/ceilometer# cat ceilometer-api.log
2017-05-31 13:57:31.620 23249 TRACE ceilometer.api.hooks ConnectionFailure: could not connect to controller:27017: [Errno 111] ECONNREFUSED
2017-05-31 13:57:31.620 23249 TRACE ceilometer.api.hooks
2017-05-31 13:57:31.749 23249 INFO ceilometer.storage.mongo.utils [-] Connecting to mongodb on [('controller', 27017)]
2017-05-31 13:57:31.750 23249 WARNING ceilometer.storage.mongo.utils [-] Unable to connect to the database server: could not connect to controller:27017: [Errno 111] ECONNREFUSED.
2017-05-31 13:57:41.751 23249 INFO ceilometer.storage.mongo.utils [-] Connecting to mongodb on [('controller', 27017)]
2017-05-31 13:57:41.751 23249 WARNING ceilometer.storage.mongo.utils [-] Unable to connect to the database server: could not connect to controller:27017: [Errno 111] ECONNREFUSED.
2017-05-31 13:57:51.752 23249 INFO ceilometer.storage.mongo.utils [-] Connecting to mongodb on [('controller', 27017)]
2017-05-31 13:57:51.752 23249 WARNING ceilometer.storage.mongo.utils [-] Unable to connect to the database server: could not connect to controller:27017: [Errno 111] ECONNREFUSED.
2017-05-31 13:58:01.762 23249 INFO ceilometer.storage.mongo.utils [-] Connecting to mongodb on [('controller', 27017)]
2017-05-31 13:58:01.762 23249 WARNING ceilometer.storage.mongo.utils [-] Unable to connect to the database server: could not connect to controller:27017: [Errno 111] ECONNREFUSED.
根据日志文件判断为 Mongodb的错误。
root@controller:/var/log/mongodb# cat mongodb.log
***** SERVER RESTARTED *****
Wed May 31 11:25:53.786 [initandlisten] MongoDB starting : pid=1779 port=27017 dbpath=/var/lib/mongodb 64-bit host=controller
Wed May 31 11:25:53.786 [initandlisten] db version v2.4.9
Wed May 31 11:25:53.786 [initandlisten] git version: nogitversion
Wed May 31 11:25:53.786 [initandlisten] build info: Linux orlo 3.2.0-58-generic #88-Ubuntu SMP Tue Dec 3 17:37:58 UTC 2013 x86_64 BOOST_LIB_VERSION=1_54
Wed May 31 11:25:53.786 [initandlisten] allocator: tcmalloc
Wed May 31 11:25:53.786 [initandlisten] options: { bind_ip: "192.168.1.170", config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", logappend: "true", logpath: "/var/log/mongodb/mongodb.log", nojournal: "true", noprealloc: "true", smallfiles: "true" }
**************
**Unclean shutdown detected.**
Please visit http://dochub.mongodb.org/core/repair for recovery instructions.
*************
Wed May 31 11:25:53.797 [initandlisten] exception in initAndListen: 12596 old lock file, terminating
Wed May 31 11:25:53.797 dbexit:
Wed May 31 11:25:53.797 [initandlisten] shutdown: going to close listening sockets...
Wed May 31 11:25:53.797 [initandlisten] shutdown: going to flush diaglog...
Wed May 31 11:25:53.797 [initandlisten] shutdown: going to close sockets...
Wed May 31 11:25:53.797 [initandlisten] shutdown: waiting for fs preallocator...
Wed May 31 11:25:53.797 [initandlisten] shutdown: closing all files...
Wed May 31 11:25:53.797 [initandlisten] closeAllFiles() finished
Wed May 31 11:25:53.797 dbexit: really exiting now
可以看出错误为Unclean shutdown detected. 然后根据此查找方法,解决方案如下,记得要修改数据库文件为 mongdb用户和组。
搞项目时,kill -9 mongo,kill了MongoDB的进程,导致mongodb无法重新启动,查看log文件,发现了如下error log:
**************
Unclean shutdown detected.
Please visit http://dochub.mongodb.org/core/repair for recovery instructions.
*************
[initandlisten] exception in initAndListen: 12596 old lock file, terminating
也就是意外推出时数据被锁定了,登陆mongo给的推荐链接找到了解决办法:
1.删除锁文件,这个锁文件位于你存储data数据的目录
rm /data/db/mongod.lock
2.修复数据文件
mongod --dbpath /data/db --repair
3.重启mongo
mongod --dbpath /data/db
好了,启动成功。
mongo不适合用暴力的方式去kill,正确的关闭方式为:
1、kill -2 PID或者kill PID
2、在admin数据库下运行命令db.shutdownServer();