---------------------------------the slice schema diagram-------------------------------------------------------------------------------
Slice 1 slice 2 slice 3
| | |
------------------
|
| | -----Configuration Server (Master)
User----------> Routing-----------|-----configuration server (from 1)
|-----configuration server (from 2)
Note: After the MONGO 3.4 version, the configuration server must be a replica set, so you can see that the tutorial configuration server is an old version.
--------------------------------------------------------------------------------------------------------------- --------------------
Steps:
1. Configure the replica set of the configuration server first
1) master./mongod--configsvr--dbpath/home/jack/mongodata01/data--logpath/home/jack/mongodata01/log/log--port 3000-- Replset MySet
2) from 1./mongod--configsvr--dbpath/home/jack/mongodata02/data--logpath/home/jack/mongodata02/log/log--port 3100-- Replset MySet
3) from 2./mongod--configsvr--dbpath/home/jack/mongodata03/data--logpath/home/jack/mongodata03/log/log--port 3300-- Replset MySet
* * Description:--configsvr must be added, indicating that the server is a configuration server
4) Master and slave all start, log in with the shell, then set the replica set
(1), configuration information
rsconf={
"_id": "MySet",
"Members": [
{
"_id": 0,
"Host": "172.16.60.180:3000"
}
]
}
(2), initialization
Rs.initiate (rsconf)
(3), add cluster
Rs.add ("172.16.60.180:3100")
Rs.add ("172.16.60.180:3200")
2. Configure the routing server and start
./mongos--configdb myset/172.16.60.180:3000,172.16.60.180:3100,172.16.60.180:3200--logpath/home/jack/ Mongodata04/log/log--port 3300
Description: The myset behind configdb must match the name of the replica set on the configuration server.
3. Configure the tile server
1) Cd/home/jack/mongodb-linux-x86_64-3.4.5/bin
./mongod--dbpath/home/jack/mongodata06/data--logpath/home/jack/mongodata01/log/log--port 3400--shardsvr
2) Cd/home/jack/mongodb-linux-x86_64-3.4.5/bin
./mongod--dbpath/home/jack/mongodata06/data--logpath/home/jack/mongodata01/log/log--port 3500--shardsvr
* * Description:--shardsvr must be added, indicating that the server is a tile server
3. Connecting routes and adding slices
1) sh.addshard (' 172.16.60.180:3400 ')
2) Sh.addshard (' 172.16.60.180:3500 ')
3) Sh.addshard (' 172.16.60.180:3600 ')
4. Add the library to be fragmented
Sh.enablesharding (DatabaseName)
5. Add a table to be fragmented
Sh.shardcollection (' Dbname.collectionname ', {field:1})
--------------------------------------------------------------------------------------------------------------
* * Description: 1) If a shard is required, the data already exists, you need to first create an index on a field in the collection
2) Once the Sharding key and the Shard value are determined, they cannot be changed.
Other commands:
1) View additional cluster status information
Sh.status ()
2) Custom Shards (example)
for (Var i=0;i<40;i++) {
Sh.splitat (' Dbname.collectionname ', {field:i*1000})
}
3) Modify Chunck size (unit: M)
(1), use Config
(2), Db.settings.save ({_id: "Chuncksize", value:64})
--------------------------------------------------------------------------------------------------------------- -
MongoDB Slice Configuration method