MongoDB Replica Set configuration steps

Source: Internet
Author: User

MongoDB Replica Set configuration steps

2012-11-09 14:10:24| Category: mongodb| Report | font size Subscription

Replication of the upgraded version of master-slave replication, which implements the automatic failover function, and from the node support read

One, node type:

A) Master node: supports read and write

b) from node: Support read (required setting)

c) Quorum node: Participation in voting also supports read (required setting)

Second, the experiment

Master node: 192.168.129.47

From node: 192.168.129.48

Quorum node: 192.168.129.49

1. The master node is configured as follows:

Vi/etc/rc.local

Rm/usr/mongodb/log/mongodb.log

/usr/mongodb/bin/mongod--dbpath=/usr/mongodb/data/--logpath=/usr/mongodb/log/mongodb.log--port 27017--replSet test/192.168.129.48:27017--maxconns=2000--fork–logappend

From the node configuration is as follows:

Vi/etc/rc.local

Rm/usr/mongodb/log/mongodb.log

/usr/mongodb/bin/mongod--dbpath=/usr/mongodb/data/--logpath=/usr/mongodb/log/mongodb.log--port 27017--replSet test/192.168.129.47:27017--maxconns=2000--fork–logappend

The quorum node is configured as follows:

Vi/etc/rc.local

Rm/usr/mongodb/log/mongodb.log

/usr/mongodb/bin/mongod--dbpath=/usr/mongodb/data/--logpath=/usr/mongodb/log/mongodb.log--port 27017--replSet test/192.168.129.47:27017,192.168.129.48:27017--fork–logappend

Start Mongod Service after configuration is complete

2. Execute on Master node after start (192.168.129.47)

Use admin

Db.runcommand ({"Replsetinitiate": {

"_id": "Test",

"Members": [

{

"_id": 0,

"Host": "192.168.129.47:27017"

},

{

"_id": 1,

"Host": "192.168.129.48:27017"

} ,

{

"_id": 2,

"Host": "192.168.129.49:27017"

}

]}})

#查看复制集状态
Rs.status ()
Rs.ismaster ()
Rs.conf ()

#查看从库状态
Db.printslavereplicationinfo ()

#设置从库可查询
Db.getmongo (). Setslaveok ()
Rs.setslaveok ()

#增加复制集节点
1. Lock the existing one from the library and write the data in the cache to disk
Use admin
Db.runcommand ({"Fsync": 1, "Lock": 1})
2. Copy is locked from the library's data file to the new data directory from the library
3. Unlock from Library
Db. $cmd. Sys.unlock.findOne ()
Db.currentop ()
4. Start the new library
./mongod--replset rs1--keyfile/data/set/key/r4--fork--port 28014--dbpath/data/set/r4--logpath=/data/set/log/ R4.log--logappend--fastsync
5.rs.add ("localhost:27017")

6. Delete the node:

Execute Rs.remove ("Ip:port") above the master node

MongoDB Replica Set configuration steps

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.