Windows环境下安装MongoDB(单节点)

简介:

2012年11月27日发布的V2.2版本不支持WinXP。为了避免2G文件大小限制,本次安装使用64位的Win7操作系统。

 
  1. 下载网址:  
  2. http://downloads.mongodb.org/win32/mongodb-win32-x86_64-2.2.2.zip  

顺便的,各操作系统下载地址汇总:http://www.mongodb.org/downloads

下载文件解压后就可以用了。本次安装解压到I:\mongodb\db,并创建I:\mongodb\data目录,使用下列指令来启动数据库,其中--dbpath指定了数据文件路径(默认路径c:\data\db也需要手工创建):

 
  1. i:\mongodb\db\bin\mongod.exe --dbpath "i:\mongodb\data" 

启动的过程中弹出防火墙提示框,允许。cmd窗口最后一行看到“waiting for connections”表示mongod.exe已正常工作。这个窗口中还可以看到操作系统是“64-bit”,看到mongodb的版本信息。

数据库启动后I:\mongodb\data下自动创建了journal目录,并创建了mogod.lock文件。journal目录下已经有了一个文件“j._0”了。在cmd窗口中能看到“journal dir=i:/mongodb/data/journal”。这个journal相当于redo,据说对系统性能影响大约5%。为了安全牺牲这5%是值得的,因此,2.0以后的MongoDB版本默认安装都是开启的。我认为这一细节可视为MongoDB奔向成熟的标志。

打开CMD窗口,输入下列指令连接数据库:

 
  1. i:\mongodb\db\bin\mongo.exe 

At the mongo.exe prompt, issue the following two commands to insert a record in the test collection of the default test database and then retrieve that record:

 
  1. > db.test.save({a:1})  
  2. > db.test.find()
    { "_id" : ObjectId("50c6b336ba95d7738d1042e3"), "a" : 1 }

下面记录ctrl+c关闭mongod.exe全过程:

 
  1. Tue Dec 11 13:37:07 Ctrl-C signal  
  2. Tue Dec 11 13:37:07 [consoleTerminate] got CTRL_C_EVENT, will terminate after cu  
  3. rrent cmd ends  
  4. Tue Dec 11 13:37:07 [consoleTerminate] now exiting  
  5. Tue Dec 11 13:37:07 dbexit:  
  6. Tue Dec 11 13:37:07 [consoleTerminate] shutdown: going to close listening socket  
  7. s...  
  8. Tue Dec 11 13:37:07 [consoleTerminate] closing listening socket: 540  
  9. Tue Dec 11 13:37:07 [consoleTerminate] closing listening socket: 548  
  10. Tue Dec 11 13:37:07 [consoleTerminate] shutdown: going to flush diaglog...  
  11. Tue Dec 11 13:37:07 [consoleTerminate] shutdown: going to close sockets...  
  12. Tue Dec 11 13:37:07 [consoleTerminate] shutdown: waiting for fs preallocator...  
  13. Tue Dec 11 13:37:07 [consoleTerminate] shutdown: lock for final commit...  
  14. Tue Dec 11 13:37:07 [consoleTerminate] shutdown: final commit...  
  15. Tue Dec 11 13:37:07 [consoleTerminate] shutdown: closing all files...  
  16. Tue Dec 11 13:37:07 [consoleTerminate] closeAllFiles() finished  
  17. Tue Dec 11 13:37:07 [consoleTerminate] journalCleanup...  
  18. Tue Dec 11 13:37:07 [consoleTerminate] removeJournalFiles  
  19. Tue Dec 11 13:37:07 [consoleTerminate] shutdown: removing fs lock...  
  20. Tue Dec 11 13:37:07 dbexit: really exiting now 

MongoDB as a Windows Service

New in version 2.0.

