One, MongoDB master, deputy, quorum node cluster installation
MongoDB's cluster approach is divided into three types of replica set/sharding/master-slaver, here only the simplest way to build a cluster (production environment), if there are multiple nodes can be and so on or view official documents.
Replica Set
Chinese translation is called a replica set. In fact, the simple is that the cluster contains a number of data, to ensure that the main node hangs, the standby node can continue to provide data services, provided the premise is that the data needs and the main node consistent. The following figure:
MongoDB (M) represents the primary node, MongoDB (S) represents the standby node, and MongoDB (A) represents the quorum node. The primary and standby node stores data (M,s), and the quorum node does not store data. The client connects the primary node to the standby node at the same time and does not connect the quorum node.
By default, the master node provides all the additions and deletions, and the standby node does not provide any services. However, you can provide a query service by setting up the standby node, which can reduce the pressure on the primary node, and when the client makes a data query, the request is automatically forwarded to the standby node. This setting is called the Read Preference Modes, and the Java client provides a simple way to configure it without having to manipulate the database directly.
The quorum node is a special node that does not store data by itself, and the main purpose is to decide which standby node is promoted to the primary node after the master node is hung, so the client does not need to connect to this node. Although there is only one standby node, a quorum node is still required to raise the node level.
After the introduction of the cluster scheme, we now start building.
1, download the three computers simultaneously, unzip the installation files
Download command: Apt-get install MONGO
2. Create MongoDB Data folder at the same time
1 mkdir-p/mongodb/data/master
2 mkdir-p/mongodb/data/slaver
3 mkdir-p/mongodb/data/arbiter
4 # Three directories corresponding to master, standby, quorum node
3. Setting up the configuration file (M,s,a)
(i) Master node configuration file
1 #master. conf
2 dbpath=/mongodb/data/master
3 logpath=/mongodb/log/master.log
4 pidfilepath=/mongodb/ Master.pid
5 directoryperdb=true
6 logappend=true
7 replset=testrs
8 bind_ip=10.10.148.130
9 port=27017
oplogsize=10000
fork=true
(ii) From the node configuration file
1 #slaver. conf
2 dbpath=/mongodb/data/slaver
3 logpath=/mongodb/log/slaver.log
4 pidfilepath=/mongodb/ Slaver.pid
5 directoryperdb=true
6 logappend=true
7 replset=testrs
8 bind_ip=10.10.148.131
9 port=27017
oplogsize=10000
fork=true
noprealloc=true
(iii) Quorum node configuration file
1 #arbiter. conf
2 dbpath=/mongodb/data/arbiter
3 logpath=/mongodb/log/arbiter.log
4 pidfilepath=/ Mongodb/arbiter.pid
5 directoryperdb=true
6 logappend=true
7 replset=testrs
8 bind_ip= 10.10.148.132
9 port=27017
oplogsize=10000
fork=true
noprealloc=true
* parameter explanation in config file:
DBPath: Data Storage Directory
LogPath: Log Storage path
Pidfilepath: Process files, easy to stop MongoDB
Directoryperdb: Set up a folder for each database according to the database name
Logappend: Logging in Append mode
Replset:replica Set's name
IP address that is bound by Bind_ip:mongodb
The port number used by the PORT:MONGODB process, which defaults to 27017
Oplogsize:mongodb the maximum size of the operation log file. MB, default to 5% of the hard disk's remaining space
Fork: Run the process in the next stage mode
Noprealloc: No pre-allocated storage
4, successively start Mongod or install MONGO service
Go to the bin directory of each MongoDB node (change the configuration file path to the following command yourself)
./monood-f master.conf
./mongod-f slaver.conf
5. Configuration master, standby, quorum node
You can connect MongoDB via client, or you can choose a connection to mongodb directly from three nodes.
./mongo 10.10.148.130:27017 #ip和port是某个节点的地址
>use admin
>cfg={_id: "Testrs", members:[{_id:0, Host: ' 10.10.148.130:27017 ', priority:2}, {_id:1,host: ' 10.10.148.131:27017 ', priority:1},
{_id:2,host: ' 10.10.148.132:27017 ', arbiteronly:true}]};
>rs.initiate (CFG)
CFG can be arbitrary name, of course, it is best not to be mongodb keyword, conf,config can. The outermost _id represents the name of the replica set, and the members contain the address and priority of all nodes. The highest priority becomes the master node, the 10.10.148.130:27017 here. It is particularly important to note that there is a special configuration--arbiteronly:true for the quorum node. This must not be less, or the main standby mode will not be effective.
6. Test configuration is successful
The configuration of the effective time according to the different machine configuration will be long and short, the configuration is good, basically in more than 10 seconds can be effective, and some configuration takes two minutes. If it takes effect, the Execute rs.status () command will see the following information:
{" Set ":" Testrs "," date ": Isodate (" 2013-01-05t02:44:43z ")," MyState " : 1, "members": [{"_id": 0, "name": "
10.10.148.130:27017 "," Health ": 1," state ": 1, "Statestr": "PRIMARY", "uptime": $, "optime": Timestamp (1357 285565000, 1), "Optimedate": Isodate ("2013-01-04t07:46:05z"), "self" : true}, {"_id": 1, "name": "1 0.10.148.131:27017