mongodb启动不了:child process failed, exited with error number 48

问题:

启动mongodb的时候,发现起不来,报错:child process failed, exited with error number 48然后先去/var/log/mongo/mongod.log 查看启动的日志

 

可能原因:

应该是没有正常关闭mongodb引起的,比如直接 kill -9 <pid>导致

 

解决方法:

1.找到mongod.lock文件,并删除mongod.lock

 

2.以修复方式启动mongodb

/usr/bin/mongod -f /etc/mongod.conf --repair

 

3.然后接着在启动一次

/usr/bin/mongod -f /etc/mongod.conf --auth

 

4.查看进程是否运行

ps aux|grep mongo

 

正确关闭mongodb的方法

 

warning:千万不能使用kill -9 <pid>,因为MongoDB使用mmap方式进行数据文件管理,也就是说写操作基本是在内存中进行,写操作会被每隔60秒(syncdelay设定)的flush到磁盘里。如果在这60秒内flush处于停止事情我们进行kill -9那么从上次flush之后的写入数据将会全部丢失。
如果在flush操作进行时执行kill -9则会造成文件混乱,可能导致数据全丢了,启动时加了repair也无法恢复。

 

 

官方文档:https://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/

Stop mongod Processes

In a clean shutdown a mongod completes all pending operations, flushes all data to data files, and closes all data files. Other shutdowns are unclean and can compromise the validity of the data files.

To ensure a clean shutdown, always shutdown mongod instances using one of the following methods:

Use shutdownServer()

Shut down the mongod from the mongo shell using the db.shutdownServer() method as follows:

use admin
db.shutdownServer()

Calling the same method from a init script accomplishes the same result.

For systems with authorization enabled, users may only issue db.shutdownServer() when authenticated to the admin database or via the localhost interface on systems without authentication enabled.

Use --shutdown

From the Linux command line, shut down the mongod using the --shutdown option in the following command:

mongod --shutdown

Use CTRL-C

When running the mongod instance in interactive mode (i.e. without --fork), issue Control-C to perform a clean shutdown.

Use kill

From the Linux command line, shut down a specific mongod instance using the following command:

kill <mongod process ID>

WARNING

Never use kill -9 (i.e. SIGKILL) to terminate a mongod instance.

posted @ 2016-02-15 13:59  joshua317  阅读(34638)  评论(0编辑  收藏  举报