First step. Start the appropriate Mongod process
Mongod--fork--slave --port 27017--replset myset--rest--dbpath/data/dbmongo/shard11--logpath/data/dbmongo/ Shard11.log
mongod--fork--slave--port 27018--replset myset--rest--dbpath/data/dbmongo/shard12--logpath / Data/dbmongo/shard12.log
mongod--fork--slave --port 27019--replset myset--rest--dbpath/data/dbmongo/ Shard13--logpath/data/dbmongo/shard13.log mongod--fork--slave--port 27020--replset myset--rest--dbpath / Data/dbmongo/shard14--logpath/data/dbmongo/shard14.log
Step two. Initialize replica set
>config = {_id: ' MySet ', members:[{_id:0, Host: ' 192.168.1.111:27017 '},{_id:1, Host: ' 192.168.1.112:27018 '},{_id:1, Host: ' 192.168.1.113:27019 '},{_id:2, Host: ' 192.168.1.114:27020 '}}]}
>rs.initiate (config);
>rs.status ();
Step three. Configure a config Servers:
192.168.1.100
mongod--fork--configsvr--port 20000--rest--dbpath/data/dbmongo/config--logpath/data/dbmongo/ Config/config.log
Fourth step. Configure a route Servers
Mongos-fork--port 30000--chunksize 1--configdb "192.168.1.100:20000"--logpath/data/dbmongo/mongos.log
Fifth step. Configuring the Shard Cluster connect to the MONGOs process and switch to the Admin database for the following configuration
192.168.1.100
>mongo 192.168.1.100:30000
>use admin
>db.runcommand ({addshard: ' myset/ 192.168.1.115:27021,192.168.1.116:27022 '});
>db.runcommand ({enablesharding: ' Test '});
>db.runcommand ({listshards:1});
>printshardingstatus ();
>db.runcommand ({shardcollection: ' Test.test ', key:{_id:1},unique:true});
Step sixth. Test
>for (Var i=1;i<=2011;i++) B.test.save ({id:i,value1: "1234567890", value2: "1234567890", Value3: "1234567890", Value4: "1234567890"});