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