In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Environment introduction: 10.9.21.178 10.9.21.179 10.9.21.114 MongoDB sharding introduction to three roles: 1. Data fragmentation (Shards) is used to save data and ensure high availability and consistency of data. It can be a single mongod instance or a replica set. In the production environment, Shard is generally a Replica Set to prevent the single point of failure of the data chip. You can put copies of all shard in multiple mongodb instances on a single server. The collection in the database of each node of sharding can be sharded or unsharded, each db has a primary shard, and the unsharded collection exists in its own primary shard. two。 Query routing mongos (Query Routers) routing is an instance of mongos. The client connects directly to the mongos and the mongos routes the read and write requests to the specified Shard. The first time mongos starts or shuts down and restarts, the configuration information will be loaded from config server. Later, if the configuration server information changes, all mongos will be notified to update their status, so that mongos can continue to route accurately. A Sharding cluster can have a mongos, or you can configure a mongos for each App Server to reduce routing pressure. Note that the mongos does not need to be configured as rs, because it is only a route and does not store data. Configuring multiple mongos means configuring multiple individual mongos instances. In theory, you can deploy countless mongos routes, but take into account the pressure of config server! 3. The configuration server (Config servers) holds the metadata (metadata) of the cluster, including the routing rules for each Shard. Config server can be configured as a replica set after version 3.2, and config server must be configured as a replica set after 3.4. In production, it is recommended that config server's rs should have at least 3 replica set members. Overall plan: mongos is as follows (multiple mongos needs to be created in production, and then highly available with the help of haproxy or lvs): 10.9.21.114 27022 in which the replica set architecture of config server is as follows: 10.9.21.178 27018 10.9.21.179 27018 10.9.21.114 27018 sharding nodes (3 shard nodes) All are replica set architecture): shard 1 (replica) 10.9.21.178 27019 10.9.21.179 27019 10.9.21.114 27019 sharding 2 (replica) 10.9.21.178 27020 10.9.21.179 27020 10.9.21.114 27020 sharding 3 (replica) 10.9.21.178 27021 10.9.21.179 27021 10.9.21.114 27021 specific construction process: 1: directory creation: 1. For the directory of sharding nodes, note that it needs to be created in 114, 178 and 179! 1) about 27021 slices mkdir-p / data/mongodb/mongodb_sharding/mongodb/27021/db mkdir-p / data/mongodb/mongodb_sharding/mongodb/27021/config mkdir-p / data/mongodb/mongodb_sharding/mongodb/27021/log 2) about 27020 slices mkdir-p / data/mongodb/mongodb_sharding/mongodb/27020/db mkdir-p / data/mongodb/mongodb_sharding/mongodb/27020/config mkdir-p / data/mongodb/mongodb_sharding/mongodb/27020/log 3) 27019 mkdir-p / data/mongodb/mongodb_sharding/mongodb/27019/db mkdir-p / data/mongodb/mongodb_sharding/mongodb/27019/config mkdir-p / data/mongodb/mongodb_sharding/mongodb/27019/log 2. About mongos related directory creation: mkdir-p / data/mongodb/mongodb_sharding/mongos/config mkdir-p / data/mongodb/mongodb_sharding/mongos/db mkdir-p / data/mongodb/mongodb_sharding/mongos/log 3. About the creation of config server-related directories: mkdir-p / data/mongodb/mongodb_sharding/config_server/db mkdir-p / data/mongodb/mongodb_sharding/config_server/log mkdir-p / data/mongodb/mongodb_sharding/config_server/config 4. Modify the directory array chown-R mongod.mongod / data/mongodb/mongodb_sharding/ 5. Create a directory to install mongodb software: mkdir-p / usr/bin/percona_mongodb chown mongod.mongo / usr/bin/percona_mongodb II: download the mongodb installation package; I used the percona version here, I chose to use the .tar.gz package, decompression can be used! When installing multiple instances, it is recommended to use the .tar.gz package, which is clear and personal https://www.percona.com/downloads/percona-server-mongodb-4.0/LATEST/.
Db.hezi.createIndex ({"name": 1}) mongos > db.hh.createIndex ({name:'hashed'}); create hash index 4. Enable sharding for the database: mongos > sh.enableSharding ("liuwenhe"); 5. Open the fragmentation of the collection hezi! 1: ascending order,-1 descending order, hashed: hash distribution sh.shardCollection ("liuwenhe.hezi", {name:1})-value-based fragmentation sh.shardCollection ("liuwenhe.hezi", {"name": "hashed"})-hash rule fragmentation 6. Check whether the collection is enabled for sharding: mongos > db.hezi.stats (). Sharded true 7.sh.status () to view the sharding information: you can see that the main shard of the liuhe library is s1092111427021, and then the sharding key of the liuhe.hezi collection is name column ascending order. Liuhe.hezi this collection currently has one chunk, on s1092111427021 node, so at this time you go to other nodes, such as s1092111427020, there is no such library and collection. When you insert data into liuhe.hezi, it is not possible to have this collection in other fragments until the chunk migration is triggered! Mongos > sh.status () {"_ id": "liuwehehe", "primary": "s1092111427021", "partitioned": true, "version": {"uuid": UUID ("46373baa-3f93-42c3-a7fd-51225ef00636") "lastMod": 1} liuwenhe.hezi shard key: {"name": 1} unique: true balancing: true chunks: s1092111427021 1 {"name": {"$minKey": 1}}-- > {"name": {"$maxKey": 1}} on: s1092111427021 Timestamp (1,0) 8. When the data exceeds 1 chunk, it is evenly distributed over multiple nodes, as follows: insert data continuously until chunk migration is triggered: for (var I = 0; I)
< 1000000000000000; i++) { db.hezi.insert({name: i}); } 不断查看分片集群状态: mongos>Sh.status () liuwenhe.hezi shard key: {"name": 1} unique: false balancing: true chunks: s1092111427019 20 s1092111427020 19 s1092111427021 20 to this production standard.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.