window下MongoDB的配置与安装
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了window下MongoDB的配置与安装,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5481字,纯文字阅读大概需要8分钟。
内容图文
in version 2.2, MongoDB does not support Windows XP. Please use a more recent version of Windows to use more recent releases of MongoDB.2、如果运行系统为windows server 2008 R2 或者 window 7,需要进入微软官网下载补丁
IMPORTANT If you are running any edition of Windows Server 2008 R2 or Windows 7, please install a hotfix to resolve an issue with memory mapped files on Windows.
并且这里需要特别注意:
下载完成后会得到一个exe
文件,但是这里并不能直接对这个文件进行安装,需要先将其解压,解压后得到 Windows6.1-KB2731284-v3-x64.msu
文件,这时候才可以进行安装,之后重启即可
3、64位的MongoDB将不能在32位的windows上运行启动
配置
1、创建一个用于存放mongodb数据的目录,
这里我创建在D:\mongodb\data\db,打开cmd(这里我用的Git Bash),进入到mongodb的bin目录,运行下面命令
mongod --dbpath="D:\mongodb\data\db"
然后出现了我遇到的第一个问题,
2016-12-29T22:30:02.229+0800 I CONTROL [initandlisten] MongoDB starting : pid=10220 port=27017 dbpath=C:\Program Files\MongoDB\db 64-bit host=Lenovo 2016-12-29T22:30:02.234+0800 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2 2016-12-29T22:30:02.235+0800 I CONTROL [initandlisten] db version v3.4.1 2016-12-29T22:30:02.237+0800 I CONTROL [initandlisten] git version: 5e103c4f5583e2566a45d740225dc250baacfbd7 2016-12-29T22:30:02.238+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1t-fips 3 May 2016 2016-12-29T22:30:02.240+0800 I CONTROL [initandlisten] allocator: tcmalloc 2016-12-29T22:30:02.241+0800 I CONTROL [initandlisten] modules: none 2016-12-29T22:30:02.241+0800 I CONTROL [initandlisten] build environment: 2016-12-29T22:30:02.243+0800 I CONTROL [initandlisten] distmod: 2008plus-ssl 2016-12-29T22:30:02.244+0800 I CONTROL [initandlisten] distarch: x86_64 2016-12-29T22:30:02.245+0800 I CONTROL [initandlisten] target_arch: x86_64 2016-12-29T22:30:02.246+0800 I CONTROL [initandlisten] options: { storage: { dbPath: "C:\Program Files\MongoDB\db" } } 2016-12-29T22:30:02.249+0800 I STORAGE [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: C:\Program Files\MongoDB\db, terminating 2016-12-29T22:30:02.251+0800 I NETWORK [initandlisten] shutdown: going to close listening sockets... 2016-12-29T22:30:02.255+0800 I NETWORK [initandlisten] shutdown: going to flush diaglog... 2016-12-29T22:30:02.256+0800 I CONTROL [initandlisten] now exiting 2016-12-29T22:30:02.257+0800 I CONTROL [initandlisten] shutting down with code:100
最后出现shutting down with code :100,
在心知博客我找到了答案,原因在于:我们进入的命令提示符只是普通模式,所以出现无法创建文件的问题,切换到管理员模式,重新运行命令:
然后就可以正常启动。
2、我把mongo命令添加到path环境变量中,
这样我就不需要每次都进入到mongodb下的bin中执行mongo命令了。
3、把mongodb设置为windows服务,
采用管理员:命令提示符,切换到安装mongodb目录的bin
目录,运行下面命令,把MongoDB
设置为Windows
服务:
mongod --dbpath="D:\mongodb\data\db" --logpath="D:\mongodb\data\log" --logappend --directoryperdb --serviceName "MongoDB" --serviceDisplayName "MongoDB" --install
参数解读:
--dbpath="D:\mongodb\data\db" mongodb的数据目录
--logpath="D:\mongodb\data\log" --logappend 指定日志文件。并且日志是以追加的方式输出的
--serviceName "MongoDB" --serviceDisplayName "MongoDB" windows服务器名称和显示名称为MongoDB
--directoryperdb 表示每个DB都会新建一个目录
--install 进行安装,与之相对的是--remove
启动停止mongodb服务的命令
启动MongoDB:net start MongoDB
停止MongoDB:net stop MongoDB
然后我遇到了第二个问题,服务器安装成功之后,进行启动,发现无法启动,查看log日志文件,有这样的信息:
2016-12-29T23:51:23.705+0800 I CONTROL [initandlisten] options: { service: true, storage: { dbPath: "D:\mongodb\data\db", directoryPerDB: true }, systemLog: { destination: "file", logAppend: true, path: "D:\mongodb\data\log\mongodb.log" } } 2016-12-29T23:51:23.706+0800 I - [initandlisten] Detected data files in C:\Program Files\MongoDB\db created by the ‘wiredTiger‘ storage engine, so setting the active storage engine to ‘wiredTiger‘. 2016-12-29T23:51:23.707+0800 I STORAGE [initandlisten] exception in initAndListen: 72 Requested option conflicts with current storage engine option for directoryPerDB; you requested true but the current server storage is already set to false and cannot be changed, terminating 2016-12-29T23:51:23.707+0800 I NETWORK [serviceStopWorker] shutdown: going to close listening sockets... 2016-12-29T23:51:23.707+0800 I NETWORK [serviceStopWorker] shutdown: going to flush diaglog... 2016-12-29T23:51:23.707+0800 I CONTROL [serviceStopWorker] now exiting 2016-12-29T23:51:23.707+0800 I CONTROL [serviceStopWorker] shutting down with code:49
大致意思就是说存储引擎冲突,(之前在命令行启动过mongodb服务,然后就在数据目录生成了数据文件)
这个时候我们可以到数据目录中找到storage.bson这个文件,删除即可。
我们可以通过添加到环境变量中的mongo命令来启动数据库,这样我们就可以通过命令行来执行一些操作了
到这里我们已经能正常使用mongodb来执行工作了,我遇到的两个问题在心知博客中也找到了答案。
后记
我的mongodb的笔记本主要是记录mongo文档的学习情况,会不断更新。
博客会分享一些开发中的心得以及学习阶段遇到的问题最后得以解决,都会坚持下去,也很开心每天都能看到博客园里有很多人分享知识。
window下MongoDB的配置与安装
标签:日志文件 cto http lenovo tle ros red x86 art
本文系统来源:http://www.cnblogs.com/okaychen/p/7404885.html
内容总结
以上是互联网集市为您收集整理的window下MongoDB的配置与安装全部内容,希望文章能够帮你解决window下MongoDB的配置与安装所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。