After the operation of MongoDB has a certain foundation, can finally pull the HA and architecture of the two tall concept. Before that, of course you have to figure out the MongoDB key feature:sharding.
1. sharding
Shard is logically a subset of the entire data, which is physically the server that manages this subset. A shard can contain more than one server. If a shard contains multiple servers, each server has an identical copy of the data subset (Replica set).
Sharding is a feature that MongoDB emphasizes. The purpose of sharding is to complete the automation cluster operation and maintenance. MongoDB cluster requires three roles, sharding Server/config Server/route.
2. HA
HA is a big topic, starting with a simple system deployment as a point to start talking about.
, the architecture of the previous MongoDB cluster requires the above three roles, three of which correspond to three processes: Mongos,shardsvr mongod and config mongod.
Figure1
Step1 : Starting Shard Server Instance 1 and instance 2
>mongod--shardsvr--port 20000--dbpath=/data/shared/s0--fork--logpath=/data/shard/log/s0.log--directory Perdb >mongod--shardsvr--port 20001--dbpath=/data/shared/s1--fork--logpath=/data/shard/log/s1.log--directory Perdb |
STEP2 : Start the config server instance
>mongod--configsvr--port 30000--dbpath=/data/shared/config--fork--logpath=/data/shard/log/config.log-- Directoryperdb |
STEP3 : Start the route server instance
>mongos--port 40000--configdb localhost:30000--fork--logpath=/data/shared/log/route.log--chunkSize 64 |
Where chunksize specifies the chunk size, in megabytes, and the default size is 200MB.
MongoDB Auto-sharding solves the problem of mass storage and dynamic expansion, but the above is far from the real HA scheme of production environment. Below further, build replica sets + sharding solution, design case.
CASE1:
- Shard: Use the replica sets to ensure that each data node has backup, automatic fault-tolerant transfer, and automatic recovery capabilities.
- Config server: Use 3 configuration servers to ensure metadata integrity and store key correspondence.
- Route Server: Using the method 3 routing processes, to achieve load balancing, improve client access performance and concurrency.
- After the cluster is built, you can join the memcached server to cache high-traffic data in memory and avoid high-frequency disk I/O to further improve performance.
Table 1 Examples of small use cases
Host |
Ip |
Service and port Assignment |
Server A |
192.168.3.231 |
Mongod shard1_1:27017 Mongod shard2_1:27018 Mongod config1:20000 mongos1:30000 |
Server B |
192.168.3.232 |
Mongod shard1_2:27017 Mongod shard2_2:27018 Mongod config2:20000 mongos2:30000 |
Server C |
192.168.3.233 |
Mongod shard1_3:27017 Mongod shard2_3:27018 Mongod config3:20000 mongos3:30000 |
Of course, the actual use of the cluster system in the environment is certainly more complex, HA is not a simple topic, but also includes disaster recovery backup and other issues, I do not have any practical experience, so can only talk about some theoretical things, I hope to share with you to learn.
According to the Convention, to be illustrated, today is the tin-silver, believe that the garden like silver soul of a few people, before seeing many friends are the head of the silver soul. In the lonely programming, writing, "Silver soul" seems to support a lot of people, poison tongue spit groove behind is a simple and ordinary life essence, warm heart. Interested to see the new ripen this article "you want to protect something is already a piece of nothingness."
All on the road, no homeward.
MongoDB Self-study diary 3--architecture and HA