MongoDB BASICS (8) replication Ⅱ-deployment of arbitration nodes, mongodb

Source: Internet
Author: User

MongoDB BASICS (8) replication Ⅱ-deployment of arbitration nodes, mongodb

Arbiter is a mongodb instance in the replica set and does not store data. The arbitration node uses the smallest resource and does not require hardware devices. It cannot deploy Arbiter in the same dataset node, and can be deployed on other application servers or monitoring servers, it can also be deployed in a separate virtual machine. To ensure that the replica set has an odd number of voting members (including primary), you must add the arbitration node as the voting node. Otherwise, the primary will not automatically switch over when it is not running.


50 Members can be set in a replica set, but there are only 7 Voting Members (including primary), and the rest are Non-Voting Members (Non-Voting Members ). Non-voting members are backup copies of the data in the replica set. They do not participate in voting, but can be voted or become the master node.


The structure is as follows:



Previous: http://blog.csdn.net/kk185800961/article/details/45700485

Three nodes are configured:

192.168.1.11: 27017 (primary)
192.168.1.12: 27018 (secondary)
192.168.1.13: 27019 (secondary)


Current node status:

rs0:SECONDARY> db.isMaster(){"setName" : "rs0","setVersion" : 12,"ismaster" : false,"secondary" : true,"hosts" : ["mongodb11.kk.net:27017","mongodb12.kk.net:27018","mongodb13.kk.net:27019"],"primary" : "mongodb13.kk.net:27019","me" : "mongodb11.kk.net:27017","maxBsonObjectSize" : 16777216,"maxMessageSizeBytes" : 48000000,"maxWriteBatchSize" : 1000,"localTime" : ISODate("2015-05-17T10:10:02.537Z"),"maxWireVersion" : 3,"minWireVersion" : 0,"ok" : 1}

In primary, remove the node "mongodb13.kk.net: 27019:

rs0:PRIMARY> rs.remove("mongodb13.kk.net:27019")rs0:PRIMARY> rs.conf()
[root@mongodb13 ~]# vi /etc/mongod.conf#replSet=rs0[root@mongodb13 ~]# service mongod restart


The remaining two nodes after deletion are as follows:

192.168.1.11: 27017 (primary)
192.168.1.12: 27018 (secondary)


Delete the service process in 192.168.1.11: 27017 (primary). primary does not switch over:

[root@redhat11 ~]# ps -ef | grep mongmongod    4592     1  0 20:00 ?        00:00:02 /usr/bin/mongod -f /etc/mongod.confroot      4648  2580  0 20:00 pts/0    00:00:00 mongo mongodb11.kk.net:27017root      4738  2618  0 20:06 pts/1    00:00:00 grep mong[root@redhat11 ~]# [root@redhat11 ~]# kill 4592

On 192.168.1.12: 27018 (secondary), the result is:

rs0:SECONDARY> rs.status(){"set" : "rs0","date" : ISODate("2015-05-17T12:02:55.595Z"),"myState" : 2,"members" : [{"_id" : 0,"name" : "mongodb11.kk.net:27017","health" : 0,"state" : 8,"stateStr" : "(not reachable/healthy)","uptime" : 0,"optime" : Timestamp(0, 0),"optimeDate" : ISODate("1970-01-01T00:00:00Z"),"lastHeartbeat" : ISODate("2015-05-17T12:02:53.655Z"),"lastHeartbeatRecv" : ISODate("2015-05-17T12:02:28.462Z"),"pingMs" : 0,"lastHeartbeatMessage" : "Failed attempt to connect to mongodb11.kk.net:27017; couldn't connect to server mongodb11.kk.net:27017 (192.168.1.11), connection attempt failed","configVersion" : -1},{"_id" : 1,"name" : "mongodb12.kk.net:27018","health" : 1,"state" : 2,"stateStr" : "SECONDARY","uptime" : 726,"optime" : Timestamp(1431860765, 1),"optimeDate" : ISODate("2015-05-17T11:06:05Z"),"infoMessage" : "could not find member to sync from","configVersion" : 13,"self" : true}],"ok" : 1}

