zoukankan      html  css  js  c++  java
  • windows下安装MongoDB

      首先自然得先去下载安装包,官网地址:https://www.mongodb.com/download-center#community,默认会提供最新的64位安装包,我看到的是4.0.9。下载后双击该.msi文件 -> 弹框后点Next -> 打√ -> 点Custom -> 点Browse,选择自己想安装的目录 -> 接下来会让你选择是将MongoDB作为windows的服务,默认给你的是windows内置账户(Run service as Network Service user),若勾选下面那个是本地或域用户,需要你自己指定账户和密码。这里我选择不勾选,我想自己来启动MongoDB,所以不勾选上面的Install MongoD as a Service -> 点击Next,这里左下角有个框框默认勾上了,安装图形化界面,我这里也不需要,去掉√ -> 继续Next,最后Install。

      接着准备启动。启动前我们先创建好数据目录,因为刚才我没有勾选配置服务,所以没有创建这两个目录,那就自力更生吧。在E盘创建了E:MongoDBdatadb和E:MongoDBdatalogmongo.log后,我们打开命令行,进入MongoDB的bin目录,执行启动命令mongod:

    D:>cd DevMongDBin
    
    D:DevMongDBin>mongod -dbpath "e:MongoDBdatadb"  -logpath "e:MongoDBdatalogmongo.log"
    2019-05-24T14:19:14.893+0800 I CONTROL  [main] log file "e:MongoDBdatalogmongo.log" exists; moved to "e:MongoDBdatalogmongo.log.2019-05-24T06-19-14".

      它提示说mongo.log已存在,它自己新创建了一个文件了,实际上这两个文件都会记录日志,打开日志看一样:

    2019-05-24T14:19:15.310+0800 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
    2019-05-24T14:19:15.313+0800 I CONTROL  [initandlisten] MongoDB starting : pid=31840 port=27017 dbpath=e:MongoDBdatadb 64-bit host=wulf00
    2019-05-24T14:19:15.313+0800 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
    2019-05-24T14:19:15.314+0800 I CONTROL  [initandlisten] db version v4.0.9
    2019-05-24T14:19:15.314+0800 I CONTROL  [initandlisten] git version: fc525e2d9b0e4bceff5c2201457e564362909765
    2019-05-24T14:19:15.314+0800 I CONTROL  [initandlisten] allocator: tcmalloc
    2019-05-24T14:19:15.314+0800 I CONTROL  [initandlisten] modules: none
    2019-05-24T14:19:15.314+0800 I CONTROL  [initandlisten] build environment:
    2019-05-24T14:19:15.321+0800 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
    2019-05-24T14:19:15.321+0800 I CONTROL  [initandlisten]     distarch: x86_64
    2019-05-24T14:19:15.321+0800 I CONTROL  [initandlisten]     target_arch: x86_64
    2019-05-24T14:19:15.321+0800 I CONTROL  [initandlisten] options: { storage: { dbPath: "e:MongoDBdatadb" }, systemLog: { destination: "file", path: "e:MongoDBdatalogmongo.log" } }
    2019-05-24T14:19:15.331+0800 I STORAGE  [initandlisten] Detected data files in e:MongoDBdatadb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
    2019-05-24T14:19:15.331+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3525M,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),statistics_log=(wait=0),verbose=(recovery_progress),
    2019-05-24T14:19:15.525+0800 I STORAGE  [initandlisten] WiredTiger message [1558678755:524591][31840:140708351462480], txn-recover: Main recovery loop: starting at 4/5888 to 5/256
    2019-05-24T14:19:15.671+0800 I STORAGE  [initandlisten] WiredTiger message [1558678755:671179][31840:140708351462480], txn-recover: Recovering log 4 through 5
    2019-05-24T14:19:15.770+0800 I STORAGE  [initandlisten] WiredTiger message [1558678755:770031][31840:140708351462480], txn-recover: Recovering log 5 through 5
    2019-05-24T14:19:15.841+0800 I STORAGE  [initandlisten] WiredTiger message [1558678755:840877][31840:140708351462480], txn-recover: Set global recovery timestamp: 0
    2019-05-24T14:19:15.868+0800 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
    2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] 
    2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
    2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
    2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] 
    2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
    2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server. 
    2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP 
    2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
    2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
    2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
    2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten] 
    2019-05-24T14:19:16.358+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'e:/MongoDB/data/db/diagnostic.data'
    2019-05-24T14:19:16.360+0800 I NETWORK  [initandlisten] waiting for connections on port 27017

      上面标黄处用于指定数据文件和日志文件路径,如果不指定,默认是在D盘,加入D盘没有提前创建好这两个目录,会报错:

    D:DevMongDBin>mongod
    2019-11-10T18:28:54.863-0700 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
    2019-11-10T18:28:54.886-0700 I CONTROL  [initandlisten] MongoDB starting : pid=28268 port=27017 dbpath=D:datadb 64-bit host=wulf00
    2019-11-10T18:28:54.886-0700 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
    2019-11-10T18:28:54.888-0700 I CONTROL  [initandlisten] db version v4.0.9
    2019-11-10T18:28:54.891-0700 I CONTROL  [initandlisten] git version: fc525e2d9b0e4bceff5c2201457e564362909765
    2019-11-10T18:28:54.891-0700 I CONTROL  [initandlisten] allocator: tcmalloc
    2019-11-10T18:28:54.892-0700 I CONTROL  [initandlisten] modules: none
    2019-11-10T18:28:54.893-0700 I CONTROL  [initandlisten] build environment:
    2019-11-10T18:28:54.893-0700 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
    2019-11-10T18:28:54.894-0700 I CONTROL  [initandlisten]     distarch: x86_64
    2019-11-10T18:28:54.894-0700 I CONTROL  [initandlisten]     target_arch: x86_64
    2019-11-10T18:28:54.895-0700 I CONTROL  [initandlisten] options: {}
    2019-11-10T18:28:54.912-0700 I STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory D:datadb not found., terminating
    2019-11-10T18:28:54.915-0700 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
    2019-11-10T18:28:54.916-0700 I CONTROL  [initandlisten] now exiting
    2019-11-10T18:28:54.916-0700 I CONTROL  [initandlisten] shutting down with code:100

      默认MongoDB监听的端口是27017。接下来我们通过客户端来连接一下,再新开一个命令行窗口 -> 敲命令mongo -> 回车,或者直接双击MongoDB的bin目录下的mongo.exe。我这里直接双击mongo.exe,它会自动连接上我们的mongo服务端,并打印一些信息出来,看到>这个符号就代表它在等待我们的请求了:

    MongoDB shell version v4.0.9
    connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
    Implicit session: session { "id" : UUID("cc101713-a114-40a8-815a-5e21f54cb82d") }
    MongoDB server version: 4.0.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:
    2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten]
    2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
    2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
    2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten]
    2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
    2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server.
    2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP
    2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
    2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
    2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
    2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten]
    ---
    Enable MongoDB's free cloud-based monitoring service, which will then receive and display
    metrics about your deployment (disk utilization, CPU, operation statistics, etc).
    
    The monitoring data will be available on a MongoDB website with a unique URL accessible to you
    and anyone you share the URL with. MongoDB may use this information to make product
    improvements and to suggest MongoDB products and deployment options to you.
    
    To enable free monitoring, run the following command: db.enableFreeMonitoring()
    To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
    ---
    
    > show dbs
    admin   0.000GB
    config  0.000GB
    local   0.000GB
    > use test
    switched to db test
    > show collections
    > db.wlf.save({"name":"wu linfeng"})
    WriteResult({ "nInserted" : 1 })
    > show collections
    wlf
    > db.wlf.findOne()
    { "_id" : ObjectId("5ce78e956abf4e49803d5029"), "name" : "wu linfeng" }
    >

      上面先看了下都有哪些库,然后指定了test(没有会自动创建),再看了下有哪些集合(刚创建的库自然是空的),接着用save创建了wlf这个集合并插入了一个属性name。

  • 相关阅读:
    Perl语言入门笔记 第十六章 进程管理
    Perl语言入门笔记 第十五章 智能匹配与given-when结构
    Perl语言入门笔记 第十四章 字符串与排序
    Perl语言入门笔记 第十三章 目录操作
    Perl语言入门笔记 第十二章 文件测试
    artdialog
    trimend("asdas".tocharArry())
    jQuery.isEmptyObject() 函数详解 转
    ajax返回数据成功 却进入error方法
    为什么有些网站PING不通但又能访问.
  • 原文地址:https://www.cnblogs.com/wuxun1997/p/10916809.html
Copyright © 2011-2022 走看看