First, build the environment:
MongoDB version: mongodb-linux-x86_64-3.0.6.gz
Linux version: CentOS 7 x64
Server: (Port: 27000)
192.168.1.201 database server, 192.168.1.202 database server, 192.168.1.203 quorum server
(Each server firewall turns on 27000 port iptables-i input-p TCP--dport 27000-j ACCEPT)
Two, 201, and 202 Configure the database and start (Cluster Name: daxiong) Command:
Bin/mongod--port 27000--dbpath db--logpath log/mongod.log--replset Daxiong
third, the connection 201 or 202 Database
Bin/mongo 192.168.1.201:27000
Iv. Enter admin, initialize the cluster
Use Adminconfig = {_id: "Daxiong", Members:[{_id:0,host: "192.168.1.201:27000"},{_id:1,host: "192.168.1.202:27000"}]} Rs.initiate (config)
(need to be executed for a period of time)
Five, add the arbiter server after successful addition
Rs.addarb ("192.168.1.203:27000")
Vi. Viewing Status:
Rs.status ()
201 is currently the primary server: Primary
202 Standby server: Secondary
203 Arbiter Server: Arbiter
Vii. test failover
Back to 201,ko Mongod
Connection 202, view status 202 has become the primary server primary, then 201 has lost the link
Start 201 Now 201 is already an alternative server.
By default, both read and write are on the primary server, and the replica server does not support queries, if the master-slave separation is implemented, the primary server is written, and the replica server reads
Replica server to turn on Read permissions
Db.getmongo (). Setslaveok ();
MongoDB Replica Cluster setup