First, the environment
centos6.5
node1:172.30.31.114
node2:172.30.31.115
node3:172.30.31.108
NODE4:172.30.31.109 arbitration Point
Second, installation
Four nodes are required to perform a
1. Install the Package
#yum install-y MongoDB Mongodb-server
#echo "This is key file" >/home/keyfile
#chown Mongodb/home/keyfile
#chmod 600/home/keyfile
#vim/etc/mongodb.conf
Port = 27017
Fork = True
Pidfilepath =/var/run/mongodb/mongodb.pid
LogPath =/var/log/mongodb/mongodb.log
DBPath =/var/lib/mongodb
Journal = True
Logappend = True
Replset = Mongotest
KeyFile =/home/keyfile
Auth = True
Oplogsize = 10000
#/etc/init.d/mongod start
#chkconfig Mongod on
Iii. Creating a replication set
Execute on 1node1
#mongo Admin
>db.runcommand ({"replsetinitiate": {"_id": "Mongotest", "members": [
{"_id": 1, "host": 172.30.31.114 "},
{"_id": 2, "host": 172.30.31.115 "},
{"_id": 3, "host": 172.30.31.108 "}
]}})
>{"info": "Config now saved locally. Should come online in about a minute. "," OK ": 1}
>exit
#mongo Admin
Mongotest:primary>use Admin
Mongotest:primary>db.adduser ("root", "MongoDB")
Create a management account, at which point the NODE2,NODE3 Use this account password. Even if the management account used by NODE2,NODE3 is different, it will be overwritten for this
Iv. Adding the quorum node
1 executing on the master node
Mongotest:primary>rs.addarb ("172.30.31.109:27017")
Mongotest:primary>rs.status () #查看集群状态
Note the secondary node does not have Read permission by default, and execution Rs.slaveok () can be turned on. The quorum node only participates in voting and does not participate in synchronizing the data.
This article is from the "Bremen Band" blog, declined reprint!
Mogodb Replica Cluster