Mongodb增加、移除Shard Server实例

发布时间:2022-04-21 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Mongodb增加、移除Shard Server实例脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

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.

脚本宝典总结

以上是脚本宝典为你收集整理的Mongodb增加、移除Shard Server实例全部内容,希望文章能够帮你解决Mongodb增加、移除Shard Server实例所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:增加移除