1、報錯,導致mongodb無法正常啟動。具體命令如下(注意紅色字型,提示日誌路徑,可查看該記錄檔):
[root@oracleLinux ~]# service mongod startStarting mongod: Fri Jan 24 09:59:59.385 Fri Jan 24 09:59:59.386 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.Fri Jan 24 09:59:59.387 about to fork child process, waiting until server is ready for connections.forked process: 2120all output going to: /var/log/mongo/mongod.logERROR: child process failed, exited with error number 100 [失敗]
通過輸出資訊可知,日子檔案為/var/log/mongo/mongod.log
錯誤資訊是:
ERROR: child process failed, exited with error number 100
2、查看mongod.log檔案內容,具體命令如下:
[root@oracleLinux ~]# cat /var/log/mongo/mongod.log
日誌內容較長,此處截取了相關的內容如下:
************** Unclean shutdown detected.Please visit http://dochub.mongodb.org/core/repair for recovery instructions.*************Thu Jan 23 12:34:11.293 [initandlisten] exception in initAndListen: 12596 old lock file, terminatingThu Jan 23 12:34:11.293 dbexit: Thu Jan 23 12:34:11.293 [initandlisten] shutdown: going to close listening sockets...Thu Jan 23 12:34:11.293 [initandlisten] shutdown: going to flush diaglog...Thu Jan 23 12:34:11.293 [initandlisten] shutdown: going to close sockets...Thu Jan 23 12:34:11.293 [initandlisten] shutdown: waiting for fs preallocator...Thu Jan 23 12:34:11.293 [initandlisten] shutdown: closing all files...Thu Jan 23 12:34:11.293 [initandlisten] closeAllFiles() finishedThu Jan 23 12:34:11.293 dbexit: really exiting now
此處是非法關閉mongodb,根據日子檔案具體內容中提供的地址(第3行處)擷取到修複方式。
a、首先刪除/var/lib/mongo/目錄下的mongod.lock檔案,具體命令如下:
[root@oracleLinux ~]# rm /var/lib/mongo/mongod.lock
b、已repair方式啟動mongodb,具體命令如下:
[root@oracleLinux mongo]# mongod -f /etc/mongod.conf --repairFri Jan 24 10:38:39.112 Fri Jan 24 10:38:39.113 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.Fri Jan 24 10:38:39.114 about to fork child process, waiting until server is ready for connections.forked process: 2237all output going to: /var/log/mongo/mongod.logchild process started successfully, parent exiting
c、在啟動一次mongodb,具體命令如下:
[root@oracleLinux mongo]# mongod -f /etc/mongod.confFri Jan 24 10:41:13.664 Fri Jan 24 10:41:13.665 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.Fri Jan 24 10:41:13.666 about to fork child process, waiting until server is ready for connections.forked process: 2253all output going to: /var/log/mongo/mongod.logchild process started successfully, parent exiting
d、查看進程,如果存在mongodb進程,即代表修複成功,具體命令如下:
[root@oracleLinux mongo]# ps -ef | grep mongoroot 2253 1 2 10:41 ? 00:00:02 mongod -f /etc/mongod.confroot 2268 2079 0 10:43 pts/0 00:00:00 grep mongo
3、開始使用mongodb,具體命令如下:
[root@oracleLinux mongo]# mongoMongoDB shell version: 2.4.9connecting to: testServer has startup warnings: Fri Jan 24 10:41:13.708 [initandlisten] Fri Jan 24 10:41:13.708 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.Fri Jan 24 10:41:13.708 [initandlisten] ** 32 bit builds are limited to less than 2GB of data (or less with --journal).Fri Jan 24 10:41:13.708 [initandlisten] ** Note that journaling defaults to off for 32 bit and is currently off.Fri Jan 24 10:41:13.708 [initandlisten] ** See http://dochub.mongodb.org/core/32bitFri Jan 24 10:41:13.708 [initandlisten] >