共计 2120 个字符,预计需要花费 6 分钟才能阅读完成。
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
produced by yaong!
正文完