After the 192.168.1.11: 27017 (primary) mongod service is started, it is found that automatic switching is performed:

192.168.1.11: 27017 (secondary)
192.168.1.12: 27018 (primary)


To facilitate the test, change primary back to the original:

192.168.1.11: 27017 (primary)
192.168.1.12: 27018 (secondary)


Now, an arbitration node 192.168.1.13: 27019 will be added.


Create a data file directory:

[Root @ mongodb13 ~] # Mkdir/var/lib/mongo/arbiter
[Root @ mongodb13 ~] # Chown mongod: mongod/var/lib/mongo/arbiter


Configuration parameter file:

[Root @ mongodb13 ~] # Vi/etc/mongod. conf

pidfilepath=/var/run/mongodb/mongod.pidlogpath=/var/log/mongodb/mongod.logbind_ip=192.168.1.13dbpath=/var/lib/mongo/arbiterport=27019logappend=falsefork=truereplSet=rs0


Restart the service:
[Root @ mongodb13 ~] # Service producer D restart


Add the arbitration node in 192.168.1.11: 27017 (primary) and view the result:

rs0:PRIMARY> rs.addArb("mongodb13.kk.net:27019")rs0:PRIMARY> rs0:PRIMARY> db.isMaster(){"setName" : "rs0","setVersion" : 16,"ismaster" : true,"secondary" : false,"hosts" : ["mongodb11.kk.net:27017","mongodb12.kk.net:27018"],"arbiters" : ["mongodb13.kk.net:27019"],"primary" : "mongodb11.kk.net:27017","me" : "mongodb11.kk.net:27017","electionId" : ObjectId("555884dc41ecb76a9ab03676"),"maxBsonObjectSize" : 16777216,"maxMessageSizeBytes" : 48000000,"maxWriteBatchSize" : 1000,"localTime" : ISODate("2015-05-17T12:31:34.720Z"),"maxWireVersion" : 3,"minWireVersion" : 0,"ok" : 1}rs0:PRIMARY> 

So far, the addition is complete !~


Test again to delete the service process in 192.168.1.11: 27017 (primary:

[root@redhat11 ~]# ps -ef | grep mongmongod    4771     1  0 20:08 ?        00:00:09 /usr/bin/mongod -f /etc/mongod.confroot      4827  2580  0 20:08 pts/0    00:00:00 mongo mongodb11.kk.net:27017root      5255  2618  0 20:33 pts/1    00:00:00 grep mong[root@redhat11 ~]# kill 4771


Go to 192.168.1.12: 27018 (secondary), and switch primary to 192.168.1.12.

rs0:SECONDARY> db.isMaster(){"setName" : "rs0","setVersion" : 16,"ismaster" : true,"secondary" : false,"hosts" : ["mongodb11.kk.net:27017","mongodb12.kk.net:27018"],"arbiters" : ["mongodb13.kk.net:27019"],"primary" : "mongodb12.kk.net:27018","me" : "mongodb12.kk.net:27018","electionId" : ObjectId("555889751e2e989b81963adc"),"maxBsonObjectSize" : 16777216,"maxMessageSizeBytes" : 48000000,"maxWriteBatchSize" : 1000,"localTime" : ISODate("2015-05-17T12:32:08.745Z"),"maxWireVersion" : 3,"minWireVersion" : 0,"ok" : 1}rs0:PRIMARY> 

Primary can start and switch normally !~


Now let's take a look at arbiter and connect it to 192.168.1.13: 27019.

[Root @ mongodb13 ~] # Mongo 192.168.1.13: 27019

rs0:ARBITER> rs0:ARBITER> rs.slaveOk();rs0:ARBITER> db.isMaster()

Arbiter is the most arbitration. It does not have data copies stored locally and can read the information of the replica set.




Refer:

Replication Introduction

Replica Set Elections

Replica Sets with Four or More Members

Add an Arbiter to Replica Set



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.