1.增加新的配置文件,并启动mongod实例
#14
mkdir -p /data/mongodb/shard311
./mongod -f /opt/mongodb-linux-x86_64-2.2.0/conf/mongod_3.conf
#16
mkdir -p /data/mongodb/shard32
./mongod -f /opt/mongodb-linux-x86_64-2.2.0/conf/mongod_3.conf
#23
mkdir -p /data/mongodb/shard33
./mongod -f /opt/mongodb-linux-x86_64-2.2.0/conf/mongod_3.conf
2.步骤2 初始化 set 集群
/opt/mongodb-linux-x86_64-2.2.0/bin/mongo -port 10003
config = {_id: \'shard3\', members: [
{_id: 0, host: \'192.168.1.14:10003\', priority:1},
{_id: 1, host: \'192.168.1.16:10003\'},
{_id: 2, host: \'192.168.1.23:10003\'}]};
rs.initiate(config);
3.增加shard
/opt/mongodb-linux-x86_64-2.2.0/bin/mongo 192.168.1.14:10000/admin
db.runCommand( {
addshard : \"shard3/192.168.1.14:10003,192.168.1.16:10003,192.168.1.23:10003\",
name:\"shard3\",
maxsize:20480,
allowLocal:true } );
4.移除shard
db.runCommand({\"removeshard\" : \"shard3/192.168.1.14:10003,192.168.1.16:10003,192.168.1.23:10003\"});
注意:
三台服务器clock不同步导致不能分片的问题,今天又碰见一次,同步后就好了。这个问题是不是有点太频繁了,难道每天定时要同步三台服务器的clock?
移除shard的时候时间会比较久,这时候 printShardingStatus()的时候会显示状态”draining” : true.