继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

MongoDB服务启动异常 status=14

yaong
关注TA
已关注
手记 8
粉丝 1
获赞 3

MongoDB进程 kill -9之后导致服务起不来了

[root@yaong etc]# systemctl status mongod.service
● mongod.service - MongoDB Database Server
......
  Process: 9526 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
......
Aug 19 10:26:12 yaong systemd[1]: mongod.service: control process exited, code=exited status=14
......

从网上找了找相关资料,大致说法是:mongo内存管理很特殊,kill -9 很可能影响存库操作

如果不是在写磁盘的时候宕掉,可以通过repair命令进行修复,会丢失最后一次写磁盘的时刻到宕掉时刻期间的数据

如果赶上写磁盘的时候进程宕掉,repair也不能恢复数据,很可能会丢失掉全部数据

尝试进行修复

[root@yaong etc]# /usr/bin/mongod -f /etc/mongod.conf --repair
about to fork child process, waiting until server is ready for connections.
forked process: 9575
child process started successfully, parent exiting

再次查看服务状态

[root@yaong etc]# systemctl status mongod.service
● mongod.service - MongoDB Database Server
   Active: failed (Result: exit-code) since Thu 2021-08-19 10:27:05 CST; 6s ago
  Process: 9618 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=1/FAILURE)
 ......
Aug 19 10:27:05 yaong systemd[1]: mongod.service: control process exited, code=exited status=1
......

燃鹅还是存在其他问题,鉴于库里没有存啥数据,统统干掉,重头再来

rm -rf /var/lib/mongo/*
rm -rf /var/log/mongodb/*
cat /var/run/mongodb/mongod.pid
rm -rf /data/db/mongod.lock
rm -rf /var/lib/mongo/mongod.lock

再次启动服务,服务就起来了

[root@yaong mongodb]# systemctl restart mongod
[root@yaong mongodb]# systemctl status mongod.service
● mongod.service - MongoDB Database Server
   Active: active (running) since Thu 2021-08-19 10:47:14 CST; 3s ago
     Docs: https://docs.mongodb.org/manual
  Process: 10836 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
	......
 Main PID: 10839 (mongod)
   CGroup: /system.slice/mongod.service
           └─10839 /usr/bin/mongod -f /etc/mongod.conf
					 
[root@yaong etc]# ps -ef | grep mongo
mongod   10839     1  0 10:47 ?        00:00:22 /usr/bin/mongod -f /etc/mongod.conf
root     15949  1627  0 12:25 pts/0    00:00:00 grep --color=auto mongo

至此,提醒大家停止mongo进程一定要谨慎,推荐三种较稳妥的方式:

交互模式下:

use admin
db.shutdownServer()

mongo命令:

mongod --shutdown

系统命令

kill

除了服务启动模式,还可以命令行后台启动

mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork
[root@yaong etc]# ps -ef | grep mongo
root     10222     1  5 10:37 ?        00:00:01 mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork
root     10281  1627  0 10:38 pts/0    00:00:00 grep --color=auto mongo

与之对应的是停止进程的命令

mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --shutdown
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP