zoukankan      html  css  js  c++  java
  • mongodb 单节点集群配置 (开发环境)

    最近项目会用到mongodb的oplog触发业务流程,开发时的debug很不方便。所以在本地创建一个单台mongodb 集群进行开发debug。

    大概:mongodb可以产生oplog的部署方式应该是两种,一种是replica set ,一种是shard;项目中使用的的shard,所以参照文档本地部署了单节点shard集群-只为debug。

    根据文档整理的内容包含三部分:

    1.配置文件

      配置文件有三个,分别是config.conf,shard.conf,mongos.conf;一下是内容

     1 #config.conf
     2 sharding:
     3   clusterRole: configsvr
     4 replication:
     5   replSetName: config
     6 net:
     7   bindIp: 127.0.0.1
     8   port: 27017
     9 storage:
    10   dbPath: D:mongodatadb
    11 systemLog:
    12   destination: file
    13   path: D:mongologconfig.log
    14   logAppend: true
    15 processManagement:
    16   pidFilePath: D:mongologconfig.pid
    #shard.conf
    sharding:
       clusterRole: shardsvr
    replication:
       replSetName: shard1
    net:
       bindIp: 127.0.0.1
       port: 20001
    storage:
      dbPath: D:mongosharddb
    systemLog:
      destination: file
      logAppend: false
      path: D:mongologshard1.log
    processManagement:
      pidFilePath: D:mongologshard1.pid
    #mongos.conf
    net:
      bindIp: 127.0.0.1
      port: 30000
    systemLog:
      destination: file
      logAppend: false
      path: D:mongologmongos.log
    processManagement:
      pidFilePath: D:mongologmongos.pid
    
    sharding:
      configDB: config/127.0.0.1:27017

    2.启动文件,启动文件是一个.bat文件,只是config,shard和mongos服务的启动。注意配置文件的位置

    start mongod --config C:Usersdocker-mongoconfconfig.conf
    start mongod --config C:Usersdocker-mongoconfshard.conf
    start mongos --config C:Usersdocker-mongoconfmongos.conf

    3.初始化语句,初始化语句需要分别在控制台中运行。

    //config
    mongo --host 127.0.0.1 --port 27017
    rs.initiate(
      {
        _id: "config",
        configsvr: true,
        members: [
          { _id : 0, host : "127.0.0.1:27017" }
        ]
      }
    )
    
    //shard 
    mongo --host 127.0.0.1 --port 20001
    rs.initiate(
      {
        _id : "shard1",
        members: [
          { _id : 0, host : "127.0.0.1:20001" }
        ]
      }
    )
    
    //mongos
    mongo --host 127.0.0.1 --port 30000
    sh.addShard( "shard1/127.0.0.1:20001")

    到这里就完成了。连接mongos后可以使用了。

  • 相关阅读:
    python模块win32com中的early-bind与lazy-bind(以Autocad为例)
    Beautiful code and beautiful life
    PyPI 使用的国内源
    JavaScript在SublimeText中的配置
    Python中的模块包
    FTP 服务器在WIN10上的搭建及服务端下载文件实例
    Oracle ASM磁盘组兼容性
    oracle ADVM
    053-28
    053-27
  • 原文地址:https://www.cnblogs.com/peng18/p/11508624.html
Copyright © 2011-2022 走看看