Windows平台下安装MongoDB

MongoDB以其操作简单、完全免费、源码公开、随时下载等特点,被广泛应用于各种大型门户网站和专业网站,大大降低了运营成本。本文描述了在Widows平台下的安装步骤及其过程,供大家参考。

一、主要步骤

1、查看当前使用的Windows版本及架构

wmic os get caption wmic os get osarchitecture

2、下载对应的版本

http://www.mongodb.org/downloads

3、配置mongdb

创建存放数据文件的路径 md \data\db You can specify an alternate path for data files using the –dbpath option to mongod.exe, for example: C:\mongodb\bin\mongod.exe –dbpath d:\test\mongodb\data

If your path includes spaces, enclose the entire path in double quotes, for example: C:\mongodb\bin\mongod.exe –dbpath “d:\test\mongo db data”

4、启动mongodb

To start MongoDB, run mongod.exe. For example, from the Command Prompt: C:\mongodb\bin\mongod.exe This starts the main MongoDB database process. The waiting for connections message in the console output indicates that the mongod.exe process is running successfully.

5、连接到mongodb

To connect to MongoDB through the mongo.exe shell, open another Command Prompt. C:\mongodb\bin\mongo.exe

6、终止mongodb

Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running

二、Mongodb的主要组件

Component               Set Binaries
---------------         --------------------
Server                  mongod.exe
Router                  mongos.exe
Client                  mongo.exe
MonitoringTools         mongostat.exe, mongotop.exe
ImportExportTools       mongodump.exe, mongorestore.exe, mongoexport.exe,mongoimport.exe
MiscellaneousTools      bsondump.exe, mongofiles.exe, mongooplog.exe, mongoperf.exe

三、配置Mongodb作为Windows服务

Step 1: Open an Administrator command prompt ###打开一个命令行窗口
Step 2: Create directories.  ###创建数据库数据及日志目录
    mkdir c:\data\db
    mkdir c:\data\log
Step 3: Create a configuration file ###创建配置文件
    Create a configuration file. The file must set systemLog.path. Include additional configuration options as appropriate.
    For example, create a file at C:\mongodb\mongod.cfg that specifies both systemLog.path and storage.dbPath:
    systemLog:
    destination: file
    path: c:\data\log\mongod.log
    storage:
    dbPath: c:\data\db

Step 4: Install the MongoDB service.
    Install the MongoDB service by starting mongod.exe with the --install option and the -config option to
    specify the previously created configuration file.
    "C:\mongodb\bin\mongod.exe" --config "C:\mongodb\mongod.cfg" --install

Step 5: Start the MongoDB service.
    net start MongoDB

    Step 6: Stop or remove the MongoDB service as needed.
    To stop the MongoDB service use the following command:
    net stop MongoDB
    To remove the MongoDB service use the following command:
    "C:\mongodb\bin\mongod.exe" --remove

四、安装演示

1、安装

C:\Users\1636>wmic os get caption
Caption
Microsoft Windows 7 Ultimate

C:\Users\1636>wmic os get osarchitecture
OSArchitecture
64-bit

使用下载的msi文件开始安装到指定文件夹,如本例中的D:\MongoDB\Server\3.0\

2、配置环境变量

//如本例中将D:\MongoDB\Server\3.0\bin添加到系统环境变量PATH
   ;D:\MongoDB\Server\3.0\bin

D:\>mkdir d:\MongoDB\data
D:\>d:\MongoDB\Server\3.0\bin\mongod.exe --dbpath d:\MongoDB\data
2015-10-29T09:26:11.498+0800 I CONTROL  Hotfix KB2731284 or later update is not installed, will zero-out data files
2015-10-29T09:26:11.508+0800 I JOURNAL  [initandlisten] journal dir=d:\MongoDB\data\journal
2015-10-29T09:26:11.509+0800 I JOURNAL  [initandlisten] recover : no journal files present, no recovery needed
2015-10-29T09:26:11.611+0800 I JOURNAL  [durability] Durability thread started
2015-10-29T09:26:11.613+0800 I JOURNAL  [journal writer] Journal writer thread started
2015-10-29T09:26:11.718+0800 I CONTROL  [initandlisten] MongoDB starting : pid=40540 port=27017 
dbpath=d:\MongoDB\data 64-bit host=hq1636
2015-10-29T09:26:11.719+0800 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2015-10-29T09:26:11.722+0800 I CONTROL  [initandlisten] db version v3.0.6
2015-10-29T09:26:11.725+0800 I CONTROL  [initandlisten] git version: 1ef45a23a4c5e3480ac919b28afcba3c615488f2
2015-10-29T09:26:11.728+0800 I CONTROL  [initandlisten] build info: windows sys.getwindowsversion(major=6,
 minor=1, build=7601, platform=2, service_pa
ck='Service Pack 1') BOOST_LIB_VERSION=1_49
2015-10-29T09:26:11.731+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2015-10-29T09:26:11.737+0800 I CONTROL  [initandlisten] options: { storage: { dbPath: "d:\MongoDB\data" } }
2015-10-29T09:26:11.906+0800 I NETWORK  [initandlisten] waiting for connections on port 27017
 //此处已表明mongodb已启动等待连接

