Get the App
SLTechnology News&Howtos  ›  Database  › 

The company's practical Replica Sets+Sharding solution

Shulou Source: shulou.com Published: 2022-06-01 09:39:18 09月30日 Update

The company's practical Replica Sets+Sharding solution

The actual practice of the company's mongo cluster fragmentation

Prepare nine servers

Shard 1:

172.16.0.124purl 11731 master

172.16.0.127.11731

172.16.0.115From 11731 arbitration

Shard 2:

172.16.0.122purl 11732 master

172.16.0.125mono 11732 ready

172.16.0.103UR 11732 arbitration

Shard 3:

172.16.0.121purl 11733 master

172.16.0.123rig 11733 ready

172.16.0.114From 11733 arbitration

Slicing 1 step

-- 172.16.0.124 slice 1 master

Create a directory

Mkdir-p / home/data/shard1_1

Mkdir-p / home/Apps

Tar zxvf mongodb-linux-x86_64-2.4.7.tgz

Mv mongodb-linux-x86_64-2.4.7 / home/Apps/mongo

Start the service

/ home/Apps/mongo/bin/mongod-shardsvr-replSet shard1-port 11731-dbpath / home/data/shard1_1-logpath / home/data/shard1_1/shard1_1.log-logappend-oplogSize 5000-fork

-- 172.16.0.127 sliced and prepared

Mkdir-p / home/data/shard1_2

Mkdir-p / home/Apps

Tar zxvf mongodb-linux-x86_64-2.4.7.tgz

Mv mongodb-linux-x86_64-2.4.7 / home/Apps/mongo

Start the service

/ home/Apps/mongo/bin/mongod-shardsvr-replSet shard1-port 11731-dbpath / home/data/shard1_2-logpath / home/data/shard1_2/shard1_2.log-logappend-oplogSize 5000-fork

-- 172.16.0.115 part 1

Mkdir-p / home/data/shard1_3

Mkdir-p / home/Apps

Mkdir-p / home/data/config

Tar zxvf mongodb-linux-x86_64-2.4.7.tgz

Mv mongodb-linux-x86_64-2.4.7 / home/Apps/mongo

/ home/Apps/mongo/bin/mongod-shardsvr-replSet shard1-port 11731-dbpath / home/data/shard1_3-logpath / home/data/shard1_3/shard1_3.log-logappend-oplogSize 5000-fork

Shard 1 starts, initializes Replica Set1 arbiterOnly:true arbitration

The operation in the shard 1 master 172.16.0.124 is as follows

/ home/Apps/mongo/bin/mongo-- port 11731

Config= {_ id:'shard1',members: [{_ id:0,host:'172.16.0.124:11731'}, {_ id:1,host:'172.16.0.127:11731'}, {_ id:2,host:'172.16.0.115:11731',arbiterOnly:true}]}

Rs.initiate (config)

-

Slicing 2 steps

-- 172.16.0.122 split 2 main

Create a directory

Mkdir-p / home/data/shard2_1

Mkdir-p / home/Apps

Tar zxvf mongodb-linux-x86_64-2.4.7.tgz

Mv mongodb-linux-x86_64-2.4.7 / home/Apps/mongo

Start the service

/ home/Apps/mongo/bin/mongod-shardsvr-replSet shard2-port 11732-dbpath / home/data/shard2_1-logpath / home/data/shard2_1/shard2_1.log-oplogSize 50000-logappend-fork

-- 172.16.0.125 sliced 2 preparation

Mkdir-p / home/data/shard2_2

Mkdir-p / home/Apps

Tar zxvf mongodb-linux-x86_64-2.4.7.tgz

Mv mongodb-linux-x86_64-2.4.7 / home/Apps/mongo

Start the service

/ home/Apps/mongo/bin/mongod-shardsvr-replSet shard2-port 11732-dbpath / home/data/shard2_2-logpath / home/data/shard2_2/shard2_2.log-oplogSize 50000-logappend-fork

-- 172.16.0.103 sliced 2

Mkdir-p / home/data/shard2_3

Mkdir-p / home/Apps

Mkdir-p / home/data/config

Tar zxvf mongodb-linux-x86_64-2.4.7.tgz

Mv mongodb-linux-x86_64-2.4.7 / home/Apps/mongo

/ home/Apps/mongo/bin/mongod-shardsvr-replSet shard2-port 11732-dbpath / home/data/shard2_3-logpath / home/data/shard2_3/shard2_3.log-oplogSize 50000-logappend-fork

