前言

在创建mongodb的replica set的时候,只是做成了1主2从,没有做成1主1从1仲裁。这我们将一个几点从replica set中删除,再以仲裁节点的身份加入到replica set中:

1.初始状态:

shard1ReplSet:PRIMARY> rs.status();rs.status();
{
  "set" : "shard1ReplSet",
  "date" : ISODate("2017-02-21T07:48:03.058Z"),
  "myState" : 1,
  "term" : NumberLong(1),
  "heartbeatIntervalMillis" : NumberLong(2000),
  "optimes" : {
    "lastCommittedOpTime" : {
      "ts" : Timestamp(0, 0),
      "t" : NumberLong(-1)
    },
    "appliedOpTime" : {
      "ts" : Timestamp(1487663274, 1),
      "t" : NumberLong(1)
    },
    "durableOpTime" : {
      "ts" : Timestamp(1487587982, 1),
      "t" : NumberLong(-1)
    }
  },
  "members" : [
    {
      "_id" : 0,
      "name" : "10.13.0.130:22001",
      "health" : 1,
      "state" : 1,
      "stateStr" : "PRIMARY",
      "uptime" : 76672,
      "optime" : {
        "ts" : Timestamp(1487663274, 1),
        "t" : NumberLong(1)
      },
      "optimeDate" : ISODate("2017-02-21T07:47:54Z"),
      "electionTime" : Timestamp(1487587993, 1),
      "electionDate" : ISODate("2017-02-20T10:53:13Z"),
      "configVersion" : 1,
      "self" : true
    },
    {
      "_id" : 1,
      "name" : "10.13.0.131:22001",
      "health" : 1,
      "state" : 2,
      "stateStr" : "SECONDARY",
      "uptime" : 75300,
      "optime" : {
        "ts" : Timestamp(1487663274, 1),
        "t" : NumberLong(1)
      },
      "optimeDurable" : {
        "ts" : Timestamp(1487587982, 1),
        "t" : NumberLong(-1)
      },
      "optimeDate" : ISODate("2017-02-21T07:47:54Z"),
      "optimeDurableDate" : ISODate("2017-02-20T10:53:02Z"),
      "lastHeartbeat" : ISODate("2017-02-21T07:48:02.150Z"),
      "lastHeartbeatRecv" : ISODate("2017-02-21T07:48:02.215Z"),
      "pingMs" : NumberLong(0),
      "syncingTo" : "10.13.0.132:22001",
      "configVersion" : 1
    },
    {
      "_id" : 2,
      "name" : "10.13.0.132:22001",
      "health" : 1,
      "state" : 2,
      "stateStr" : "SECONDARY",
      "uptime" : 75300,
      "optime" : {
        "ts" : Timestamp(1487663274, 1),
        "t" : NumberLong(1)
      },
      "optimeDurable" : {
        "ts" : Timestamp(1487587982, 1),
        "t" : NumberLong(-1)
      },
      "optimeDate" : ISODate("2017-02-21T07:47:54Z"),
      "optimeDurableDate" : ISODate("2017-02-20T10:53:02Z"),
      "lastHeartbeat" : ISODate("2017-02-21T07:48:02.889Z"),
      "lastHeartbeatRecv" : ISODate("2017-02-21T07:48:01.503Z"),
      "pingMs" : NumberLong(0),
      "syncingTo" : "10.13.0.130:22001",
      "configVersion" : 1
    }
  ],
  "ok" : 1
}
shard1ReplSet:PRIMARY> 
shard1ReplSet:PRIMARY> 
shard1ReplSet:PRIMARY> 
shard1ReplSet:PRIMARY> 

2.删除节点:

shard1ReplSet:PRIMARY> rs.remove("10.13.0.132:22001"); rs.remove("10.13.0.132:22001"); 
{ "ok" : 1 }
shard1ReplSet:PRIMARY> rs.status();rs.status();
{
  "set" : "shard1ReplSet",
  "date" : ISODate("2017-02-21T07:50:52.934Z"),
  "myState" : 1,
  "term" : NumberLong(1),
  "heartbeatIntervalMillis" : NumberLong(2000),
  "optimes" : {
    "lastCommittedOpTime" : {
      "ts" : Timestamp(0, 0),
      "t" : NumberLong(-1)
    },
    "appliedOpTime" : {
      "ts" : Timestamp(1487663447, 1),
      "t" : NumberLong(1)
    },
    "durableOpTime" : {
      "ts" : Timestamp(1487587982, 1),
      "t" : NumberLong(-1)
    }
  },
  "members" : [
    {
      "_id" : 0,
      "name" : "10.13.0.130:22001",
      "health" : 1,
      "state" : 1,
      "stateStr" : "PRIMARY",
      "uptime" : 76841,
      "optime" : {
        "ts" : Timestamp(1487663447, 1),
        "t" : NumberLong(1)
      },
      "optimeDate" : ISODate("2017-02-21T07:50:47Z"),
      "electionTime" : Timestamp(1487587993, 1),
      "electionDate" : ISODate("2017-02-20T10:53:13Z"),
      "configVersion" : 2,
      "self" : true
    },
    {
      "_id" : 1,
      "name" : "10.13.0.131:22001",
      "health" : 1,
      "state" : 2,
      "stateStr" : "SECONDARY",
      "uptime" : 75470,
      "optime" : {
        "ts" : Timestamp(1487663447, 1),
        "t" : NumberLong(1)
      },
      "optimeDurable" : {
        "ts" : Timestamp(1487587982, 1),
        "t" : NumberLong(-1)
      },
      "optimeDate" : ISODate("2017-02-21T07:50:47Z"),
      "optimeDurableDate" : ISODate("2017-02-20T10:53:02Z"),
      "lastHeartbeat" : ISODate("2017-02-21T07:50:51.182Z"),
      "lastHeartbeatRecv" : ISODate("2017-02-21T07:50:52.212Z"),
      "pingMs" : NumberLong(0),
      "configVersion" : 2
    }
  ],
  "ok" : 1
}
shard1ReplSet:PRIMARY> 
shard1ReplSet:PRIMARY> 
shard1ReplSet:PRIMARY> 

