A cluster consists of the following three services:
Shards Server: each shard is composed of one or more mongod processes used to store data.
Config Server: used to store the Metadata information of a cluster, including the information of each Shard and chunks.
Route Server: used to provide the routing service, connected by the Client, so that the entire Cluster looks like a single DB Server
In addition, Chunks are continuous data blocks in MongoDB. The default size is 200 MB, and a Chunk is located on one of the Shard servers.
Next, build a Cluster, which consists of four servers, including two Shard, three Config, and one Route
Each Shard is composed of a Replica Set, and each Replica Set is composed of two Mongod nodes and one vote node.
Directory/opt/soft/mongodb/data,/opt/soft/mongodb/log
192.168.11.229
/Opt/soft/mongodb/bin/mongod-fork-shardsvr-port 10000-replSet set1-dbpath/opt/soft/mongodb/data-logpath/opt/soft/mongodb /log. log
/Opt/soft/mongodb/bin/mongod-fork-shardsvr-port 10001-replSet set2-dbpath/opt/soft/mongodb/data/data1-logpath/opt/soft/mongodb /log/log1.log
192.168.11.17
/Usr/local/mongodb/bin/mongod-fork-shardsvr-port 10000-replSet set1-dbpath/opt/soft/mongodb/data-logpath/pvdata/mongodb_log/mongod. log
192.168.11.227
/Usr/local/mongodb/bin/mongod-fork-shardsvr-port 10000-replSet set2-dbpath/opt/soft/mongodb/data-logpath/opt/soft/mongodb /log/mongod. log
/Usr/local/mongodb/bin/mongod-fork-shardsvr-port 10001-replSet set1-dbpath/opt/soft/mongodb/data/data1-logpath/opt/soft/mongodb /log/mongod1.log
192.168.11.228
/Usr/local/mongodb/bin/mongod-fork-shardsvr-port 10000-replSet set2-dbpath/opt/soft/mongodb/data-logpath/opt/soft/mongodb /log/mongod. log
Connect mongo-port 10000 to mongo on 192.168.11.229
Config = {_ id: 'set1', members :[
{_ Id: 0, host: '192. 168.11.229: 100 '},
{_ Id: 1, host: '192. 168.11.17: 100 '},
{_ Id: 2, host: '192. 168.11.227: 100', arbiterOnly: true}
]}
Rs. initiate (config)
Rs. status ()
Connect mongo-port 10000 to mongo on 192.168.11.227
Config = {_ id: 'set2', members :[
{_ Id: 0, host: '192. 168.11.227: 100 '},
{_ Id: 1, host: '192. 168.11.228: 100 '},
{_ Id: 2, host: '192. 168.11.229: 100', arbiterOnly: true}
]}
Rs. initiate (config)
Rs. status ()
192.168.11.229:; 192.168.11.17; start the process on 192.168.11.228
Mongod -- configsvr -- fork -- logpath/opt/soft/mongodb/log/config. log -- logappend -- dbpath/opt/soft/mongodb/data/configdata -- port 20000
Start the process on 192.168.11.227
Mongos -- fork -- configdb "192.168.11.229: 20000,192.168 .11.17: 20000,192.168 .11.228: 20000" -- logpath/opt/soft/mongodb/log/mongos. log
192.168.11.227
Mongos> use admin
Mongos> db. adminCommand ({addShard: "set1/192.168.20.29: 10000,192.168 .11.17: 10000 "})
Mongos> db. adminCommand ({addShard: "set2/192.168.11.227: 10000,192.168 .11.228: 10000 "})
Mongos> db. adminCommand ({enablesharding: 'test '})
Mongos> db. adminCommand ({listshards: 1 })
Mongos> printShardingStatus ()
Mongos> db. adminCommand ({shardcollection: 'test. test2', key: {_ id: 1}, unique: true })
Import text data (separated by commas)
Export Import-h 192.168.11.227-d test-c test -- type csv-f ip, sid, uid, cateid, type -- file/opt/dm/meta/uidip_20111017