MongoDB服务启动bug
It has been 439 days since the last update, the content of the article may be outdated.
在linux单机部署MongoDB时,指定配置文件运行时报错
报错内容
shell
1 | child process failed, exited with error number 48 |
报错原因
没有正常关闭mongodb引起的,比如直接 kill -9
导致
解决方法
1.找到mongod.lock文件,并删除mongod.lock
2.以修复方式启动mongodb
shell
1 | /usr/bin/mongod -f /etc/mongod.conf --repair |
3.然后接着在启动一次
shell
1 | /usr/bin/mongod -f /etc/mongod.conf --auth |
(实测只采用步骤2即可启动成功)
正确关闭mongodb的方法
warning:千万不能使用kill -9
,因为MongoDB使用mmap方式进行数据文件管理,也就是说写操作基本是在内存中进行,写操作会被每隔60秒(syncdelay设定)的flush到磁盘里。如果在这60秒内flush处于停止事情我们进行kill -9那么从上次flush之后的写入数据将会全部丢失。
如果在flush操作进行时执行kill -9则会造成文件混乱,可能导致数据全丢了,启动时加了repair也无法恢复。
shell
1 | # 建议使用 |
评论