zoukankan      html  css  js  c++  java
  • Windows 平台安装 MongoDB

    Windows 平台安装 MongoDB

    MongoDB 下载

    官网下载地址:https://www.mongodb.com/download-center#community

    • 注意:在 MongoDB 2.2 版本后已经不再支持 Windows XP 系统。最新版本也已经没有了 32 位系统的安装文件。
    1. 下载后双击该文件,按操作提示安装即可。 安装过程中,你可以通过点击 "Custom(自定义)" 按钮来设置你的安装目录。
    2. 创建数据目录 MongoDB将数据目录存储在 db 目录下。但是这个数据目录不会主动创建,我们在安装完成后需要创建它。请注意,数据目录应该放在根目录下((如: C: 或者 D: 等 )。 在本教程中,我们已经在C:盘 安装了 mongodb,现在让我们创建一个data的目录然后在data目录里创建db目录。
    c:>cd c:
    
    c:>mkdir data
    
    c:>cd data
    
    c:data>mkdir db
    
    c:data>cd db
    
    c:datadb>
    

    你也可以通过window的资源管理器中创建这些目录,而不一定通过命令行。

    命令行下运行 MongoDB 服务器

    1. 你可以找到MongoDB下的bin目录中得mongod.exe双击直接运行它。
    2. 或者使用命令行运行它,为了从命令提示符下运行 MongoDB 服务器,你必须从 MongoDB 目录的 bin 目录中执行 mongod.exe 文件。例:cd C:Program FilesMongoDBServer3.4in 再执行:mongod --dbpath c:datadb 若出现以下显示表示运行成功
    2017-09-26T14:41:23.836+0800 I CONTROL  [initandlisten] MongoDB starting : pid=1176 port=27017 dbpath=C:datadb 64-bit host=DESKTOP-64MC4GG
    2017-09-26T14:41:23.841+0800 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
    2017-09-26T14:41:23.841+0800 I CONTROL  [initandlisten] db version v3.4.9
    2017-09-26T14:41:23.841+0800 I CONTROL  [initandlisten] git version: 876ebee8c7dd0e2d992f36a848ff4dc50ee6603e
    2017-09-26T14:41:23.841+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips  22 Sep 2016
    2017-09-26T14:41:23.841+0800 I CONTROL  [initandlisten] allocator: tcmalloc
    2017-09-26T14:41:23.841+0800 I CONTROL  [initandlisten] modules: none
    2017-09-26T14:41:23.842+0800 I CONTROL  [initandlisten] build environment:
    2017-09-26T14:41:23.842+0800 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
    2017-09-26T14:41:23.842+0800 I CONTROL  [initandlisten]     distarch: x86_64
    2017-09-26T14:41:23.842+0800 I CONTROL  [initandlisten]     target_arch: x86_64
    2017-09-26T14:41:23.842+0800 I CONTROL  [initandlisten] options: {}
    2017-09-26T14:41:23.862+0800 I -        [initandlisten] Detected data files in C:datadb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
    2017-09-26T14:41:23.864+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1474M,session_max=20000,eviction=(threads_min=4,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-09-26T14:41:24.964+0800 I CONTROL  [initandlisten]
    2017-09-26T14:41:24.965+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
    2017-09-26T14:41:24.965+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
    2017-09-26T14:41:24.965+0800 I CONTROL  [initandlisten]
    2017-09-26T14:41:25.652+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'C:/data/db/diagnostic.data'
    2017-09-26T14:41:25.661+0800 I NETWORK  [thread1] waiting for connections on port 27017
    

    将MongoDB服务器作为Windows服务运行

    命令行进入mongoDB的bin目录执行:

    mongod.exe --bind_ip yourIPadress --logpath "C:datadbConfmongodb.log" --logappend --dbpath "C:datadb" --port yourPortNumber --serviceName "YourServiceName" --serviceDisplayName "YourServiceName" --install
    
    • --bind_ip 绑定服务IP,若绑定127.0.0.1,则只能本机访问,不指定默认本地所有IP
    • --logpath 定MongoDB日志文件,注意是指定文件不是目录(此处文件夹dbConf为我自己新建的)
    • --logappend 使用追加的方式写日志
    • --dbpath 指定数据库路径
    • --port 指定服务端口号,默认端口27017
    • --serviceName 指定服务名称
    • --serviceDisplayName 指定服务名称,有多个mongodb服务时执行。
    • --install 指定作为一个windows服务安装。

    MongoDB后台管理 Shell

    如果你需要进入MongoDB后台管理,你需要先打开mongodb装目录的下的bin目录,然后执行mongo.exe文件,MongoDB Shell是MongoDB自带的交互式Javascript shell,用来对MongoDB进行操作和管理的交互式环境。 当你进入mongoDB后台后,它默认会链接到 test 文档(数据库)即命令行进入bin目录后执行:mongo 出现如下信息表示成功:

    MongoDB shell version v3.4.9
    connecting to: mongodb://127.0.0.1:27017
    MongoDB server version: 3.4.9
    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-09-26T14:41:24.964+0800 I CONTROL  [initandlisten]
    2017-09-26T14:41:24.965+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
    2017-09-26T14:41:24.965+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
    2017-09-26T14:41:24.965+0800 I CONTROL  [initandlisten]
    
    • 由于它是一个JavaScript shell,您可以运行一些简单的算术运算:

      > 2 + 2

      4

      > 4+4

      8

    • db 命令用于查看当前操作的文档(数据库):

      > db

      test

  • 相关阅读:
    hdu 1372 Knight Moves
    hdu 1253 胜利大逃亡
    nyoj 737 石子合并 经典区间 dp
    nyoj 737 石子合并 http://blog.csdn.net/wangdan11111/article/details/45032519
    nyoj 55 懒省事的小明
    C++ STL priority_queue
    Code forces363D Renting Bikes
    性能测试分享:jmeter性能监控(一)
    性能测试培训:WebSocket协议的接口性能之Jmeter
    翻译一篇文章:It's Difficult to Grow a Test Developer(成为测试开发工程师的艰辛)
  • 原文地址:https://www.cnblogs.com/sinceForever/p/7596885.html
Copyright © 2011-2022 走看看