MongoDB在windows 64下的安装方法

  • MongoDB下载 , 注意64位的MongoDB不能运行在32位的系统上。
  • 创建数据存储目录,默认的数据目录路径是\data\db
例如在D:\Documents\下创建\data\db
cd D:\Documents
md \data\db
如果使用的是类Linux命令行工具,可以使用mkdir \data\db
  • 将MongoDB与数据目录关联,使用–dbpath
进入到mongodb安装目录下的bin目录,在该目录中有个mongod.exe,执行命令
mongod.exe --dbpath D:\Documents\data\db

此时,mongodb服务被开启,将会显示一下信息

2017-03-07T13:03:29.343+0800 I CONTROL [initandlisten] MongoDB starting : pid=14992 port=27017 dbpath=D:\Documents\data\db 64-bit host=DESKTOP-GD5OHOR
2017-03-07T13:03:29.343+0800 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2017-03-07T13:03:29.345+0800 I CONTROL [initandlisten] db version v3.4.2
2017-03-07T13:03:29.345+0800 I CONTROL [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2017-03-07T13:03:29.346+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips 22 Sep 2016
2017-03-07T13:03:29.346+0800 I CONTROL [initandlisten] allocator: tcmalloc
2017-03-07T13:03:29.346+0800 I CONTROL [initandlisten] modules: none
2017-03-07T13:03:29.347+0800 I CONTROL [initandlisten] build environment:
2017-03-07T13:03:29.347+0800 I CONTROL [initandlisten] distmod: 2008plus-ssl
2017-03-07T13:03:29.347+0800 I CONTROL [initandlisten] distarch: x86_64
2017-03-07T13:03:29.347+0800 I CONTROL [initandlisten] target_arch: x86_64
2017-03-07T13:03:29.347+0800 I CONTROL [initandlisten] options: { storage: { dbPath: “D:\Documents\data\db” } }
2017-03-07T13:03:29.363+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3532M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-03-07T13:03:30.430+0800 I CONTROL [initandlisten]
2017-03-07T13:03:30.433+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-03-07T13:03:30.435+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-03-07T13:03:30.436+0800 I CONTROL [initandlisten]
2017-03-07T13:03:31.413+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory ‘D:/Documents/data/db/diagnostic.data’
2017-03-07T13:03:31.681+0800 I INDEX [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: “incompatible_with_version_32”, ns: “admin.system.version” }
2017-03-07T13:03:31.682+0800 I INDEX [initandlisten] building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2017-03-07T13:03:31.704+0800 I INDEX [initandlisten] build index done. scanned 0 total records. 0 secs
2017-03-07T13:03:31.706+0800 I COMMAND [initandlisten] setting featureCompatibilityVersion to 3.4
2017-03-07T13:03:31.710+0800 I NETWORK [thread1] waiting for connections on port 27017

另起一个终端,同样进去到bin目录下,执行mongo.exe

mongo.exe

此时显示一下信息,表示安装启动成功!

MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.2
Welcome to the MongoDB shell.
For interactive help, type “help”.
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
2017-03-07T13:03:30.430+0800 I CONTROL [initandlisten]
2017-03-07T13:03:30.433+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-03-07T13:03:30.435+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-03-07T13:03:30.436+0800 I CONTROL [initandlisten]

以上exe执行时,都可以省略.exe后缀。

  • 测试一下
创建个文档test_db
use test_db
显示结果:
switched to db test_db
  • 创建日志目录
    同样在data\目录下新建一个log目录,用于存储日志文件
  • 创建个配置文件指定日志和数据存储的目录
配置文件内容:
logpath=D:\Documents\data\log\mongod.log
dbpath=D:\Documents\data (这个后面不加\db,否则会出现“服务没有响应控制功能”)

将该配置文件放在mongodb的安装目录下,假设命名为mongodb.config,然后启动做关联。

mongod.exe --config "D:\soft-dev\mongdb\mongodb.config" --install
  • 添加系统服务
将mongodb添加到系统服务中:
sc create MongoDB binPath= "\"D:\soft-dev\mongdb\bin\mongod.exe\" --service --config=\"D:\soft-dev\mongdb\mongodb.config\"" DisplayName= "MongoDB" start= "demand"
可能会出现的报错信息
[SC] OpenSCManager 失败 5:
拒绝访问。

这是由于权限问题导致的,解决方法是使用管理员权限运行。

启动MongoDB服务

使用管理员运行终端,键入
net start MongoDB
终端显示:
MongoDB 服务正在启动 .
MongoDB 服务已经启动成功。

关闭MongoDB服务

net stop MongoDB

删除MongoDB服务

sc delete MongoDB

你可能感兴趣的:(开发必备技能与工具)