DOCX

Directing a high availability cluster - copy set deployment

By Frances Chavez,2015-12-21 11:43
34 views 0
Directing a high availability cluster - copy set deployment

    A, a copy of the set (repl set)

    Early versions use the master - slave mode, a main from similar to MySQL, but slave read-only in this architecture, when the main library after downtime, switch from library doesn't automatically give priority to.Has been eliminated the master - slave mode, instead of a copy of the set, this mode has a main (primary), and multiple (secondary) read-only.Support set weight to them, when the Lord goes down, the highest weight switch to give priority to.

    In this architecture can also set up an arbitration (arbiter) role, it is only responsible for ruling, instead of storing data.And the framework, speaking, reading and writing data in the lords, advantage is that can automatically switch roles, but the disadvantage is can't achieve lets the user access from the main switch to now the Lord of the manual switch was needed to achieve the purpose of load balancing;Of course that we can write a monitoring script, let the program automatically switch to the help us to access the main IP.

    Finally should note that if you want to use copy sets, from the mongo's data must be empty, otherwise perform rs. Initiate () command will prompt initialization failed caused by the existing data (from the data already, always initiate a set).

    Second, the copy set of architecture

    1, the main process

2, the ruling mechanism

The construction of the three, a copy of the set

    1, the preparation work

    Ready for the following three machines

    The main (primary) : 192.168.0.103

    From (secondary1) : 192.168.0.109

    From (secondary2) : 192.168.0.120

    All of this three machines installed mongo, install the detailed process of reference my previous article mongo's installation:

    http://msiyuetian.blog.51cto.com/8637744/1720559

    2, edit the configuration file

    1) the configuration files of three machines to make the following modifications

    # vim /etc/mongod.conf

    Find:

    #replication:

    Is amended as:

    replication:

oplogSizeMB: 20

replSetName: tpp

    Description: oplogSizeMB refers to the size of the oplog;Copy replSetName refers to the set name.Note two format is in front of the empty, empty one after the colon.

    2) and then restart the three mongo

    # /etc/init.d/mongod restart

    If restart fails, use mongod - f/etc/mongod. Conf command to open.

    3) connect the main

    [root@primary ~]# mongo MongoDB shell version: 3.0.7

connecting to: test

    > use admin

    switched to db admin

    >

    config={_id:"tpp",members:[{_id:0,host:"192.168.0.103:27017"},{_id:1,host:"192.16

    8.0.109:27017"},{_id:2,host:"192.168.0.120:27017"}]}

{

"_id" : "tpp",

"members" : [

{

"_id" : 0,

"host" : "192.168.0.103:27017"

},

{

"_id" : 1,

"host" : "192.168.0.109:27017"

},

{

"_id" : 2,

"host" : "192.168.0.120:27017"

}

]

}

    > rs. Initiate (config) / / initialized

{ "ok" : 1 }

    The TPP: OTHER > rs. The status () / / view state

{

"set" : "tpp",

    "date" : ISODate("2015-12-12T23:19:04.253Z"),

"myState" : 1,

"members" : [

{

"_id" : 0,

    "name" : "192.168.0.103:27017",

"health" : 1,

"state" : 1,

"stateStr" : " PRIMARY ",

"uptime" : 10034,

"optime" : Timestamp(1449961495, 1),

    "optimeDate" : ISODate("2015-12-12T23:04:55Z"),

    "electionTime" : Timestamp(1449961497, 1),

    "electionDate" : ISODate("2015-12-12T23:04:57Z"),

"configVersion" : 1,

"self" : true

},

{

"_id" : 1,

"name" : "192.168.0.109:27017",

"health" : 1,

"state" : 2,

"stateStr" : " SECONDARY ",

"uptime" : 848,

"optime" : Timestamp(1449961495, 1),

    "optimeDate" : ISODate("2015-12-12T23:04:55Z"),

    "lastHeartbeat" : ISODate("2015-12-12T23:19:04.073Z"),

"lastHeartbeatRecv" : ISODate("2015-12-12T23:19:03.796Z"),

"pingMs" : 0,

"configVersion" : 1

},

{

"_id" : 2,

"name" : "192.168.0.120:27017",

"health" : 1,

"state" : 2,

"stateStr" : " SECONDARY ",

"uptime" : 848,

"optime" : Timestamp(1449961495, 1),

    "optimeDate" : ISODate("2015-12-12T23:04:55Z"),

    "lastHeartbeat" : ISODate("2015-12-12T23:19:04.073Z"),

    "lastHeartbeatRecv" : ISODate("2015-12-12T23:19:03.831Z"),

"pingMs" : 0,

"configVersion" : 1

}

],

"ok" : 1

}

    Note: two from the status of "stateStr" : "SECONDARY", if "STARTUP",

    requires the following: > var config={_id:"tpp",members:[{_id:0,host:"192.168.0.103:27017"},{_id:1,hos

t:"192.168.0.109:27017"},{_id:2,host:"192.168.0.120:27017"}]}

    > rs.initiate(config)

    View to the above information is configuration is successful, we also find that

    master prefix into the TPP: PRIMARY

tpp:PRIMARY>

    And both from the top to the TPP, SECONDARY [root@secondary1 ~]# mongo

MongoDB shell version: 3.0.7

connecting to: test

tpp:SECONDARY>

    3, a copy of the set of tests

    Test 1: synchronous data test

    1) master database construction, build collections

    tpp:PRIMARY> use mydb

    switched to db mydb

    tpp:PRIMARY> db.createCollection('test1') { "ok" : 1 }

    tpp:PRIMARY> show dbs

    local 0.078GB

mydb 0.078GB

    2) from the top view

    The TPP: SECONDARY > show DBS / / an error, because the SECONDARY node default unreadable

    2015-12-13T07:44:46.256+0800 E QUERY Error: listDatabases failed:{ "note" : "from execCommand", "ok" : 0, "errmsg" : "not master" }

at Error ()

at Mongo.getDBs (src/mongo/shell/mongo.js:47:15)

at shellHelper.show (src/mongo/shell/utils.js:630:33)

at shellHelper (src/mongo/shell/utils.js:524:36)

at (shellhelp2):1:1 at src/mongo/shell/mongo.js:47

    The TPP: SECONDARY > rs. SlaveOk () / / execution after the command can query

    tpp:SECONDARY> show dbs

    local 0.078GB

mydb 0.078GB

    Note: by the above command can only be temporary query, again through the mongo after the command into the query still complains, so you can modify the file

    / root @ secondary2 ~ # vi ~ /. Mongorc. Js / / write below this line rs.slaveOk();

    [root@secondary2 ~]# service mongod restart

    [root@secondary2 ~]# mongo

    MongoDB shell version: 3.0.7

    connecting to: test

    tpp:SECONDARY> show dbs local 0.078GB

mydb 0.078GB

    Test 2: main downtime, from become the Lord

    1) in the master to see all the weight of the machine

    tpp:PRIMARY> rs.config() {

"_id" : "tpp",

"version" : 1,

"members" : [

{

"_id" : 0,

"host" : "192.168.0.103:27017",

"arbiterOnly" : false,

"buildIndexes" : true,

"hidden" : false,

"priority" : 1,

"tags" : {

Report this document

For any questions or suggestions please email
cust-service@docsford.com