观看本文之间,请先移步至下面纠正部分
之前按照MongoDB官网提供的安装方法一直出错
http://cn.docs.mongodb.org/master/tutorial/install-mongodb-on-windows/#mongodb-as-a-windows-service
错误主要如下:
Mon Dec 24 10:57:41 Trying to start Windows service 'MongoDB'
Mon Dec 24 10:57:41 Service running
Mon Dec 24 10:57:41 [initandlisten] MongoDB starting : pid=2628 port=27017 dbpath=datadb 64-bit host=Dean
Mon Dec 24 10:57:41 [initandlisten] db version v2.2.2, pdfile version 4.5
Mon Dec 24 10:57:41 [initandlisten] git version: d1b43b61a5308c4ad0679d34b262c5af9d664267
Mon Dec 24 10:57:41 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
Mon Dec 24 10:57:41 [initandlisten] options: { config: "e:mongodbmongod.cfg", logpath: "e:mongodblogmongo.log", service: true }
Mon Dec 24 10:57:41 [initandlisten] exception in initAndListen: 10296
*********************************************************************
ERROR: dbpath (datadb) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
Mon Dec 24 10:57:41 dbexit:
Mon Dec 24 10:57:41 [initandlisten] shutdown: going to close listening sockets...
Mon Dec 24 10:57:41 [initandlisten] shutdown: going to flush diaglog...
Mon Dec 24 10:57:41 [initandlisten] shutdown: going to close sockets...
Mon Dec 24 10:57:41 [initandlisten] shutdown: waiting for fs preallocator...
Mon Dec 24 10:57:41 [initandlisten] shutdown: lock for final commit...
Mon Dec 24 10:57:41 [initandlisten] shutdown: final commit...
Mon Dec 24 10:57:41 [initandlisten] shutdown: closing all files...
Mon Dec 24 10:57:41 [initandlisten] closeAllFiles() finished
Mon Dec 24 10:57:41 dbexit: really exiting now
提到找不到datadb,但是按照官方的教程试了好几遍,也没发现哪里有问题,还是不行
于是,就Google了一下,按照一下方式安装windows服务就可以了,特此记录,以备后用
E:mongodbin>mongod --logpath E:mongodblogMongoDB.log --logappend --dbpath
E:mongodbdata --directoryperdb --serviceName MongoDB --install
all output going to: E:mongodblogMongoDB.log
E:mongodbin>mongod --logpath E:mongodblogMongoDB.log --logappend --dbpath
E:mongodbdata --directoryperdb --serviceName MongoDB --remove
all output going to: E:mongodblogMongoDB.log
E:mongodbin>mongod --logpath E:mongodblogMongoDB.log --logappend --dbpath
E:mongodbdata --directoryperdb --serviceName MongoDB --install
all output going to: E:mongodblogMongoDB.log
E:mongodbin>net start MongoDB
The Mongo DB service was started successfully.
该命令行指定了日志文件:D:MongoDBlogsMongoDB.log,日志是以追加的方式输出的;
数据文件目录:D:MongoDBdata,并且参数--directoryperdb说明每个DB都会新建一个目录;
最后是安装参数:--install,与之相对的是--remove
启动MongoDB:net start MongoDB
停止MongoDB:net stop MongoDB
(突然停电等情况容易造成Mongo服务出错,可以先删除data目录下的log和lock文件然后重新启动服务)
纠正:
第二次安装MongoDB的时候,发现以上的错误是官方在配置mongod.cfg的时候没有指定datadb的目录
我们可以在mongod.cfg文件中配置一下参数:【注意保存文件的编码格式ANSI】
logpath=E:mongodblogMongoDB.log
logappend=true
dbpath=E:mongodbdatadb
directoryperdb=true
然后按照官方的教程
D:Program Filesmongodbin>mongod.exe --config E:mongodbmongodb.cfg --install
就可以了,如果以后想要添加或修改其他参数如auth,就可以直接在mongodb.cfg中增加修改,然后
重启MonoDB服务即可,不需要重新删除MogoDB服务,在建立,或者在注册表中修改
还有启动客户端的时候,有时候会发生
Sat Jan 12 14:22:51 Create/Open File failed C:Users???2.mongorc.js errno:3 The
system cannot find the path specified.
Sat Jan 12 14:22:51 Assertion failure fo <= 0x7ffffffe srcmongoscriptingeng
ine.cpp 136
的错误,只要到该目录下删除mongorc.js,然后重新打开mongo.exe即可