3.添加成arbiter节点:

shard1ReplSet:PRIMARY> rs.addArb("10.13.0.132:22001");rs.addArb("10.13.0.132:22001");
{ "ok" : 1 }
shard1ReplSet:PRIMARY> 
shard1ReplSet:PRIMARY> rs.status();rs.status();
{
  "set" : "shard1ReplSet",
  "date" : ISODate("2017-02-21T07:54:05.161Z"),
  "myState" : 1,
  "term" : NumberLong(1),
  "heartbeatIntervalMillis" : NumberLong(2000),
  "optimes" : {
    "lastCommittedOpTime" : {
      "ts" : Timestamp(0, 0),
      "t" : NumberLong(-1)
    },
    "appliedOpTime" : {
      "ts" : Timestamp(1487663637, 1),
      "t" : NumberLong(1)
    },
    "durableOpTime" : {
      "ts" : Timestamp(1487587982, 1),
      "t" : NumberLong(-1)
    }
  },
  "members" : [
    {
      "_id" : 0,
      "name" : "10.13.0.130:22001",
      "health" : 1,
      "state" : 1,
      "stateStr" : "PRIMARY",
      "uptime" : 77034,
      "optime" : {
        "ts" : Timestamp(1487663637, 1),
        "t" : NumberLong(1)
      },
      "optimeDate" : ISODate("2017-02-21T07:53:57Z"),
      "electionTime" : Timestamp(1487587993, 1),
      "electionDate" : ISODate("2017-02-20T10:53:13Z"),
      "configVersion" : 3,
      "self" : true
    },
    {
      "_id" : 1,
      "name" : "10.13.0.131:22001",
      "health" : 1,
      "state" : 2,
      "stateStr" : "SECONDARY",
      "uptime" : 75662,
      "optime" : {
        "ts" : Timestamp(1487663637, 1),
        "t" : NumberLong(1)
      },
      "optimeDurable" : {
        "ts" : Timestamp(1487587982, 1),
        "t" : NumberLong(-1)
      },
      "optimeDate" : ISODate("2017-02-21T07:53:57Z"),
      "optimeDurableDate" : ISODate("2017-02-20T10:53:02Z"),
      "lastHeartbeat" : ISODate("2017-02-21T07:54:03.210Z"),
      "lastHeartbeatRecv" : ISODate("2017-02-21T07:54:02.211Z"),
      "pingMs" : NumberLong(0),
      "configVersion" : 3
    },
    {
      "_id" : 2,
      "name" : "10.13.0.132:22001",
      "health" : 1,
      "state" : 7,
      "stateStr" : "ARBITER",
      "uptime" : 5,
      "lastHeartbeat" : ISODate("2017-02-21T07:54:03.214Z"),
      "lastHeartbeatRecv" : ISODate("2017-02-21T07:54:02.274Z"),
      "pingMs" : NumberLong(0),
      "configVersion" : 3
    }
  ],
  "ok" : 1
}
shard1ReplSet:PRIMARY> 

注1: mongodb 3.4之后,虽然要求config server为replica set,但是不支持arbiter。

添加的时候,会报错:

cfgReplSet:PRIMARY> rs.addArb("10.13.0.132:21000");rs.addArb("10.13.0.132:21000");
{
  "ok" : 0,
  "errmsg" : "Arbiters are not allowed in replica set configurations being used for config servers",
  "code" : 103,
  "codeName" : "NewReplicaSetConfigurationIncompatible"
}
cfgReplSet:PRIMARY> 

注2:rs.reconfig()也可以进行操作,效果类似re.remove+rs.addArb,详见:mongodb官方文档- Remove Members from Replica Set

总结

以上就是关于mongodb添加arbiter节点的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。

标签:
mongodb,arbiter,mongodb,添加节点,mongodb,arbiter作用

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com

评论“mongodb添加arbiter节点的方法示例”

暂无“mongodb添加arbiter节点的方法示例”评论...

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?