MongoDB 启动报错

由于我之前执行kill -9 mongo进程号,导致再次启动时报如下错误:

[mongo@myfirst mongodb]$ ../mongodb/bin/mongod -f mongo.conf --fork
about to fork child process, waiting until server is ready for connections.
forked process: 18287
ERROR: child process failed, exited with error number 14
To see additional information in this output, start without the "--fork" option.
[mongo@myfirst mongodb]$ kill -9 18287
-bash: kill: (18287) - No such process

情况一:【进程 18287存在】

如果如提示的进程 18287存在,执行如下:

kill -9 18287

然后在data目录下找到mongod.lock文件删除

rm rf data/db/mongod.lock

执行:

mongodb/bin/mongod -f mongo.conf --repair

之后再正常启动

mongodb/bin/mongod -f mongo.conf --fork

情况二:【进程 18287不存在】

此时执行 kill -9 18287是失败的如下:

[mongo@myfirst mongodb]$ kill -9 18287
-bash: kill: (18287) - No such process

这是删除mongod.lock文件后,加上–repair也报错

[mongo@myfirst mongodb]$ ../mongodb/bin/mongod -f mongo.conf --repair
about to fork child process, waiting until server is ready for connections.
forked process: 19554
ERROR: child process failed, exited with error number 100
To see additional information in this output, start without the "--fork" option.

此时需要先把mongod.lock删除,然后找到同目录下的 _repair_incomplete 也删除
之后正常启动即可:

[mongo@myfirst db]$ rm mongod.lock 
[mongo@myfirst db]$ rm _repair_incomplete
[mongo@myfirst mongodb]$ bin/mongod -config mongo.conf --fork
about to fork child process, waiting until server is ready for connections.
forked process: 31928
child process started successfully, parent exiting

注意:

非正常关闭MongoDB是会产生lock文件和repair文件,
测试一般的kill + 进程号操作后,删除lock文件,使用 --repair进行恢复即可;
kill -9 进程号 无法进行恢复,此时需要丢失部分操作数据才可启动,为不完整修复吧

MongoDB配置参数说明:
https://www.cnblogs.com/phpzhou/articles/5390042.html

Logo

一站式 AI 云服务平台

更多推荐