符合中小企业对网站设计、功能常规化式的企业展示型网站建设
本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...
商城网站建设因基本功能的需求不同费用上面也有很大的差别...
手机微信网站开发、微信官网、微信商城网站...
刚刚接触MongoDB,遇到了个小问题,网上查到的资料好像都不是很全,总结记录下,希望对大家有帮助。
成都创新互联是一家专业提供乌恰企业网站建设,专注与网站设计、成都网站设计、HTML5建站、小程序制作等业务。10年已为乌恰众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。
一、问题描述
在重新配置mongodb的主从时,非正常关闭了数据库【kill mongod进程】,结果在重新启动时抛出错误如下
PS:正常应该是: mongod -f /mvnobss/users/mgousr01/mongodb/conf/master.conf --shutdown
mgousr01@test:/mvnobss/users/mgousr01/mongodb/bin>./start_mongodb.sh about to fork child process, waiting until server is ready for connections. forked process: 30717 ERROR: child process failed, exited with error number 100
二、问题解决
查看日志:
2017-05-11T16:01:42.370+0800 I CONTROL ***** SERVER RESTARTED ***** 2017-05-11T16:01:42.404+0800 I JOURNAL [initandlisten] journal dir=/mvnobss/users/mgousr01/mongodb/dbdata/rs0/journal 2017-05-11T16:01:42.404+0800 I JOURNAL [initandlisten] recover begin 2017-05-11T16:01:42.404+0800 I JOURNAL [initandlisten] recover lsn: 75715637 2017-05-11T16:01:42.404+0800 I JOURNAL [initandlisten] recover /mvnobss/users/mgousr01/mongodb/dbdata/rs0/journal/j._23 2017-05-11T16:01:42.408+0800 I JOURNAL [initandlisten] recover skipping application of section seq:59812763 < lsn:75715637 2017-05-11T16:01:43.187+0800 I JOURNAL [initandlisten] recover skipping application of section seq:59872073 < lsn:75715637 2017-05-11T16:01:43.517+0800 I JOURNAL [initandlisten] recover /mvnobss/users/mgousr01/mongodb/dbdata/rs0/journal/j._24 2017-05-11T16:01:44.633+0800 I JOURNAL [initandlisten] recover /mvnobss/users/mgousr01/mongodb/dbdata/rs0/journal/j._25 2017-05-11T16:01:45.762+0800 I JOURNAL [initandlisten] recover /mvnobss/users/mgousr01/mongodb/dbdata/rs0/journal/j._26 2017-05-11T16:01:45.765+0800 I JOURNAL [initandlisten] recover skipping application of section seq:60050033 < lsn:75715637 2017-05-11T16:01:45.766+0800 F JOURNAL [initandlisten] dbexception during recovery: 15923 couldn't get file length when opening mapping /mvnobss/users/mgousr01/mongodb/dbdata/rs0/lxvomgodb1/lxvomgodb1.19 boost::filesystem::file_size: No such file or directory: "/mvnobss/users/mgousr01/mongodb/dbdata/rs0/lxvomgodb1/lxvomgodb1.19" 2017-05-11T16:01:45.766+0800 I STORAGE [initandlisten] exception in initAndListen: 15923 couldn't get file length when opening mapping /mvnobss/users/mgousr01/mongodb/dbdata/rs0/lxvomgodb1/lxvomgodb1.19 boost::filesystem::file_size: No such file or directory: "/mvnobss/users/mgousr01/mongodb/dbdata/rs0/lxvomgodb1/lxvomgodb1.19", terminating 2017-05-11T16:01:45.766+0800 I CONTROL [initandlisten] now exiting 2017-05-11T16:01:45.766+0800 I NETWORK [initandlisten] shutdown: going to close listening sockets... 2017-05-11T16:01:45.767+0800 I NETWORK [initandlisten] shutdown: going to flush diaglog... 2017-05-11T16:01:45.767+0800 I NETWORK [initandlisten] shutdown: going to close sockets... 2017-05-11T16:01:45.767+0800 I STORAGE [initandlisten] shutdown: waiting for fs preallocator... 2017-05-11T16:01:45.767+0800 I STORAGE [initandlisten] shutdown: final commit... 2017-05-11T16:01:45.767+0800 I STORAGE [initandlisten] shutdown: closing all files... 2017-05-11T16:01:45.767+0800 I STORAGE [initandlisten] closeAllFiles() finished 2017-05-11T16:01:45.767+0800 I CONTROL [initandlisten] dbexit: rc: 100
日志说找不到/mvnobss/users/mgousr01/mongodb/dbdata/rs0/lxvomgodb1/lxvomgodb1.19文件,这个是正常的,因为我停库之前备份数据库后删除了数据库,常规情况是可以启动起来的。
网上百度说是需要删除非正常关闭后产生的mongod.lock文件再去重新启动,好,删除来一遍:
mgousr01@test:/mvnobss/users/mgousr01/mongodb/dbdata/rs0>ll total 20 drwxrwxr-x 3 mgousr01 mongodb 4096 2015-10-10 17:46 admin drwxrwxr-x 2 mgousr01 mongodb 4096 2017-05-11 11:12 journal drwxrwxr-x 3 mgousr01 mongodb 4096 2015-10-10 17:43 local drwxrwxr-x 3 mgousr01 mongodb 4096 2017-05-11 15:47 lxvomgodb1 -rwxrwxr-x 1 mgousr01 mongodb 0 2017-05-11 16:02 mongod.lock -rw-rw-r-- 1 mgousr01 mongodb 69 2015-10-10 17:09 storage.bson mgousr01@test:/mvnobss/users/mgousr01/mongodb/dbdata/rs0> mgousr01@test:/mvnobss/users/mgousr01/mongodb/dbdata/rs0> mgousr01@test:/mvnobss/users/mgousr01/mongodb/dbdata/rs0>rm -rf mongod.lock
重新启动依旧报错,并且又生成了mongod.lock文件:
mgousr01@test:/mvnobss/users/mgousr01/mongodb/bin>./start_mongodb.sh about to fork child process, waiting until server is ready for connections. forked process: 30717 ERROR: child process failed, exited with error number 100 mgousr01@test:/mvnobss/users/mgousr01/mongodb/dbdata/rs0>ll total 20 drwxrwxr-x 3 mgousr01 mongodb 4096 2015-10-10 17:46 admin drwxrwxr-x 2 mgousr01 mongodb 4096 2017-05-11 11:12 journal drwxrwxr-x 3 mgousr01 mongodb 4096 2015-10-10 17:43 local drwxrwxr-x 3 mgousr01 mongodb 4096 2017-05-11 15:47 lxvomgodb1 -rwxrwxr-x 1 mgousr01 mongodb 0 2017-05-11 16:15 mongod.lock
试过了很多遍还是不行,继续看日志:
2017-05-11T16:15:42.379+0800 I CONTROL ***** SERVER RESTARTED ***** 2017-05-11T16:15:42.413+0800 I STORAGE [initandlisten] ************** 2017-05-11T16:15:42.413+0800 I STORAGE [initandlisten] Error: journal files are present in journal directory, yet starting without journaling enabled. 2017-05-11T16:15:42.413+0800 I STORAGE [initandlisten] It is recommended that you start with journaling enabled so that recovery may occur. 2017-05-11T16:15:42.413+0800 I STORAGE [initandlisten] ************** 2017-05-11T16:15:42.413+0800 I STORAGE [initandlisten] exception in initAndListen: 13597 can't start without --journal enabled when journal/ files are present, terminating 2017-05-11T16:15:42.413+0800 I CONTROL [initandlisten] dbexit: rc: 100
journal文件目前存在在journal目录下,并且本次启动过程没有启动journaling,由于启动数据库时伴随启动了journaling所以才会抛出错误。
于是进到journal目录下,将非正常关闭时间点的journal文件删除:
mgousr01@test:/mvnobss/users/mgousr01/mongodb/dbdata/rs0/journal>ls -lrt total 3179664 -rw------- 1 mgousr01 mongodb 1076690944 2017-05-11 11:11 j._23 -rw------- 1 mgousr01 mongodb 1081876480 2017-05-11 11:11 j._24 -rw------- 1 mgousr01 mongodb 1093656576 2017-05-11 11:12 j._25 -rw------- 1 mgousr01 mongodb 3735552 2017-05-11 15:38 j._26 -rw------- 1 mgousr01 mongodb 88 2017-05-11 15:38 lsn mgousr01@test:/mvnobss/users/mgousr01/mongodb/dbdata/rs0/journal>rm -rf j._26
启动成功:
mgousr01@test:/mvnobss/users/mgousr01/mongodb/bin>ll total 4 -rwxrwxr-x 1 mgousr01 mongodb 60 2015-08-11 17:44 start_mongodb.sh mgousr01@test:/mvnobss/users/mgousr01/mongodb/bin>./start_mongodb.sh about to fork child process, waiting until server is ready for connections. forked process: 30927 child process started successfully, parent exiting
由于不是很懂这个文件目录的作用,网上查阅各种资料才知道,这个journal就是oracle 的redo log,MySQL的binlog,用于故障恢复的。
具体是怎样的运行机制还需要进一步研究。
我上面的环境是测试环境,不怕丢数据所以删除无所谓,生产环境应该要慎重。
【个人觉得,应该是可以在配置文件中指定disable journaling,然后去启动mongodb,启动成功后再enable重启数据库,还未尝试~】