MongoDB cluster in Linux-replica set Environment Construction
MongoDB replica sets are suitable for scenarios with fewer writes and more reads. You can use message queues for write control to reduce the pressure on highly concurrent writes. The Application Scenario of replica set should be selected based on the project requirements. If there is a high concurrency write requirement, we recommend that you build a cluster using sharding mode, which is higher than the replica set in terms of stability. My application scenario here is to use queue control for write operations, mainly for queries.
After the master node fails in the replica set and is detected by the heartbeat mechanism, the master node election mechanism is initiated in the cluster to automatically elect a new master server.
After the master node fails, automatic failover is performed. The number of nodes must be greater than or equal to 3. Otherwise, a primary election error may occur. The official recommendation is an odd number of nodes. I will use three nodes here.
Install mongoDB on each node
Mkdir/data/mongo/replset
# Store mongodb data files
Mkdir-p/data/mongo/replset/data
# Go To The mongodb folder
Cd/data/mongo
Download to deployment package
Wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.12.tar
Tar xzvf mongodb-linux-x86_64-2.4.12.tar
Next, run the following command on each machine:
/Data/mongo/mongodb-linux-x86_64-2.4.12/bin/mongod -- fork -- dbpath/data/mongo/replset/data -- logpath =/data/mongo/logs/logs.info -- replSet repset
Note: It is started in the background, and the fork must be added.
Log on to mongodb on any of the three machines
// Data/mongo/mongodb-linux-x86_64-2.4.12/bin/mongo
Use admin
Define replica set configuration variables
Config = {_ id: "repset ",
Members :[
{_ Id: 0, host: "x. x. x.8: 27017 "},
{_ Id: 1, host: "x. x. x.9: 27017 "},
{_ Id: 2, host: "x. x. x.10: 27017 "}
]}
After successful configuration
Initialize replica set
Rs. initiate (config );
View cluster node status
Rs. status ();
Test whether the replica set is synchronized.
Log on to the master node
/Data/mongo/mongodb-linux-x86_64-2.4.12/bin/mongo 127.0.0.1 or local node IP
Create a Test Database
Use test;
Db. testdb. insert ({"demo": "demo "})
Go to another replica machine and check that the data has been synchronized.
You can stop the master node and check the effect of automatic master selection.
CentOS compilation and installation of MongoDB
CentOS compilation and installation of php extensions for MongoDB and mongoDB
CentOS 6 install MongoDB and server configuration using yum
Install MongoDB2.4.3 in Ubuntu 13.04
MongoDB beginners must read (both concepts and practices)
MongoDB Installation Guide for Ubunu 14.04
MongoDB authoritative Guide (The Definitive Guide) in English [PDF]
Nagios monitoring MongoDB sharded cluster service practice
Build MongoDB Service Based on CentOS 6.5 Operating System
MongoDB details: click here
MongoDB: click here
This article permanently updates the link address: