Windows下MongoDB安裝副本集

  • 安裝環境簡介
    Windows十、MongoDB4.0.三、Robo 3T(mongo命令行操做比較方便)
  • 建立數據庫文件夾、配置文件等數據庫

    (1)數據庫文件夾:db2701七、db3701七、db47017
      (2)log文件夾:log2701七、log3701七、log47017
      (3)配置文件:mongod2701七、mongod3701七、mongod47017
      配置文件更改端口號便可,具體內容以下:
      λ cat mongod27017.conf
       systemLog:
           destination: file
           logAppend: true
           path: E:\mongo\log27017\mongod27017.log
       
       storage:
           dbPath: E:\mongo\db27017
           journal:
               enabled: true
           engine: wiredTiger
       
       #processManagement:
       #    fork: true
       #    pidFilePath: E:\mongo\mongod27017.pid
       
       net:
           port: 27017
       
       replication:
           replSetName: mongo
  • 啓動primary學習

    λ mongod --config "..\mongod27017.conf"
      2018-11-08T21:23:38.399+0800 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
       #查看狀態
       > rs.status()
       {
               "operationTime" : Timestamp(0, 0),
               "ok" : 0,
               "errmsg" : "no replset config has been received",
               "code" : 94,
               "codeName" : "NotYetInitialized",
               "$clusterTime" : {
                       "clusterTime" : Timestamp(0, 0),
                       "signature" : {
                               "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                               "keyId" : NumberLong(0)
                       }
               }
       }
      #副本集配置並啓動
      > config = {_id:"mongo",members:[{_id:0,host:"127.0.0.1:27017"}]}
           {
                   "_id" : "mongo",
                   "members" : [
                           {
                                   "_id" : 0,
                                   "host" : "127.0.0.1:27017"
                           }
                   ]
           }
       > rs.initiate(config)
       {
               "ok" : 1,
               "operationTime" : Timestamp(1541685032, 1),
               "$clusterTime" : {
                       "clusterTime" : Timestamp(1541685032, 1),
                       "signature" : {
                               "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                               "keyId" : NumberLong(0)
                       }
               }
       }
  • 添加其餘成員spa

    λ mongod --config "..\mongod37017.conf"
    2018-11-08T21:52:18.237+0800 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
    
       mongo:PRIMARY> rs.add("127.0.0.1:37017")
       {
               "ok" : 1,
               "operationTime" : Timestamp(1541685236, 1),
               "$clusterTime" : {
                       "clusterTime" : Timestamp(1541685236, 1),
                       "signature" : {
                               "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                               "keyId" : NumberLong(0)
                       }
               }
       }
     
     λ mongod --config "..\mongod47017.conf"
     2018-11-08T22:01:26.664+0800 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
       #此次指定arbiterOnly參數,覺得建立一個仲裁接點
       mongo:PRIMARY> rs.add("127.0.0.1:47017",{arbiterOnly:true})
       {
               "ok" : 1,
               "operationTime" : Timestamp(1541685748, 1),
               "$clusterTime" : {
                       "clusterTime" : Timestamp(1541685748, 1),
                       "signature" : {
                               "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                               "keyId" : NumberLong(0)
                       }
               }
       }
       #查看副本集的狀態信息
       mongo:PRIMARY> db.isMaster()
       {
               "hosts" : [
                       "127.0.0.1:27017",
                       "127.0.0.1:37017"
               ],
               "arbiters" : [
                       "127.0.0.1:47017"
               ],
               "setName" : "mongo",
               "setVersion" : 3,
               "ismaster" : true,
               "secondary" : false,
               "primary" : "127.0.0.1:27017",
               "me" : "127.0.0.1:27017",
               "electionId" : ObjectId("7fffffff0000000000000001"),
               "lastWrite" : {
                       "opTime" : {
                               "ts" : Timestamp(1541685884, 1),
                               "t" : NumberLong(1)
                       },
                       "lastWriteDate" : ISODate("2018-11-08T14:04:44Z"),
                       "majorityOpTime" : {
                               "ts" : Timestamp(1541685884, 1),
                               "t" : NumberLong(1)
                       },
                       "majorityWriteDate" : ISODate("2018-11-08T14:04:44Z")
               },
               "maxBsonObjectSize" : 16777216,
               "maxMessageSizeBytes" : 48000000,
               "maxWriteBatchSize" : 100000,
               "localTime" : ISODate("2018-11-08T14:04:52.091Z"),
               "logicalSessionTimeoutMinutes" : 30,
               "minWireVersion" : 0,
               "maxWireVersion" : 7,
               "readOnly" : false,
               "ok" : 1,
               "operationTime" : Timestamp(1541685884, 1),
               "$clusterTime" : {
                       "clusterTime" : Timestamp(1541685884, 1),
                       "signature" : {
                               "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                               "keyId" : NumberLong(0)
                       }
               }
       }

    以上副本集建立完成,接下來看下數據同步命令行

    mongo:PRIMARY> show dbs
       admin   0.000GB
       config  0.000GB
       local   0.000GB
       mongo:PRIMARY> use mongo
       switched to db mongo
       mongo:PRIMARY> db.createCollection("test")
       {
               "ok" : 1,
               "operationTime" : Timestamp(1541686077, 1),
               "$clusterTime" : {
                       "clusterTime" : Timestamp(1541686077, 1),
                       "signature" : {
                               "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                               "keyId" : NumberLong(0)
                       }
               }
       }
       mongo:PRIMARY> show collections
       test

    clipboard.png

    以上就是搭建的全過程,後續學習再補充這塊內容~code

相關文章
相關標籤/搜索