Linux set up MongoDB Replica Set Replica Set cluster

Replica Set Replica Set using cluster mode:
  Replica Set + even number of nodes consisting of an arbitration node, the node that owns the data set, only nodes involved in arbitration arbitration elected Primary node. Minimum architecture: a Primary node, a Secondary node, a node Arbiter.

Three servers:
  Host (Primary): 101.37.157.51:27011
  Slave (Secondary): 101.37.66.61:27011
  arbiter (Arbiter): 47.111.89.220:27011

First, create a profile:
  Primary configuration file:

     systemlog:
          destination: file
          path: / usr / supplywater / DATABASE / MongoDB / log / mongodb.log # log file storage path
          logappend: to true # Use additional way to write the log
        storage:
          dbPath: / usr / supplywater / DATABASE / MongoDB / db # inventory data file storage directory
          journal:
              Enabled: to true # each time a write operation log records (writes out the data can be reconstructed by the journal).
          wiredTiger: # storage engine has mmapv1, wiretiger, mongorocks
              engineConfig:
                cacheSizeGB: 2
        processManagement:
          fork: true
          pidFilePath: /usr/supplywater/dataBase/mongodb/log/mongodbpid.pid
        net:
          bindIp: 0.0.0.0
          port: 27011
        replication:
          replSetName: " chiticsupplywater "

Secondary profile: on the same
Arbiter profile: on the same

 

Second, start the service on all three servers mongodb

[root @ Master bin] # ./mongod -f / usr / supplywater / DATABASE / MongoDB / master.conf 
- following appears on behalf of the successful start about to fork child process, waiting until server
is ready for connections. forked process: 11656 child process started successfully, parent exiting

 

Third, configure the Replica Set

1. Log in Renyiyitai three servers, database login mongodb

[root @ Master bin] # ./mongo --port 27011 
- The following represents the emergence of a successful login MongoDB shell version v4.0.0 connecting to: mongodb://127.0.0.1:27011/ MongoDB server version: 4.0.0

2, an input command (note: chiticsupplywater profile corresponds replSetName):

> use admin
switched to db admin
--priority: the larger the value, the host arbiterOnly: true arbiter
> cfg={ _id:"chiticsupplywater",members:[{_id:0,host:'101.37.157.51:27011',priority:2},{_id:1,host:'101.37.66.61:27011',priority:1},{_id:2,host:'47.111.89.220:27011',arbiterOnly:true}] };
> Rs.initiate (cfg) 
- The following appears on behalf of success {
"ok" : 1, "operationTime" : Timestamp(1560492018, 1), "$clusterTime" : { "clusterTime" : Timestamp(1560492018, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } }
- View cluster status 
chiticsupplywater: the SECONDARY> rs.conf () { "_id" : "chiticsupplywater", "version" : 1, "protocolVersion" : NumberLong(1), "writeConcernMajorityJournalDefault" : true, "members" : [ { "_id" : 0, "host" : "101.37.157.51:27011", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 2, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 1, "host" : "101.37.66.61:27011", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 2, "host" : "47.111.89.220:27011", "arbiterOnly" : true, "buildIndexes" : true, "hidden" : false, "priority" : 0, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 } ], "settings" : { "chainingAllowed" : true, "heartbeatIntervalMillis" : 2000, "heartbeatTimeoutSecs" : 10, "electionTimeoutMillis" : 10000, "catchUpTimeoutMillis" : -1, "catchUpTakeoverDelayMillis" : 30000, "getLastErrorModes" : { }, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 }, "replicaSetId" : ObjectId("5d0337f2c259a815a2289ac6") } }

 

Close MongoDB service: use admin
first: db.shutdownServer ();
second: ./mongod --shutdown --dbpath / usr / supplywater / dataBase / mongodb / db

Guess you like

Origin www.cnblogs.com/gaomanito/p/11023562.html