将MongoDB配置为Windows Service, 实现开机自启动。mongod.exe从2.0开始支持,mongos.exe 2.1.1开开始支持。

  1. 创建log文件目录Create a specific directory for MongoDB log files:

    md i:\mongodb\log
  2. 创建配置文件:

    echo logpath=i:\mongodb\log\mongo.log > i:\mongodb\db\mongod.cfg

使用配置文件指定log文件的位置是件好事。

注意事项

考虑是否设置logappend选项,如果不设置,则每次启动时会清空日志历史信息。从V2.2开始,logpath和logappend的默认设置发生了变化。

下列指令需要管理员权限(“Administrative Privileges”):

  1. 安装MongoDB服务:

    i:\mongodb\db\bin\mongod.exe --config i:\mongodb\db\mongod.cfg --install

    all output going to: i:\mongodb\log\mongo.log. Modify the path to the mongod.cfg file as needed. For the--install option to succeed, you must specify a logpath setting or the --logpath run-time option. (配置logpath是必须的)

  2. 运行MongoDB service:

    net start MongoDB
    

注意事项

If you wish to use an alternate path for your dbpath specify it in the config file (e.g. i:\mongodb\db\mongod.cfg) on that you specified in the --install operation. You may also specify --dbpathon the command line; however, always prefer the configuration file.

优先使用mongod.cfg中的配置。

If the dbpath directory does not exist, mongod.exe will not be able to start. The default value for dbpath is \data\db.

需手工创建dbpath目录。

Stop or Remove the MongoDB Service

  • To stop the MongoDB service:

    net stop MongoDB
    
  • To remove the MongoDB service:

    i:\mongodb\db\bin\mongod.exe --remove



 本文转自 hexiaini235 51CTO博客,原文链接:http://blog.51cto.com/idata/1085488 ,如需转载请自行联系原作者

相关文章
|
6月前
|
人工智能 JavaScript 开发工具
极速上手!Claude Code 原生支持 Windows 免WSL安装教程
Claude Code 现已支持 Windows 原生运行,无需 WSL 配置。本文提供详细安装教程,涵盖 Node.js 环境验证、Git 安装及 Claude Code 配置步骤,助你快速上手这一强大 AI 编程工具。
5834 7
|
6月前
|
存储 虚拟化 Windows
VMware安装Windows10
本案例介绍了在Windows系统上使用VMware Workstation 17.5 Pro安装配置Windows 10虚拟机的详细步骤,包括所需设备、软件下载链接、虚拟机设置及系统安装全过程。
3423 133
VMware安装Windows10
|
7月前
|
Ubuntu Unix Linux
在Windows上轻松安装和使用Ubuntu的方法详解
继续点击“Continue”按钮以继续安装流程,随后选择清理磁盘并安装操作系统的选项。 接下来,在安装过程中,你需要选择时区。为了与你的地理位置相匹配,请选择中国上海作为你的时区设置。 在安装过程中,你还需要设置计算机的名称以及账号密码。请务必牢记这些信息,因为它们将作为你登录系统的凭证。
|
9月前
|
NoSQL IDE MongoDB
Studio 3T 2025.11 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.11 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
507 3
|
5月前
|
安全 Ubuntu iOS开发
Nessus Professional 10.10 Auto Installer for Windows - Nessus 自动化安装程序
Nessus Professional 10.10 Auto Installer for Windows - Nessus 自动化安装程序
247 3
Nessus Professional 10.10 Auto Installer for Windows - Nessus 自动化安装程序
|
6月前
|
NoSQL IDE MongoDB
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
404 1
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
6月前
|
安全 数据安全/隐私保护 Windows
ZyperWin++使用教程!让Windows更丝滑!c盘飘红一键搞定!ZyperWin++解决系统优化、Office安装和系统激活
ZyperWin++是一款仅5MB的开源免费Windows优化工具,支持快速优化、自定义设置与垃圾清理,兼具系统加速、隐私保护、Office安装等功能,轻便无广告,小白也能轻松上手,是提升电脑性能的全能管家。
1960 0

推荐镜像

更多