1. Replica set
Each replica set needs to set the replica set name. Specified when the Mongod is started.
2. Build Step 2.1 Start
First start Mongod set to replica set mode when startup, and set the name. Two ways, either through configuration files, or command-line mode. Configuration file:
# Mongodb.confreplset = Replsetname
Command-line mode:
Mongod--replset "Replsetname"
2.2 MONGO Shell
Open MONGO Shell
$./bin/mongo
2.3 Initialization
Use Rs.initiate (): Initialize the replica set in the MONGO shell.
> Rs.initiate ():
2.4 Verification
Verify that initialization is successful.
> rs.conf ();
Returns the following results.
{ "_id": "Replsetname", "version": 1, "members": [ { "_id": 1, "host": " mongodb0.example.net:27017 " } ]}
2.5 Adding an instance
adding instances using Rs.add
> Rs.add ("mongodb1.example.net")
3. View replica set status
Use the following command to view
Returns the following information.
{ "set": "Replisetname", "date": Isodate ("2014-08-23t07:43:51z"), "MyState": 2, "members": [ { "_id": 0, "name": "mongodb0.example.net:2701", "health": 1, "state": 2, "STATESTR": "Secondary ", " uptime ": 3816405, " Optime ": Timestamp (1408335342, 1), " Optimedate ": Isodate (" 2014-08-18t04 : 15:42z "), " Lastheartbeat ": Isodate (" 2014-08-23t07:43:51z "), " Lastheartbeatrecv ": Isodate (" 2014-08-23t07:43:50z "), " Pingms ": 1, },
4. Delete a node
Delete using remove
Rs.remove ("mongod3.example.net:27017")
Address: http://blog.csdn.net/yonggang7/article/details/38778729
MongoDB replica set build and increase or decrease machine