粗陋的记录一下
shard1:
config = {_id : "shard1",members : [{_id : 0, host : "192.168.0.120:27001" }, {_id : 1, host : "192.168.0.121:27001", arbiterOnly: true }, {_id : 2, host : "192.168.0.122:27001" }]}
rs.initiate(config);
shard2:
config = {_id : "shard2",members : [{_id : 0, host : "192.168.0.120:27002" }, {_id : 1, host : "192.168.0.121:27002" }, {_id : 2, host : "192.168.0.122:27002", arbiterOnly: true }]}
仲裁不能再同一台服务器上换下就可以
shard3:
config = {_id : "shard3",members : [{_id : 0, host : "192.168.0.120:27003", arbiterOnly: true}, {_id : 1, host : "192.168.0.121:27003" }, {_id : 2, host : "192.168.0.122:27003" }]}
server:
config = {_id : "configs",members : [{_id : 0, host : "192.168.0.120:21000" }, {_id : 1, host : "192.168.0.121:21000" }, {_id : 2, host : "192.168.0.122:21000" }]}
13 21 32
12 23 31
pidfilepath = /data/mongodb/mongos/log/mongos.pid
logpath = /data/mongodb/mongos/log/mongos.log
logappend = true
bind_ip = 0.0.0.0
port = 20000
fork = true
#监听的配置服务器,只能有1个或者3个 configs为配置服务器的副本集名字
configdb = configs/172.25.34.210:21000,172.25.34.211:21000,172.25.34.212:21000
#设置最大连接数
maxConns=20000
sh.addShard("shard1/192.168.0.120:27001,192.168.0.121:27001,192.168.0.122:27001")
sh.addShard("shard2/192.168.0.120:27002,192.168.0.121:27002,192.168.0.122:27002")
sh.addShard("shard3/192.168.0.120:27003,192.168.0.121:27003,192.168.0.122:27003")
./mongod -f /opt/mongodb/mongodb-linux-x86_64-4.0.10/conf/config.conf
./mongod -f /opt/mongodb/mongodb-linux-x86_64-4.0.10/conf/shard1.conf
./mongod -f /opt/mongodb/mongodb-linux-x86_64-4.0.10/conf/shard2.conf
./mongod -f /opt/mongodb/mongodb-linux-x86_64-4.0.10/conf/shard3.conf
./mongos -f /opt/mongodb/mongodb-linux-x86_64-4.0.10/conf/mongos.conf
use admin
db.runCommand( { enablesharding :"kaliarchdb"}); #开启kaliarch库分片功能
db.runCommand( { shardcollection : "kaliarchdb.table1",key : {_id:"hashed"} } ) #指定数据库里需要分片的集合tables和片键_id
for (var i = 1; i <= 10000; i++) db.table1.save({id:i,"test2":"testval1"});
db.table1.stats();
rs.status();