【安装文档】mongodb安装步骤说明(windows版)

前言

所需安装文件:
mongodb-win32-x86_64-2008plus-ssl-3.2.8-signed.msi

安装步骤

选择路径安装完毕后,在根目录下创建data、conf、logs文件夹。

执行以下命令启动mongodb:

F:\MongoDB\Server\3.2\bin>mongod.exe --dbpath F:\MongoDB\Server\3.2\data\db
2016-08-14T18:11:16.994+0800 I CONTROL  [main] Hotfix KB2731284 or later update is not installed, will zero-out data files
2016-08-14T18:11:16.996+0800 I CONTROL  [initandlisten] MongoDB starting : pid=8520 port=27017 dbpath=F:\MongoDB\Server\3.2\data\db 64-bit host=whw-PC
2016-08-14T18:11:16.996+0800 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2016-08-14T18:11:16.996+0800 I CONTROL  [initandlisten] db version v3.2.8
2016-08-14T18:11:16.997+0800 I CONTROL  [initandlisten] git version: ed70e33130c977bda0024c125b56d159573dbaf0
2016-08-14T18:11:16.998+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1p-fips 9 Jul 2015
2016-08-14T18:11:16.999+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2016-08-14T18:11:16.999+0800 I CONTROL  [initandlisten] modules: none
2016-08-14T18:11:17.000+0800 I CONTROL  [initandlisten] build environment:
2016-08-14T18:11:17.002+0800 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2016-08-14T18:11:17.002+0800 I CONTROL  [initandlisten]     distarch: x86_64
2016-08-14T18:11:17.003+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2016-08-14T18:11:17.003+0800 I CONTROL  [initandlisten] options: { storage: { db Path: "F:\MongoDB\Server\3.2\data\db" } }
2016-08-14T18:11:17.025+0800 I STORAGE  [initandlisten] wiredtiger_open config:create,cache_size=4G,session_max=20000,eviction=(threads_max=4),config_base=fals
e,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),
2016-08-14T18:11:18.196+0800 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-08-14T18:11:18.196+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'F:/MongoDB/Server/3.2/data/db/diagnostic.data'
2016-08-14T18:11:18.523+0800 I NETWORK  [initandlisten] waiting for connectionson port 27017
2016-08-14T18:11:45.313+0800 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:50991 #1 (1 connection now open)
2016-08-14T18:11:45.317+0800 I NETWORK  [conn1] end connection 127.0.0.1:50991 (0 connections now open)

mongodb默认连接端口27017,如果出现如图的情况,可以打开http://localhost:27017查看(这里使用sogou),发现如下图所示则表示连接成功,如果不成功,可以查看端口是否被占用。

mongodb-browser.pngmongodb-browser.png

使用配置文件方式启动mongodb:

在conf目录下新建mongodb.conf配置文件:

dbpath=F:\MongoDB\Server\3.2\data
logpath=F:\MongoDB\Server\3.2\logs\mongodb.log

将mongodb启动命令设置成window服务:

F:\MongoDB\Server\3.2\bin>mongod.exe --config F:\MongoDB\Server\3.2\conf\mongodb.conf --install --serviceName "MongoDB"

注意:
以管理员身份运行cmd执行上述命令;

使用mongo.exe测试

在服务中启动mongoDB服务,使用mongo.exe测试mongoDB服务是否可用;
打开cmd:

F:\MongoDB\Server\3.2\bin>mongo.exe localhost:27017
2016-08-14T18:50:27.894+0800 I CONTROL  [main] Hotfix KB2731284 or later update
is not installed, will zero-out data files
MongoDB shell version: 3.2.8
connecting to: localhost:27017/test
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
> show dbs;
local  0.000GB
> db.foo.save({a:1});
WriteResult({ "nInserted" : 1 })
> db.foo.save({a:2});
WriteResult({ "nInserted" : 1 })
> db.foo.find();
{ "_id" : ObjectId("63c53bbdc49216c64343239e"), "a" : 1 }
{ "_id" : ObjectId("63c53ff3869aa9fb90287d91"), "a" : 2 }
>

使用mongochef客户端连接测试

安装mongochef-x64.msi客户端,通过可视化工具连接mongodb。

安装完之后,创建连接,默认连接localhost:27017,点击完成即可成功连接mongodb服务,如下图示:

mongochef.pngmongochef.png

(完)

最后修改于:2023年01月16日 20:42

添加新评论