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.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM