复制集成员配置管理

1.修改成员priority
The value of priority can be any floating point (i.e. decimal) number between 0 and 1000. The default value for the 

priority field is 1.The higher the number, the higher the priority.

Hidden members, delayed members, and arbiters all have priority set to 0

MongoDB does not permit the current primary to have a priority of 0. To prevent the current primary from again becoming a 

primary, you must first step down the current primary using rs.stepDown().

操作步骤:

cfg = rs.conf()

cfg.members[0].priority = 0.5
cfg.members[1].priority = 2
cfg.members[2].priority = 2

rs.reconfig(cfg)

2.配置隐藏成员

If the chainingAllowed setting allows secondary members to sync from other secondaries, MongoDB by default prefers non-

hidden members over hidden members when selecting a sync target. MongoDB will only choose hidden members as a last 

resort. If you want a secondary to sync from a hidden member, use the replSetSyncFrom database command to override the 

default sync target. See the documentation for replSetSyncFrom before using the command.

操作步骤:
rs0:PRIMARY> cfg = rs.conf()
{
	"_id" : "rs0",
	"version" : 6,
	"members" : [
		{
			"_id" : 0,
			"host" : "standby:27017"
		},
		{
			"_id" : 1,
			"host" : "primary:27017"
		},
		{
			"_id" : 2,
			"host" : "mail:27017"
		}
	]
}

rs0:PRIMARY> cfg.members[2].priority = 1
1
rs0:PRIMARY> cfg.members[2].hidden = false
false
rs0:PRIMARY> rs.reconfig(cfg)
2014-10-29T08:16:04.604+0800 DBClientCursor::init call() failed
2014-10-29T08:16:04.606+0800 trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2014-10-29T08:16:04.608+0800 reconnect 127.0.0.1:27017 (127.0.0.1) ok
reconnected to server after rs command (which is normal)

rs0:PRIMARY> cfg = rs.conf()
{
	"_id" : "rs0",
	"version" : 5,
	"members" : [
		{
			"_id" : 0,
			"host" : "standby:27017"
		},
		{
			"_id" : 1,
			"host" : "primary:27017"
		},
		{
			"_id" : 2,
			"host" : "mail:27017",
			"priority" : 0,
			"hidden" : true
		}
	]
}

rs0:PRIMARY> db.isMaster()
{
	"setName" : "rs0",
	"setVersion" : 5,
	"ismaster" : true,
	"secondary" : false,
	"hosts" : [
		"standby:27017",
		"primary:27017"               //这里已经没有mail了
	],
	"primary" : "standby:27017",
	"me" : "standby:27017",
	"maxBsonObjectSize" : 16777216,
	"maxMessageSizeBytes" : 48000000,
	"maxWriteBatchSize" : 1000,
	"localTime" : ISODate("2014-10-29T00:14:58.576Z"),
	"maxWireVersion" : 2,
	"minWireVersion" : 0,
	"ok" : 1
}

3.配置延时成员
After the replica set reconfigures, the delayed secondary member cannot become primary and is hidden from applications. 

The slaveDelay value delays both replication and the member’s oplog by 3600 seconds (1 hour).

操作步骤:
rs0:PRIMARY> cfg = rs.conf()
{
	"_id" : "rs0",
	"version" : 6,
	"members" : [
		{
			"_id" : 0,
			"host" : "standby:27017"
		},
		{
			"_id" : 1,
			"host" : "primary:27017"
		},
		{
			"_id" : 2,
			"host" : "mail:27017"
		}
	]
}
rs0:PRIMARY> cfg.members[2].priority = 0
0
rs0:PRIMARY> cfg.members[2].hidden = true
true
rs0:PRIMARY> cfg.members[2].slaveDelay = 3600
3600
rs0:PRIMARY> rs.reconfig(cfg)
2014-10-29T08:21:28.120+0800 DBClientCursor::init call() failed
2014-10-29T08:21:28.122+0800 trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2014-10-29T08:21:28.125+0800 reconnect 127.0.0.1:27017 (127.0.0.1) ok
reconnected to server after rs command (which is normal)

rs0:PRIMARY> rs.conf()
{
	"_id" : "rs0",
	"version" : 7,
	"members" : [
		{
			"_id" : 0,
			"host" : "standby:27017"
		},
		{
			"_id" : 1,
			"host" : "primary:27017"
		},
		{
			"_id" : 2,
			"host" : "mail:27017",
			"priority" : 0,
			"slaveDelay" : 3600,
			"hidden" : true
		}
	]
}

4.配置不能投票的成员
Non-voting members allow you to add additional members for read distribution beyond the maximum seven voting members. To configure a member as non-voting, set its votes value to 0. To disable the ability to vote in elections

操作步骤:
cfg = rs.conf()
cfg.members[3].votes = 0
cfg.members[4].votes = 0
cfg.members[5].votes = 0
rs.reconfig(cfg)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值