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

MongoDB practice (12) Replica Sets + Sharding

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

MongoDB Auto-Sharding solves the problem of mass storage and dynamic expansion, but it is higher than that required by the actual production environment.

There is still some distance between high availability and high availability, so there is a "Replica Sets + Sharding" solution.

1 、 Shard:

Use Replica Sets to ensure that each data node has backup, automatic fault-tolerant transfer, and automatic recovery.

2 、 Config:

Use 3 configuration servers to ensure metadata integrity

3 、 Route:

Using three routing processes to achieve load balancing to improve client access performance

Below we configure a Replica Sets + Sharding environment architecture diagram as follows

The open ports are as follows

Host ip service and port Server A192.168.3.231mongod shard1_1:27017

Mongod shard2_1:27018

Mongod config1:20000

Mongs1:30000Server B192.168.3.232mongod shard1_2:27017

Mongod shard2_2:27018

Mongod config2:20000

Mongs2:30000Server C192.168.3.233mongod shard1_3:27017

Mongod shard2_3:27018

Mongod config3:20000

Mongs3:30000

Create a data directory

On Server A:

On Server B:

On Server C:

Configure Replica Sets

1. Configure the Replica Sets used by shard1

On Server A:

On Server B:

On Server C:

Initialize the Replica Sets "shard1" execution with the mongod of port 27017 connected to one of the machines with mongo:

Configure the Replica Sets used by shard2

On Server A:

On Server B:

On Server C:

Use mongo to connect the mongod on port 27018 of one of the machines, initialize the Replica Sets "shard2", and execute:

Configure 3 Config Server

Execute on Server A, B, C:

Configure 3 Route Process

Execute on Server A, B, C:

Configure Shard Cluster

Activate the fragmentation of databases and collections

Verify that Sharding is working properly

Connect to the mongos process on port 30000 of one of the machines and switch to the test database to add test data

You can see that the Sharding has been successfully built, which is consistent with the result we expected, so we will combine Replica Sets and Sharding

The architecture of the combination has also been learned.

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