Single Replication sets design:
, 10.9.3.228, only Mongos and config services are started.
- Pai_^ [root @:/usr/local/mongodb/bin] # cat runServerConfig. sh
- ./Mongod -- configsvr -- dbpath = ../data/config -- logpath = ../data/config. log -- fork
- Pai_^ [root @:/usr/local/mongodb/bin] # cat runServerMongos. sh
- ./Mongos -- configdb 10.7.3.228: 27019 -- logpath = ../data/mongos. log -- logappend -- fork
Note: The ip addresses and ports in Mongos are the ip addresses and ports of the config service.
Advanced Configuration AutoSharding
163 of shardv has been started, as long as the autoSharding service of the 165 server is started
- [Root @ localhost bin] # cat runServerShard. sh
- ./Mongod -- shardsvr-dbpath = ../data/mongodb -- logpath = ../data/shardsvr_logs.txt -- fork
Configure 163 and 164 Replication
- [Root @ localhost bin] #./mongo 10.10.21.163: 27018
- MongoDB shell version: 1.8.2
- Connecting to: 10.10.21.163: 27018/test
- > Cfg = {_ id:"Set163164", Members :[
- ... {_ Id: 0, host:"10.10.21.163: 27018"},
- ... {_ Id: 1, host:"10.10.21.164: 27017"}
- ...]}
- {
- "_ Id":"Set163164",
- "Members":[
- {
- "_ Id": 0,
- "Host":"10.10.21.163: 27018"
- },
- {
- "_ Id": 1,
- "Host":"10.10.21.164: 27017"
- }
- ]
- }
- > Rs. initiate (cfg)
- {
- "Info":"Config now saved locally. shocould come online in about a minute .",
- "OK": 1
- }
- > Rs. conf ()
- {
- "_ Id":"Set163164",
- "Version": 1,
- "Members":[
- {
- "_ Id": 0,
- "Host":"10.10.21.163: 27018"
- },
- {
- "_ Id": 1,
- "Host":"10.10.21.164: 27017"
- }
- ]
- }
- Set163164: PRIMARY>
- Set163164: PRIMARY>
- Set163164: PRIMARY> show dbs
- Admin (empty)
- Local 14.1962890625 GB
- Set163164: PRIMARY> use local
- Switched to db local
- Set16.04: PRIMARY> show collections
- Oplog. rs
- System. replset
- Set163164: PRIMARY> db. system. replset. find ()
- {"_ Id":"Set163164","Version": 1,"Members":[
- {
- "_ Id": 0,
- "Host":"10.10.21.163: 27018"
- },
- {
- "_ Id": 1,
- "Host":"10.10.21.164: 27017"
- }
- ]}
- Set163164: PRIMARY> rs. isMaster ()
- {
- "SetName":"Set163164",
- "Ismaster":True,
- "Secondary":False,
- "Hosts":[
- "10.10.21.163: 27018",
- "10.10.21.164: 27017"
- ],
- "MaxBsonObjectSize"16777216,
- "OK": 1
- }
So far, Replication sets are configured successfully!
Configure the Sharding on the 228 server.
Use admin
- > Db. runCommand ({addshard:"Set163164/10.10.21.163: 27018, 10.10.21.165: 27018"});
- {"ShardAdded":"Set163164","OK": 1}
- > Db. runCommand ({enableSharding:"Test"})
- {"OK": 1}
- > Db. runCommand ({shardcollection:"Test. users", Key: {_ id: 1 }})
- {"Collectionsharded":"Test. users","OK": 1}
Then, start the rep service on the 163 and 164 servers respectively, and the 163 server should start the shard service separately.
163:
- [Root @ localhost bin] # cat runServerShard. sh
- ./Mongod -- shardsvr -- dbpath = ../data/mongodb -- logpath = ../data/shardsvr_logs.txt -- fork -- replSet set163164
164:
- [Root @ localhost bin] # cat runServerShard. sh
- ./Mongod -- dbpath = ../data -- logpath = ../data/shardsvr_logs.txt -- fork -- replSet set162134
So far, AutoSharding + Rep is successfully configured. Then perform the stability test.
First look at the result:
We can see that a total of 163 pieces of data are inserted, and 164 and 165 of the same size are part data.