---
title: "mongodb的安装以及加入服务启动项（windows）"
author: "jadethao"
date: "2013-12-12T13:32:07Z"
tags: ["MongoDB"]
categories: ["数据库"]
slug: "mongodb-windows"
draft: false
lastmod: "2013-12-12T13:38:04Z"
id: 1988515
url: "https://jadethao.iteye.com/blog/1988515"
---

1、下载mongodb的windows版本，注意下载你操作系统版本匹配的。
   下载地址：<http://www.mongodb.org/downloads>

```java
2、解压并且重命名为mongodb，copy到D:/websoft/下，注：这个是我的命名及其目录结构,可以根据你自己的习惯执行
3、在mongodb文件件下，新建两个文件data和logs
4、配置mongodb服务器：
4.1 cmd进入到：D:/websoft/mongodb/bin下（操作：1.d:  2.cd :/websoft/mongodb/bin）;
4.2 命令：mongod --dbpath d:/websoft/mongodb/data
   打印如下后：
```

	
```xml
	。。。。。。。
        Thu Dec 12 11:27:14.295 [fileallocator] done allocating datafile d:/websoft/mong
		odb/data\local.0, size: 64MB,  took 0.261 secs
		Thu Dec 12 11:27:14.299 [initandlisten] command local.$cmd command: { create: "s
		tartup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0  reslen:37
		386ms
		Thu Dec 12 11:27:14.346 [initandlisten] waiting for connections on port 27017
		Thu Dec 12 11:27:14.347 [websvr] admin web console waiting for connections on port 28017
```

4.3 打开浏览器：http://localhost:27017/
      显示结果为：
		
```xml
You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number
```

	  到此，monggodb启动成功。
5、把mongodb加入到windows服务启动项中：
5.1cmd 进入到：D:/websoft/mongodb/bin下（操作：1.d:  2.cd D:/websoft/mongodb/bin）;
5.2 命令：
```java
mongod.exe --logpath d:/websoft/mongodb/logs --logappend --dbpath d:/websoft/mongodb/data --directoryperdb --serviceName MongoDB -install
```

5.3 打开window服务,可以看到MongoDB服务。
以后可以在cmd中直接这样启动：
   net start MongoDB和net stop MongoDB来启动和停止MongoDB，或者可以在本地服务中操作![](http://dl2.iteye.com/upload/attachment/0092/0787/edcbd5cf-f222-3189-ab25-618c15219f8a.png)