1024programmer Mongodb Introduction to MongoDB database cluster fragmentation technology

Introduction to MongoDB database cluster fragmentation technology

1. Fragmentation

Fragmentation is to split and save the data in the database on different machines;

Sharding includes manual sharding and automatic sharding;

MongoDB supports automatic sharding;

Two, mongos

MongoDB needs the routing process mongos, mongos knows where all the data is stored, and the application connects to mongos to send requests. mongos hides the fragmentation details from the application and forwards the request to the corresponding database machine;

3. Chip key

1. The slice key is used as the basis for data splitting, and MongoDB splits the data according to the slice key;

According to the addition and deletion of the number of machines, MongoDB will rebalance the data to make its traffic more balanced;

2. Shard key type

Shard keys include incremental shard keys and random shard keys;

Like “timestamp” is an incremental shard key, the feature is that the data writing will be concentrated on one server, and the data query speed is very fast;

The choice of shard key will affect the operation of data query

4. Create shards

Fragmentation consists of three components, namely: slice, mongos, configuration server;

Slices: collection data containers

mongos: router process

Configuration server: store cluster configuration information

1. Start the configuration server

mkdir -p ~/dbs/config
./mongod –dbpath ~/dbs/config –port 20000

2. Start the configuration server

./mongos –port 3000 –configdb localhost:20000

3. Create shards

mkdir -p ~/dbs/db1
./mongod –dbpath ~/dbs/shard1 –port 10000

4. Add slices

connect mongos

./mongo localhost:30000/admin

Add slices through the addshard command (allowLocal allows configuration locally)

db.runCommand({addshard:”localhost:10000″,allowLocal:true})
{
“added”:”localhost:10000″,
“ok”:true
}

5. Segment the test collection of the database will

First enable the sharding function of the will database

db.runCommand({“enablesharding”:”will”})

Fragment the collection again (based on _id)

db.runCommand({“shardcollection”:”will.test”,”key”:{“_id”:1}})

5. Ensure the robustness of the cluster

1. Multiple configuration servers

Method: Repeat configuration server creation steps;

When starting mongos ./mongos –configdb
localhost:20001, localhost:20002

2. Multiple mongos processes

Method: multi-start

3. Data fault tolerance

Method: create a copy of the data

6. Manage shards

1. View slice

2. View the database list information on the chip

In the result:

_id: database name

partitioned: Whether to enable fragmentation

primary: database base camp

3. View block information

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/introduction-to-mongodb-database-cluster-fragmentation-technology/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索