第40章:MongoDB-集群--Replica Sets(副本集)---副本集的管理

①以单机模式启动成员

由于很多维护的工作需要写入操作,所以不合适在副本集中操作,可以以单机模式启动成员,也就是不要使用副本的选项,就跟以前启动单独的服务器一样。一般使用一个跟副本集配置中不一样的端口号,这样其他成员会认为这个服务器挂了。

②副本集的配置

副本集的配置以一个文档的形式保存在local.system.replSet集合中,副本集中所有成员的这个文档都是相同的。绝对不要使用update来更新这个文档,应该使用rs或者replSetReconfig命令来修改副本集的配置。

1:创建副本集,这个前面学过,就是启动所有的成员服务器后,使用rs.initiate命令

2:修改副本集成员,前面也学过一些,比如rs.add(),rs.remove()命令,还可以使用

rs.reconfig(config)命令,比如修改第一个成员的host名称,

示例如下:

var config = rs.config();

config.members[0].host="newHost:port";

rs.reconfig(config);

修改其他的也一样,先rs.config()得到当前配置,然后修改数据,再rs.reconfig就OK了,但有如下几个限制:

 

(1):不能修改成员的"_id"字段

(2):不能将接收rs.reconfig命令的成员的优先级设置为0

(3):不能将仲裁者变成正常成员,反之也不行

(4):不能将buildIndexes为false的成员修改为true

 

③创建比较大的副本集

副本集最多只能拥有12个成员,只有7个成员拥有投票权。因此要创建超过7个副本集的话,需要将其他成员的投票权设置为0,例如:

rs.add({"_id":8,"host":"localhost:20008","votes":0});

如果要配置超过12个成员的话,需要使用Master/Slave的方式,不过这个方式已经不建议使用了,如果将来副本集能支持更多成员的话,这个方式可能会立即废除。

④强制重新配置

如果副本集无法达到"大多数"要求的话,可能会无法选出主节点,这个时候,可以shell连接任意一个成员,然后使用force选项强制重新配置,示例如下:

rs.reconfig(config,{"force":true});

⑤把主节点变为备份节点

可以使用stepDown函数,可以自己指定退化的持续时间,示例如下:

rs.stepDown(); 或者rs.stepDown(60); //秒为单位

⑥阻止选举

如果对主节点进行维护,但不希望这段时间其他节点选举新的主节点,可以在每个备份节点上执行freeze命令,强制他们始终处于备份状态。例如:

rs.freeze(100); //秒为单位,表示冻结多长时间

如果在主节点上执行rs.freeze(0);,可以将退位的主节点重新变为主节点。

⑦使用维护模式

当在副本集的某个成员上执行一个非常耗时的功能的话,可以设置该成员进入维护模式,方式如下:db.adminCommand({"replSetMaintenanceMode":true});

要从维护模式中恢复的话,设置为false就可以了。

⑧不作为复制源
如果希望都从主节点复制数据,可以把所有的备份成员的allowChaining设置为false

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/Lucky-stars/p/10555520.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
为什么会这样[user_mongo@nosql01 replicaset]$ cd /opt [user_mongo@nosql01 opt]$ ll total 0 drwxr-xr-x. 3 root root 25 Mar 16 17:08 servers drwxr-xr-x. 2 root root 51 Mar 16 17:10 software [user_mongo@nosql01 opt]$ tar -zxvf /opt/software/mongodb-linux-x86_64-rhel70-4.4.12.tgz -C /opt/servers/mongodb_demo/replicaset/ mongodb-linux-x86_64-rhel70-4.4.12/LICENSE-Community.txt tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/LICENSE-Community.txt: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/MPL-2 tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/MPL-2: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/README tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/README: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/THIRD-PARTY-NOTICES tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/THIRD-PARTY-NOTICES: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/install_compass tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/install_compass: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongo tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongo: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongod tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongod: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongos tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongos: Cannot open: No such file or directory tar: Exiting with failure status due to previous errors [user_mongo@nosql01 opt]$ tar -zcvf /opt/software/mongodb-linux-x86_64-rhel70-4.4.12.tgz -C /opt/servers/mongodb_demo/replicaset/ tar: Cowardly refusing to create an empty archive Try `tar --help' or `tar --usage' for more information.
06-01

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值