Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build a sharding cluster in MongoDB

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you how to build a shard cluster in MongoDB. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Introduction to the basic components of MongoDB sharding cluster

Mongos: the entry of database cluster requests. All requests need to be coordinated by mongos, and there is no need to use programs to select routes at the application level. Mongos itself is a request distribution center, which is responsible for distributing external requests to the corresponding shard servers. As a unified request entry, mongos is generally required to HA mongos in order to prevent single node failure.

Config server: configuration server that stores the configuration of all database metadata (sharding, routing). Mongos itself does not physically store sharding server and data routing information, but caches it in memory to read data. When mongos starts for the first time or restarts later, it will load configuration information from config server. If the configuration server information is updated, it will notify all mongos to update its status, so as to ensure accurate request routing. Multiple config server is usually required in production environment. Prevent the loss of a single node in the profile.

Shard: in the traditional sense, if there is a large amount of data, the pressure of storing 1T on a single server is very great, no matter considering the hard disk of the database, network IO, and the bottleneck of CPU and memory, if more than one server allocates 1T of data, it will be estimably small data on each platform. As long as the slicing rule is set up in the mongodb cluster, the database can be operated through mongos. The corresponding operation request can be automatically forwarded to the corresponding back-end sharding server.

Replica set: in the overall mongodb cluster architecture, for the corresponding sharding node, if a single machine goes offline, the data corresponding to the whole cluster will be partially missing, which cannot happen. Therefore, replica set is required for shard nodes to ensure the reliability of the data. In production environment, it is usually 2 copies + 1 arbitration.

Building architecture of MongoDB fragmentation cluster

Architecture: what we have built this time is a three-part cluster with three copies of each part.

Port distribution: mongos:20000 config:21000 shard1:22001 shard2:22002 shard3:22003

Steps of building MongoDB sharding cluster

1. MongoDb is installed on each machine.

The installation process is omitted. Just unpack the installation package COPY to each server.

two。 Set up six directories: conf, mongos, config, shard1, shard2 and shard3 on each machine, because mongos does not store data, you only need to establish a log file directory

Mkdir-p / data/mongodb/mongos/ {log,conf} mkdir-p / data/mongodb/mongoconf/ {data,log,conf} mkdir-p / data/mongodb/shard1/ {data,log,conf} mkdir-p / data/mongodb/shard2/ {data,log,conf} mkdir-p / data/mongodb/shard3/ {data,log Conf} touch / data/mongodb/mongos/log/mongos.logtouch / data/mongodb/mongoconf/log/mongoconf.logtouch / data/mongodb/mongoconf/conf/mongoconf.conftouch / data/mongodb/shard1/log/shard1.logtouch / data/mongodb/shard2/log/shard2.logtouch / data/mongodb/shard3/log/shard3.log

3. Turn off the firewall

Systemctl stop firewalld.service

4. Config server builds a replica set and adds the following

Cat > / data/mongodb/mongoconf/conf/mongoconf.conf

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report