重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
刚刚接触mongodb,遇到了个小问题,网上查到的资料好像都不是很全,总结记录下,希望对大家有帮助。
成都做网站、网站建设的关注点不是能为您做些什么网站,而是怎么做网站,有没有做好网站,给成都创新互联一个展示的机会来证明自己,这并不会花费您太多时间,或许会给您带来新的灵感和惊喜。面向用户友好,注重用户体验,一切以用户为中心。一、问题描述
在重新配置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: 100journal文件目前存在在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重启数据库,还未尝试~】
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。