1. Start a new shard Server process
[Email protected] ~]# mkdir/data/shard/~]#/apps/mongo/bin/mongod--shardsvr--port 20002--dbpath/data/ shard/S2--fork--logpath/data/shard/log/s2.log--/data/shard/log/6772
2. Configuring the new Shard Server
[[email protected] ~]#/apps/mongo/bin/mongo admin--port 40000MongoDB Shell version:1.8.1Connecting to:127.0.0.1:40000/Admin> Db.runcommand ({addshard: "localhost:20002" }){ "shardadded": "shard0002", "OK": 1 }>printshardingstatus ()---sharding Status---sharding version: {"_id": 1, "Version": 3}shards:{"_id": "shard0000", "host": "localhost:20000" }{ "_id": "shard0001", "host": "Localhost:20001" }{ "_id": "shard0002", "host": "Localhost:20002"}--New Shard serverdatabases:{"_id": "admin", "partitioned":false, "PRIMARY": "config" }{ "_id": "Test", "partitioned":true, "PRIMARY": "shard0000"}test.users chunks:shard00022shard000021stshard000121sttoo many chunksn to print, use verboseifYou want to force printtest.users_2 chunks:shard000146shard00021shard000045too many chunksn to print, use verboseifYou want to force print
View Code
3. View the Shard table status to verify the new Shard Server
>Use testswitched to DB test>db.users_2.stats () {"Sharded":true,"NS": "Test.users_2",......"shard0002": {--the new Shard Server already has data"NS": "Test.users_2","Count": 21848,"Size": 2097408,"Avgobjsize": 96,"Storagesize": 2793472,"Numextents": 5,"Nindexes": 1,"Lastextentsize": 2097152,"Paddingfactor": 1,"Flags": 1,"Totalindexsize": 1277952,"Indexsizes" : {"_id_": 1277952},"OK": 1}},"OK": 1}>
View Code
We can see that when we add Shard Server, the data is automatically distributed to the new Shard, which is self-implemented by MongoDB internally.
MongoDB Finishing notes New Shard Server