MongoDB replica setsAndAuto shardingThe simple configuration procedure is what we will introduce in this article. Many tutorials on the Internet have written replica sets and auto sharding (or sharding) together, which may be confusing for beginners, this is because a better auto sharding solution is to set each shard (shard) as a replica set ).
A replica set is composed of several mongod instances. In this set, the data of all instances is the same, so that even if one machine is down, other machines can still run normally, in addition, this part of the control is automatically completed by Mongo, so as to minimize the error caused by the machine and manual processing.
Sharding can split a large database into several parts and distribute them to each shard, reducing the pressure on a single server and increasing the efficiency by reducing the proportion of potential losses. That is to say, an auto sharding structure based on replica sets can split a complete and huge database into several server sets based on individual customization. The server clusters in each server set maintain data synchronization with each other, therefore, unless all the servers in a server set are taken down, the impact of one or more servers on the database is negligible. These two parts are described in detail in Mongo's official document. Therefore, this article aims to summarize and summarize them.
The implementation of a complete auto sharding function requires mongod and mongos. Among them, mongos serves as the real application interface, and the input and output of data must pass through it. Then you need a Config server, which is mongod, but it will not be used to store applications.ProgramIn general, the database stores the configuration attributes of the entire structure. mongos reads the configuration from the config server for work. Finally, mongod will actually store data. They are divided into several replica sets to store the sharding of mongos.
2. we recommend that you configure replica sets. A replica set contains several mongod instances. The basic command is mongod -- replset % setname % -- shardsvr, instances of the same replica set use the same % setname %. For example, a replica set named "set1" has three servers named "server1" and "server2" respectively ", "server3", run the following commands on the three servers:
Server1: mongod -- replset set1 -- shardsvr
Server2: mongod -- replset set1 -- shardsvr
Server2: mongod -- replset set1 -- shardsvr
Start mongod to include multiple parameters. You can run the command: mongod -- help to query and modify the parameters as needed.
After every server starts mongod, it starts the initialization of replica sets.
There are multiple initialization methods. The following describes two convenient methods:
(1) Initiate (CFG), where CFG is written by the user;
(2) Initiate-> Add;
3. Then start config serve;
4. Start mongs;
The above is a simple process for configuring MongoDB replica sets and auto sharding. This article will introduce it here. I hope this introduction will be helpful to you!