MongoDB Foundation (eight) Replication ⅱ-deployment Quorum node

Source: Internet
Author: User
Tags mongodb

An arbiter (arbiter) is a MongoDB instance in a replication set that does not hold data. The quorum node uses minimal resources and does not require hardware devices, cannot deploy arbiter in the same dataset node, can be deployed on other application servers or monitoring servers, or can be deployed in a separate virtual machine. To ensure that there are an odd number of voting members (including primary) in the replication set, the quorum node needs to be added as a vote, otherwise primary will not automatically switch primary when it is not running.


A replication set can have 50 members, but only 7 voting members (including primary) and the rest are non-voting members (non-voting). A non-voting member is a backup copy of the data in the replication set and does not participate in the poll, but can be voted on or become the master node.


The structure is as follows:



In the previous article: http://blog.csdn.net/kk185800961/article/details/45700485

3 nodes are configured:

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


current node Condition:

Rs0:secondary> Db.ismaster ()
{
	"setName": "Rs0",
	"setversion": "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": +,
	" LocalTime ": Isodate (" 2015-05-17t10:10:02.537z "),
	" Maxwireversion ": 3,
	" Minwireversion ": 0,
	" OK ": 1< c19/>}

now remove the node "mongodb13.kk.net:27019" in primary:

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 2 nodes after deletion are as follows:

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


The service process was removed in 192.168.1.11:27017 (primary), and primary did not switch:

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

in 192.168.1.12:27018 (secondary), view the results as:

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 Reachab Le/healthy) "," uptime ": 0," Optime ": Timestamp (0, 0)," optimedate ": Isodate (" 1970-01-01t00:00:00z ")," lasth  Eartbeat ": 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-sync from "," ConfigversioN ": +," Self ": true}]," OK ": 1}
 

After starting the 192.168.1.11:27017 (primary) Mongod service, the discovery is automatically switched:

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


easy to test, change the primary back to the original:

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


A quorum node will now be added: 192.168.1.13:27019


To 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.pid
logpath=/var/log/mongodb/mongod.log
bind_ip=192.168.1.13
Dbpath=/var/lib/mongo/arbiter
port=27019
logappend=false
fork=true
replset=rs0


then restart the service:
[Root@mongodb13 ~]# Service Mongod restart


Add the Quorum node in 192.168.1.11:27017 (primary) and view the results:

Rs0:primary> Rs.addarb ("mongodb13.kk.net:27019")
rs0:primary> 
rs0:primary> db.isMaster ()
{
	"SetName": "Rs0",
	"setversion": +,
	"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": +,
	"localtime": Isodate ("2015-05-17t12:31:34.720z"),
	"Maxwireversion": 3,
	"Minwireversion": 0,
	"OK": 1
}

At this point, add complete. ~


test again to remove the service process in 192.168.1.11:27017 (primary):

[Root@redhat11 ~]# Ps-ef | grep mong
mongod    4771     1  0 20:08?        00:00:09/usr/bin/mongod-f/etc/mongod.conf
root      4827  2580  0 20:08 pts/0 00:00:00    MONGO mongodb11.kk.net:27017
root      5255  2618  0 20:33 pts/1    00:00:00 grep mong
[ Root@redhat11 ~]# Kill 4771


to 192.168.1.12:27018 (secondary) view, primary switch to 192.168.1.12

Rs0:secondary> Db.ismaster ()
{
	"setName": "Rs0",
	"setversion": +,
	"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": +,
	"localtime": Isodate (" 2015-05-17t12:32:08.745z "),
	" Maxwireversion ": 3,
	" Minwireversion ": 0,
	" OK ": 1
}

The primary can start switching normally. ~


Now look at arbiter, connected 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 the most arbitrators, no copies of the data are stored locally and can read the information of the replica set.




Reference:

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.