1.增加新的配置文件,并啟動mongod實(shí)例
復(fù)制代碼 代碼如下:
#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 集群
復(fù)制代碼 代碼如下:
/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
復(fù)制代碼 代碼如下:
/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
復(fù)制代碼 代碼如下:
db.runCommand({"removeshard" : "shard3/192.168.1.14:10003,192.168.1.16:10003,192.168.1.23:10003"});
注意:
三臺服務(wù)器clock不同步導(dǎo)致不能分片的問題,今天又碰見一次,同步后就好了。這個(gè)問題是不是有點(diǎn)太頻繁了,難道每天定時(shí)要同步三臺服務(wù)器的clock?
移除shard的時(shí)候時(shí)間會比較久,這時(shí)候 printShardingStatus()的時(shí)候會顯示狀態(tài)”draining” : true.