在打开一个单独的cmd窗口,使用mongo客户端连接到mongod
C:\Users\1636>d:\MongoDB\Server\3.0\bin\mongo.exe
2015-10-29T09:28:12.427+0800 I CONTROL  Hotfix KB2731284 or later update is not installed, will zero-out data
files
MongoDB shell version: 3.0.6
connecting to: test            //此时已连接成功
> db.version()
3.0.6
> show dbs
local  0.078GB
//如果此时需要停止mongod,则直接在原来的窗口使用ctrl+c即可

3、将Mongodb添加为Windows服务

D:\>mkdir d:\MongoDB\data
D:\>mkdir d:\MongoDB\log
D:\> -- Author : Leshami
D:\> -- Blog   : http://blog.csdn.net/leshami

D:\>echo logpath=d:\MongoDB\log\mongd.log> "d:\MongoDB\mongod.cfg"

D:\>echo dbpath=d:\MongoDB\data>> "d:\MongoDB\mongod.cfg"

D:\>type d:\MongoDB\mongod.cfg
logpath=d:\MongoDB\log\mongd.log
dbpath=d:\MongoDB\data

D:\>sc.exe create MongoDB binPath= "D:\MongoDB\Server\3.0\bin\mongod.exe --service --config=D:\MongoDB\mongod.cfg"
[SC] CreateService SUCCESS

D:\>net start MongoDB
The MongoDB service is starting.
The MongoDB service was started successfully.

D:\>net stop MongoDB
The MongoDB service is stopping.
The MongoDB service was stopped successfully.

4、修复Bug:Hotfix KB2731284

https://support.microsoft.com/zh-cn/kb/2731284 Linux下快速安装MongoDB

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Ubuntu 16.04上安装和配置Redmine

Redmine是一个用于项目管理的Web应用程序,它允许用户灵活地管理项目,同时提供强大的追踪工具和众多的插件库。这个免费的开源解决方案是付费项目管理工具的替代...

15120
来自专栏开心的学习之路

Fedora27搭建GPU版TensorFlow

主机:华硕(ASUS)G11飞行堡垒 显卡:GeForce 1070 原操作系统为win10,准备安装Fedora 27,从零开始搭建GPU版TensorF...

37370
来自专栏py+selenium

linux 安装weblogic12.1.3.0步骤

需注意:fmw_12.1.3.0.0_wls.jar     需要jdk1.7.0_15以上的版本

1.4K50
来自专栏Android干货

Android项目实战(二十五):Android studio 混淆+打包+验证是否成功

36070
来自专栏orientlu

连接器 -- Scatter File & Linker Script File

源文件编译后生成 elf 格式的目标文件(各种.o), 与运行时库经过连接器处理后,生成可以被写入嵌入式设备 ROM 中的 elf 格式文件。

18120
来自专栏张善友的专栏

实现WebSocket和WAMP协议的开源库WampSharp

22150
来自专栏依乐祝

Asp.NetCoreWebApi图片上传接口(二)集成IdentityServer4授权访问(附源码)

上一篇文章中,给大家讲解了如何通过 Asp.Net Core Web Api实现图片上传的接口,具体的可以[点这里查看][https://www.cnblogs...

15010
来自专栏草根专栏

使用Identity Server 4建立Authorization Server (1)

本文内容基本完全来自于Identity Server 4官方文档: https://identityserver4.readthedocs.io/ 官方文档很详...

533100
来自专栏云计算教程系列

如何在Ubuntu 16.04上使用Lynis执行安全审计

Lynis是一个基于主机的开源安全审计应用程序,可以评估Linux和其他类型UNIX操作系统的安全配置文件和状态。

31340
来自专栏JadePeng的技术博客

K8S集群安装

主要参考 https://github.com/opsnull/follow-me-install-kubernetes-cluster

72920

扫码关注云+社区

领取腾讯云代金券