MongoDB Sharding Cluster is a horizontally scalable mode. It is very powerful when the data volume is large. I have been trying to study three roles to build a MongoDB Sharding Cluster:
1. Shard Server: mongod instance, used to store actual data blocks. In the actual production environment, a role of Shard Server can be assumed by one Replica Set of several machines to prevent single point of failure (spof) on the host.
2. Config Server: mongod instance, which stores the entire Cluster Metadata, including Chunk information.
3. Route Server: mongos instance, front-end routing, access from the client, and make the entire cluster look like a single database, front-end applications can be used transparently.
The Sharding architecture is as follows:
650) this. width = 650; "border = 0>
Because it is an experimental environment, I only use a Linux server. The basic information is as follows:
1. Three Sharding parts
2. Each shard consists of three nodes, one master node and two slave Replica Set.
3. Three configuration nodes: Configsvr
4. 1 routing node Mongos
Shard replica set A (three shard nodes constitute A replica set): 127.0.0.1: 10000 127.0.0.1: 10001 127.0.0.1: 10002
Shard replica Set B (three shard nodes constitute a replica set): 127.0.0.1: 20000 127.0.0.1: 20001 127.0.0.1: 20002
Sharding replica set C (three sharding nodes constitute a replica set): 127.0.0.1: 30000 127.0.0.1: 30001 127.0.0.1: 30002
Configsvr (three configuration server nodes): 127.0.0.1: 40000 127.0.0.1: 40001 127.0.0.1: 40002
Mongos (a route node): 127.0.0.1: 50000
The procedure is as follows:
1. Download and install MongoDB and create a MongoDB user
- tar zxvf mongodb-linux-i686-2.0.4.tgz -C /usr/local/
- mv /usr/local/mongodb-linux-i686-2.0.4/ /usr/local/mongodb/
- ln -s /usr/local/mongodb/bin/* /usr/bin/
-
- groupadd -g 20001 mongodb
- useradd -u 20001 -g mongodb mongodb
-
- su - mongodb
2. Create related directories
- mkdir -p /home/mongodb/data/shard1/r0
- mkdir -p /home/mongodb/data/shard1/r1
- mkdir -p /home/mongodb/data/shard1/r2
- mkdir -p /home/mongodb/data/shard1/config
-
- mkdir -p /home/mongodb/data/shard2/r0
- mkdir -p /home/mongodb/data/shard2/r1
- mkdir -p /home/mongodb/data/shard2/r2
- mkdir -p /home/mongodb/data/shard2/config
-
- mkdir -p /home/mongodb/data/shard3/r0
- mkdir -p /home/mongodb/data/shard3/r1
- mkdir -p /home/mongodb/data/shard3/r2
- mkdir -p /home/mongodb/data/shard3/config