• 1台Primary,1台Secondary,1台Arbiter
  • 当Arbiter挂了
  • Primary和Secondary的主从不会切换
  • 外部应用服务不受影响
  • 在Primary上重新配置拓扑,去掉原有Aribter引入新的Arbiter, 命令如下。这个操作对Primary,Secondary以及外部应用都没有影响。

rs.reconfig({"_id" : "rs1","members" : [{"_id" : 0, "host" : "127.0.0.1:27017","priority":1},{"_id" : 1, "host" : "127.0.0.1:27018","priority":2},{"_id" : 2, "host" : "127.0.0.1:27019","arbiterOnly" : true}]});

  • Primary和Arbiter同时挂了
  • Secondary一直保持Secondary状态,不会自动切换为Primary。重启之后,仍然保持Secondary状态。
  • 外部应用服务不能读写,且应用服务不能正常重启
  • 重启Primary,则经过几秒钟之后,Primary恢复成Primary状态,则外部应用能正常重启,外部应用读写正常,如果外部应用没有重启,则仍然能恢复正常读写;Primary与Secondary之间数据同步恢复正常。
  • 如果因为硬件等原因Primary不能重启,则需要在Secondary的上强制修改拓扑配置,将其余节点去掉,并将原来的Secondary指定为新的Primary,然后修改应用服务的mongo URL指向新的Primary再重启应用服务。修改命令如下:
rs1:SECONDARY> use admin
switched to db admin
rs1:SECONDARY> db.auth('admin','adminpassword')
1
rs1:SECONDARY> rs.reconfig({"_id" : "rs1","members" : [{"_id" : 1, "host" : "127.0.0.1:27018","priority":2}]},{ force: true });
{ "ok" : 1 }
rs1:SECONDARY> rs.status()
{
"set" : "rs1",
"date" : ISODate("2018-11-09T07:02:58.605Z"),
"myState" : 1,
"term" : NumberLong(24),
"heartbeatIntervalMillis" : NumberLong(2000),
"members" : [
{
"_id" : 1,
"name" : "127.0.0.1:27018",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 1662,
"optime" : {
"ts" : Timestamp(1541746976, 2),
"t" : NumberLong(24)
},
"optimeDate" : ISODate("2018-11-09T07:02:56Z"),
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1541746976, 1),
"electionDate" : ISODate("2018-11-09T07:02:56Z"),
"configVersion" : 281693,
"self" : true
}
],
"ok" : 1
}
rs1:PRIMARY>

等原有Primary恢复以后,再将其作为Secondary加入到拓扑当中,需要在新的Primary上修改配置,命令如下

rs1:PRIMARY> rs.reconfig({"_id" : "rs1","members" : [{"_id" : 0, "host" : "127.0.0.1:27017","priority":1},{"_id" : 1, "host" : "127.0.0.1:27018","priority":2},{"_id" : 2, "host" : "127.0.0.1:27019","arbiterOnly" : true}]});
  • 1台Primary,2台Secondary,1台Arbiter
  • Primary和Arbiter同时挂了,达到总节点数的一半
  • 2台Secondary无法自动选出一个Primary,日志中会报“Not starting an election, since we are not electable due to: Not standing for election because I cannot see a majority (mask 0x1)”
  • 1台Primary,3台Secondary,1台Arbiter
  • Primary和Arbiter同时挂了
  • 3台Secondary会自动选出一个Primary,先选priority值最大的,priority值相同的情况则随机选择。
  • Primary和其中一个Secondary同时挂了
  • 2台Secondary中会自动选出一个Primary,先选priority值最大的,priority值相同的情况则随机选择。
  • Primary,其中一个Secondary和Arbiter同时挂了
  • 2台Secondary无法自动选出一个Primary,日志中会报“Not starting an election, since we are not electable due to: Not standing for election because I cannot see a majority (mask 0x1)”
  • 1台Primary,4台Secondary,1台Arbiter
  • Primary和Arbiter同时挂了
  • 4台Secondary会自动选出一个Primary,暂时没有发现有平局的情况
  • Primary,Arbiter和一个Secondary同时挂,达到总节点数的一半
  • 3台Secondary无法自动选出一个Primary,日志中会报“Not starting an election, since we are not electable due to: Not standing for election because I cannot see a majority (mask 0x1)”
  • Primary和2个Secondary同时挂,达到总节点数的一半
  • 2台Secondary无法自动选出一个Primary,日志中会报“Not starting an election, since we are not electable due to: Not standing for election because I cannot see a majority (mask 0x1)”

多个Secondary节点并不是全部都从主节点同步,也可以从其它从节点同步。Secondaries may automatically change their sync from source as needed based on changes in the ping time and state of other members’ replication.

应用服务里所配的多个Mongo IP只要有一个还处于存活状态,则读写正常,应用服务重启也正常。