Table of Content
Failed global initialization: FileNotOpen: Failed to open "f:\MongoDB\log\mongod.log" (mongodb 4.2)
mongodb:4.2
Failed global initialization: FileNotOpen: Failed to open "f:\MongoDB\log\mongod.log"
reason:
aready open a mongodb
mongodb:3.0.5
一、系统环境
os:windows 2012
mongodb:3.0.5
storageEngine:wiredTiger
二、配置文件 配置文件
mongod.cfg 内容如下:
dbpath=g:\mongodb\dataWiredTiger
storageEngine=wiredTigersync
delay=60quiet=true
journal=false
三、启动时出现的错误信息及解决办法
1、删去mongod.lock
cmd
运行启动命令 .
cd \mongodb\binmongod --config=e:\mongodb\mongod.cfg
出现错误信息: Detected unclean shutdown - g:\mongodb\dataWiredTiger\mongod.lock is not empty. exception in initAndListen: 98 Unable to create/open lock file: g:\mongodb\dataWiredTiger\mongod.lock errno:5 拒绝访问。. Is a mongod instance already running?, terminating dbexit: rc: 100
解决办法: 由于重启机器,导致非正常停止mongod服务,mongod.lock中还记录了上次运行的进程号,所以无法启动。清除lock文件。
删去 g:\mongodb\dataWiredTiger\mongod.lock
2、repair数据库
cd \mongodb\bin
mongod --repair g:\mongodb\dataWiredTiger
出现错误信息: exception in initAndListen: 28574 Cannot start server. Detected data files in g:\MongoDB\dataWiredTiger created by storage engine 'wiredTiger'. The configured storage engine is 'mmapv1'., terminating [initandlisten] dbexit: rc: 100
数据库引擎不对,运行命令
mongod --repair --dbpath g:\mongodb\dataWiredTiger --storageEngine wiredTiger
ok,修复成功
三、重新启动,正常。
正确关闭mongod 的方法:
进入mongo shell use admin db.shutdownServer()
解决重启失败问题:mongo有一个journal参数,加上这个参数后,就算mongo是非正常关闭,也会自动修复文件。
所以你可以在config文件( /etc/mongodb.conf )中将journal参数打开:
# Disables write-ahead journaling nojournal = true
或者在启动命令加上journal参数:
/usr/local/mongodb/bin/mongod --dbpath=/data/db/ --fork --logpath=/data/log/m.log --journal
64位机,默认journal参数是打开的,而32位机默认关闭。
other:
Personally, for me to get this working I had to remove the service via the command:
.\mongod.exe --remove
followed by an install however this time specifying the storage engine etc. So the command becomes .\mongod.exe --dbpath c:\mongodb\data\wt --logpath
c:\mongodb\log\mongo.log --storageEngine wiredTiger --install
Enter the shell and use the command
db.serverStatus().storageEngine
the world suddenly becomes a happier place
{ "name" : "wiredTiger" } .