节点仲裁mongodb replica sets reconfig and conver a Secondary to an Arbiter

题记:写这篇博客要主是加深自己对节点仲裁的认识和总结实现算法时的一些验经和训教,如果有错误请指出,万分感谢。

    replica set由于需求可能会调整节点的优先级,或者仲裁节点

    

那么先看一下法语:
rs.reconfig(configuration[force])
Parameters:
  • configuration – A document that specifies the configuration of a replica set.
  • force – Optional. Specify { force: true } as the force parameter to force the replica set to accept the new configuration even if a majority of the members are not accessible. Use with caution, as this can lead to rollback situations.

Initializes a new replica set configuration. This function will disconnect the shell briefly and forces a reconnection as the replica set renegotiates which node will be primary. As a result, the shell will display an error even if this command succeeds.

rs.reconfig() provides a wrapper around the “replSetReconfig” database command.

rs.reconfig() overwrites the existing replica set configuration. Retrieve the current configuration object with rs.conf(), modify the configuration as needed and then use rs.reconfig() to submit the modified configuration object.

To reconfigure a replica set, use the following sequence of operations:

conf = rs.conf()

// modify conf to change configuration

rs.reconfig(conf)

If you want to force the reconfiguration if a majority of the set isn’t connected to the current member, or you’re issuing the command against a secondary, use the following form:

conf = rs.conf()

// modify conf to change configuration

rs.reconfig(conf, { force: true } )

Warning

 

Forcing a rs.reconfig() can lead to rollback situations and other difficult to recover from situations. Exercise caution when using this option.这里到遇rollback情况,可能会致使fatal态状,那么replica set就于等效失了,可以拷贝local数据文件,或者有所数据文件停止建重

举例:
    每日一道理
书,各种各样的书。书,寄托着人类热切的希望;书,蕴含着人类丰富的感悟。提起书,会有说不完的话语……
var c = rs.conf();
c.members[2].priority = 0;  0~100数字越大优先级越高,0不会被切换为primary节点,这里也可以写成包括数小的值
rs.reconfig(c);

    

配置完当前,可以通过一下令命查看一下配置否是修改好:

    

rs.conf()
rs.status()

    

为了止防脑裂,可以参加仲裁节点,应用以下令命:

    

rs.addArb("<hostname>:<:port>"); ==rs.add(hostspecarbiterOnly)

    

示例:

    

rs.add('mongodb3.example.net:27017', true)

    

当然将一个从节点转换为仲裁节点:

    

(1)首先关闭从节点

    

(2)rs.remove("<hostname><:port>")删除该从节点,rs.conf()验证一下

    

(3)创立新的数据目录,因为仲裁节点是不存放产生数据的

    

(4)通过rs.addArb("<hostname>:<:port>")参加,rs.conf()验证一下

    

那么以可就看到:仲裁节点的属性为"arbiterOnly" : true

    

{
        "_id" : "xxx",
        "version" : 14,
        "members" : [
                {
                        "_id" : 1,
                        "host" : "xxx.xxx.xxx.xxx:5281"
                },
                {
                        "_id" : 2,
                        "host" : " xxx.xxx.xxx.xxx :5281",
                        "arbiterOnly" : true
                },
                {
                        "_id" : 3,
                        "host" : " xxx.xxx.xxx.xxx :5281"
                }
        ]
}

文章结束给大家分享下程序员的一些笑话语录: 3G普不普及现在已经不是看终端了,而是看应用,有好的,便宜实用的应用,花1000多买个能用的智能手机应该不是什么难事。反过来说,你200元拿一个智能手机,没有好的应用,看个电影要几十元,也是没人用3G。

posted @ 2013-05-02 20:18  坚固66  阅读(277)  评论(0编辑  收藏  举报