Shard 2 starts, initializes Replica Set 2 arbiterOnly:true arbitration

The operation in the shard 2 master 172.16.0.122 is as follows

/ home/Apps/mongo/bin/mongo-- port 11732

Config= {_ id:'shard2',members: [{_ id:0,host:'172.16.0.122:11732'}, {_ id:1,host:'172.16.0.125:11732'}, {_ id:2,host:'172.16.0.103:11732',arbiterOnly:true}]}

Rs.initiate (config)

-

Slicing 3 steps

-- 172.16.0.121 3-part master

Create a directory

Mkdir-p / home/data/shard3_1

Mkdir-p / home/Apps

Tar zxvf mongodb-linux-x86_64-2.4.7.tgz

Mv mongodb-linux-x86_64-2.4.7 / home/Apps/mongo

Start the service

/ home/Apps/mongo/bin/mongod-shardsvr-replSet shard3-port 11733-dbpath / home/data/shard3_1-logpath / home/data/shard3_1/shard3_1.log-oplogSize 50000-logappend-fork

-- 172.16.0.123 3 pieces prepared

Mkdir-p / home/data/shard2_2

Mkdir-p / home/Apps

Tar zxvf mongodb-linux-x86_64-2.4.7.tgz

Mv mongodb-linux-x86_64-2.4.7 / home/Apps/mongo

Start the service

/ home/Apps/mongo/bin/mongod-shardsvr-replSet shard3-port 11733-dbpath / home/data/shard3_2-logpath / home/data/shard3_2/shard3_2.log-oplogSize 50000-logappend-fork

-- 172.16.0.114 sliced 3 times

Mkdir-p / home/data/shard3_3

Mkdir-p / home/Apps

Mkdir-p / home/data/config

Tar zxvf mongodb-linux-x86_64-2.4.7.tgz

Mv mongodb-linux-x86_64-2.4.7 / home/Apps/mongo

/ home/Apps/mongo/bin/mongod-shardsvr-replSet shard3-port 11733-dbpath / home/data/shard3_3-logpath / home/data/shard3_3/shard3_3.log-oplogSize 50000-logappend-fork

Shard 3 starts, initializes Replica Set 3 arbiterOnly:true arbitration

The operation in the shard 3 master 172.16.0.121 is as follows

/ home/Apps/mongo/bin/mongo-- port 11733

Config= {_ id:'shard3',members: [{_ id:0,host:'172.16.0.121:11733'}, {_ id:1,host:'172.16.0.123:11733'}, {_ id:2,host:'172.16.0.114:11733',arbiterOnly:true}]}

Rs.initiate (config)

Configure 3 sharded Config Server

Perform the operation on 172.16.0.115172.16.0.103172.16.0.114, as shown in the following code

/ home/Apps/mongo/bin/mongod-configsvr-dbpath / home/data/config-port 30000-logpath / home/data/config/config.log-logappend-fork

Configure 3 sharded Route Process

Perform the operation on 172.16.0.115172.16.0.103172.16.0.114, as shown in the following code

/ home/Apps/mongo/bin/mongos-- configdb 172.16.0.115 home/Apps/mongo/bin/mongos 30000172.16.0.103Ver 30000172.16.0.114Rod 30000-port 60000-- chunkSize 1-logpath / home/data/mongos.log-- logappend-- fork

Configure Shard Cluster

Perform the operation on one of the three 172.16.0.115172.16.0.103172.16.0.114, as shown in the following code

/ home/Apps/mongo/bin/mongo-- port 60000

Use admin

Db.runCommand ({addshard: "shard1/172.16.0.124:11731, 172.16.0.127) 11731, 172.16.0.115"})

Db.runCommand ({addshard: "shard2/172.16.0.122:11732, 172.16.0.125 shard2/172.16.0.122:11732 11732, 172.16.0.103 shard2/172.16.0.122:11732 11732"})

Db.runCommand ({addshard: "shard3/172.16.0.121:11733, 172.16.0.123 shard3/172.16.0.121:11733 11733, 172.16.0.114 shard3/172.16.0.121:11733 11733"})

Next, activate sharding, as shown in the following code: using hash shredding

Db.runCommand ({enablesharding: "test"})

Db.runCommand ({shardcollection: "test.users", key: {id: "hashed"}})

Emphasize that the service time must be synchronized, otherwise there will be problems.

Tags: Service arbitration code step directory three configuration company actual combat solution next nine time server activation problem cluster face-to-face preparation synchronization Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL OPPO Reno Redmi Shulou Information MariaDB