There is only one Ubuntu machine. The configuration scheme is as follows:
1. Three sharding parts
2. Each shard consists of three nodes: 1 master and 2 slave replica sets.
3. configsever
4. One routing node mongos
Shard server: mongod instance, used to store actual data blocks. In the actual production environment, a role of shard server can be assumed by one relica set of several machines to prevent single point of failure (spof) on the host.
Config server: mongod instance, which stores the entire cluster metadata, including chunk information.
Route server: A mongos instance, with frontend routing and access from the client. It makes the entire cluster look like a single database, and front-end applications can be used transparently.
Create a data directory And a log directory
Data/A/R0
Data/A/r1
Data/A/R2
Data/B/R0
Data/B/r1
Data/B/R2
Data/C/R0
Data/C/r1
Data/C/R2
Data/configsvr/R0
Data/configsvr/r1
Data/configsvr/R2
Create a log file directory:
Data/log/
Data/log/B
Data/log/C
Data/log/configsvr
Create shard and replica set
First group
/Usr/opensource/mongodb-linux-i686-2.0.2/bin $. /mongod-logpath .. /.. /data/log/A/rc0.log -- dbpath .. /.. /data/A/RC0 -- logappend -- port 10000 -- shardsvr -- replset Seta -- rest
/Usr/opensource/mongodb-linux-i686-2.0.2/bin $. /mongod-logpath .. /.. /data/log/A/rc1.log -- dbpath .. /.. /data/A/RC1 -- logappend -- port 10001 -- shardsvr -- replset Seta -- rest
/Usr/opensource/mongodb-linux-i686-2.0.2/bin $. /mongod-logpath .. /.. /data/log/A/rc2.log -- dbpath .. /.. /data/A/RC2 -- logappend -- Port 10002 -- shardsvr -- replset Seta -- rest
Create a replica set after creating a shard
./Mongo -- port 10000
> Config = {_ ID: "Seta", members: [{_ ID: 0, host: "127.0.0.1: 10000" },{ _ ID: 1, host: "127.0.0.1: 10001 "},{ _ ID: 2, host:" 127.0.0.1: 10002 "}]}
Rs. Initiate (config)
Second part
/Usr/opensource/mongodb-linux-i686-2.0.2/bin $. /mongod-logpath .. /.. /data/log/B/rc0.log -- dbpath .. /.. /data/B/RC0 -- logappend -- port 20000 -- shardsvr -- replset SETB -- rest
/Usr/opensource/mongodb-linux-i686-2.0.2/bin $. /mongod-logpath .. /.. /data/log/B/rc1.log -- dbpath .. /.. /data/B/RC1 -- logappend -- Port 20001 -- shardsvr -- replset SETB -- rest
/Usr/opensource/mongodb-linux-i686-2.0.2/bin $. /mongod-logpath .. /.. /data/log/B/rc2.log -- dbpath .. /.. /data/B/RC2 -- logappend -- Port 20002 -- shardsvr -- replset SETB -- rest
Create a replica set
./Mongo -- port 20000
> Config = {_ ID: "SETB", members: [{_ ID: 0, host: "127.0.0.1: 20000" },{ _ ID: 1, host: "127.0.0.1: 20001 "},{ _ ID: 2, host:" 127.0.0.1: 20002 "}]}
Rs. Initiate (config)
Third Component
/Usr/opensource/mongodb-linux-i686-2.0.2/bin $. /mongod-logpath .. /.. /data/log/C/rc0.log -- dbpath .. /.. /data/C/RC0 -- logappend -- Port 30000 -- shardsvr -- replset SETC -- rest
/Usr/opensource/mongodb-linux-i686-2.0.2/bin $. /mongod-logpath .. /.. /data/log/C/rc1.log -- dbpath .. /.. /data/C/RC1 -- logappend -- Port 30001 -- shardsvr -- replset SETC -- rest
/Usr/opensource/mongodb-linux-i686-2.0.2/bin $. /mongod-logpath .. /.. /data/log/C/rc2.log -- dbpath .. /.. /data/C/RC2 -- logappend -- Port 30002 -- shardsvr -- replset SETC -- rest
Create a replication group
./Mongo -- Port 30000
> Config = {_ ID: "SETC", members: [{_ ID: 0, host: "127.0.0.1: 30000" },{ _ ID: 1, host: "127.0.0.1: 30001 "},{ _ ID: 2, host:" 127.0.0.1: 30002 "}]}
Start configsvr for three Configuration Service nodes
/Usr/opensource/mongodb-linux-i686-2.0.2/bin $. /mongod -- configsvr -- logpath .. /.. /data/log/configsvr/rc0.log -- dbpath .. /.. /data/configsvr/RC0 -- logappend
-- Port 40000 -- shardsvr
/Usr/opensource/mongodb-linux-i686-2.0.2/bin $. /mongod -- configsvr -- logpath .. /.. /data/log/configsvr/rc1.log -- dbpath .. /.. /data/configsvr/RC1 -- logappend
-- Port 40001 -- shardsvr
/Usr/opensource/mongodb-linux-i686-2.0.2/bin $. /mongod -- configsvr -- logpath .. /.. /data/log/configsvr/rc2.log -- dbpath .. /.. /data/configsvr/RC2 -- logappend
-- Port 40002 -- shardsvr
Start a route Node
/Usr/opensource/mongodb-linux-i686-2.0.2/bin $./mongos -- configdb 127.0.0.1: 40000,127.0 .0.1: 40001,127.0 .0.1: 40002 -- logpath.../data/log/mongos. log -- logappend
-- Port 50000
Set parts
./Mongo 127.0.0.1: 50000
Switch to Admin
Mongos> Use Admin
DB. runcommand ({addshard: "Seta/127.0.0.1: 10000,127.0 .0.1: 10001,127.0 .0.1: 10002", name: "shardseta "})
DB. runcommand ({addshard: "SETB/127.0.0.1: 20000,127.0 .0.1: 20001,127.0 .0.1: 20002", name: "shardsetb "})
DB. runcommand ({addshard: "SETB/127.0.0.1: 20000,127.0 .0.1: 20001,127.0 .0.1: 20002", name: "shardsetb "})
View results
Printshardingstatus ();
Configuration complete