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