MongoDB副本集配置系列四:节点的关闭顺序

接上一篇博客:http://www.cnblogs.com/xiaoit/p/4522218.html

Primary Secondary Arbiter
1:关闭顺序PSA :会报错
2:关闭顺序PAS :可以
3:关闭顺序SAP :主节点会变为从节点
4:关闭顺序SPA :会报错
5:关闭顺序APS
6:关闭顺序ASP :主节点会变为从节点

  

1:关闭顺序PSA
gechongrepl:PRIMARY> rs.isMaster()
{
	"setName" : "gechongrepl",
	"setVersion" : 13,
	"ismaster" : true,
	"secondary" : false,
	"hosts" : [
		"192.168.91.133:27017",
		"192.168.91.132:27017",
		"192.168.91.132:27018"
	],
	"arbiters" : [
		"192.168.91.135:27017"
	],
	"primary" : "192.168.91.133:27017",
	"me" : "192.168.91.133:27017",
	"electionId" : ObjectId("5568098a6de3d53a2ea91c64"),
	"maxBsonObjectSize" : 16777216,
	"maxMessageSizeBytes" : 48000000,
	"maxWriteBatchSize" : 1000,
	"localTime" : ISODate("2015-05-29T06:39:36.548Z"),
	"maxWireVersion" : 3,
	"minWireVersion" : 0,
	"ok" : 1
}

  

P:

gechongrepl:PRIMARY> use admin
switched to db admin
gechongrepl:PRIMARY> db.shutdownServer()

S:

从变为了:gechongrepl:PRIMARY>

gechongrepl:PRIMARY> use admin
switched to db admin
gechongrepl:PRIMARY> db.shutdownServer()
assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:48:06.022-0700
Error: assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:48:06.022-0700
at Error (<anonymous>)
at doassert (src/mongo/shell/assert.js:11:14)
at assert (src/mongo/shell/assert.js:20:5)
at DB.shutdownServer (src/mongo/shell/db.js:212:9)
at (shell):1:4
2015-05-28T23:48:06.023-0700 E QUERY Error: assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:48:06.022-0700
at Error (<anonymous>)
at doassert (src/mongo/shell/assert.js:11:14)
at assert (src/mongo/shell/assert.js:20:5)
at DB.shutdownServer (src/mongo/shell/db.js:212:9)
at (shell):1:4 at src/mongo/shell/assert.js:13

A:

gechongrepl:ARBITER> use admin
switched to db admin
gechongrepl:ARBITER> db.shutdownServer()

  

  

再次关闭S:

S变为了:ggechongrepl:SECONDARY> 

gechongrepl:SECONDARY> use admin
switched to db admin
gechongrepl:SECONDARY> db.shutdownServer()

  

2:关闭顺序PAS : 已经验证,不报错。

3:关闭顺序SAP

S:

gechongrepl:SECONDARY> use admin
switched to db admin
gechongrepl:SECONDARY> db.shutdownServer()

  

A:

gechongrepl:ARBITER> use admin
switched to db admin
gechongrepl:ARBITER> db.shutdownServer()

  

P:

主变为了:gechongrepl:SECONDARY>

gechongrepl:SECONDARY> use admin
switched to db admin
gechongrepl:SECONDARY> db.shutdownServer()

  

4:关闭顺序SPA

S:

gechongrepl:SECONDARY> use admin
switched to db admin
gechongrepl:SECONDARY> db.shutdownServer()

P:

gechongrepl:PRIMARY> use admin
switched to db admin
gechongrepl:PRIMARY> db.shutdownServer()
assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:59:19.685-0700
Error: assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:59:19.685-0700
    at Error (<anonymous>)
    at doassert (src/mongo/shell/assert.js:11:14)
    at assert (src/mongo/shell/assert.js:20:5)
    at DB.shutdownServer (src/mongo/shell/db.js:212:9)
    at (shell):1:4
2015-05-28T23:59:19.702-0700 E QUERY    Error: assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:59:19.685-0700
    at Error (<anonymous>)
    at doassert (src/mongo/shell/assert.js:11:14)
    at assert (src/mongo/shell/assert.js:20:5)
    at DB.shutdownServer (src/mongo/shell/db.js:212:9)
    at (shell):1:4 at src/mongo/shell/assert.js:13

A:

gechongrepl:ARBITER> use admin
switched to db admin
gechongrepl:ARBITER> db.shutdownServer()

  

再次关闭P:

gechongrepl:PRIMARY> use admin
switched to db admin
2015-05-29T00:00:44.938-0700 I NETWORK  DBClientCursor::init call() failed
2015-05-29T00:00:44.940-0700 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2015-05-29T00:00:44.941-0700 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) ok
gechongrepl:SECONDARY> db.shutdownServer()

  

下面猜测:在关闭最后的Primary节点之前,先关掉仲裁节点即不会报错。(首先关掉Primary节点,还有其他Secondary不属于这种情况)

5:关闭顺序APS : 不会报错
6:关闭顺序ASP : 不会报错

验证猜测:

5:关闭顺序APS

A:

gechongrepl:ARBITER> use admin
switched to db admin
gechongrepl:ARBITER> db.shutdownServer()

  

P:

gechongrepl:PRIMARY> use admin
switched to db admin
gechongrepl:PRIMARY> db.shutdownServer()

  

S:因为仲裁节点关闭了。所以Primary节点不会再自动切换

gechongrepl:SECONDARY> use admin
switched to db admin
gechongrepl:SECONDARY> db.shutdownServer()

  

6:关闭顺序ASP

A:

gechongrepl:ARBITER> use admin
switched to db admin
gechongrepl:ARBITER> db.shutdownServer()

  

S:

gechongrepl:SECONDARY> use admin
switched to db admin
gechongrepl:SECONDARY> db.shutdownServer()

  

P:

gechongrepl:PRIMARY>
2015-05-29T00:12:23.962-0700 I NETWORK  DBClientCursor::init call() failed
2015-05-29T00:12:23.965-0700 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2015-05-29T00:12:23.966-0700 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) ok
gechongrepl:SECONDARY>
gechongrepl:SECONDARY> use admin
switched to db admin
gechongrepl:SECONDARY> db.shutdownServer()

  

总结:

1:先关闭从节点、仲裁节点。或者先关闭仲裁节点,最后关闭从节点。则:主节点自动变为从节点

2:先关闭主节点,则从节点自动变为主节点,在仲裁节点关闭之前,新主节点不能关闭

初始化的时候主从节点受priority的影响

priority: 是优先级,默认为1,优先级0为被动节点,不能成为活跃节点。优先级不位0则按照有大到小选出活跃节点。

 

时间: 2024-10-11 04:16:10

MongoDB副本集配置系列四:节点的关闭顺序的相关文章

MongoDB副本集配置系列三:副本集的认证方式

1:副本集配置参考这篇博客: http://www.cnblogs.com/xiaoit/p/4478951.html 2:副本集的认证 假设有两台机器已经配置好了副本集(副本集罪一般最少3台机器,这里只做演示使用) 192.168.91.132 192.168.91.133 副本集总体思路是用户名.密码和keyfile文件,keyfile需要各个副本集服务启动时加载而且要是同一文件,然后在操作库是需要用户名.密码KeyFile文件必须满足条件:(1)至少6个字符,小于1024字节(2)认证时候

MongoDB副本集配置系列十一:MongoDB 数据同步原理和自动故障转移的原理

1:数据同步的原理: 当Primary节点完成数据操作后,Secondary会做出一系列的动作保证数据的同步: 1:检查自己local库的oplog.rs集合找出最近的时间戳. 2:检查Primary节点local库oplog.rs集合,找出大于此时间戳的记录. 3:将找到的记录插入到自己的oplog.rs集合中,并执行这些操作. 2:查看副本集的信息 gechongrepl:PRIMARY> rs.status() { "set" : "gechongrepl&quo

MongoDB副本集配置系列二:配置MongoDB副本集

接上一篇博客: http://www.cnblogs.com/xiaoit/p/4479066.html 1:首先创建3台虚拟机作为配置环境 IP1:192.168.91.128 IP2:192.168.91.129 IP3:192.168.91.130 2:下载MongoDB 2.6版本 https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-2.6.9.zip 3:解压 tar -zxvf mongodb-linux-x8

MongoDB副本集配置系列十:MongoDB local库详解和数据同步原理

1:local库是MongoDB的系统库,记录着时间戳和索引和复制集等信息 gechongrepl:PRIMARY> use local switched to db local gechongrepl:PRIMARY> show tables me oplog.rs replset.minvalid slaves startup_log system.indexes system.replset temp 2:local库下的每个集合分别记录的内容 local库下面的me集合保存了服务器名称

MongoDB副本集配置系列七:MongoDB oplog详解

1:oplog简介 oplog是local库下的一个固定集合,Secondary就是通过查看Primary 的oplog这个集合来进行复制的.每个节点都有oplog,记录这从主节点复制过来的信息,这样每个成员都可以作为同步源给其他节点. 2:副本集数据同步的过程 副本集中数据同步的详细过程:Primary节点写入数据,Secondary通过读取Primary的oplog得到复制信息,开始复制数据并且将复制信息写入到自己的oplog.如果某个操作失败(只有当同步源的数据损坏或者数据与主节点不一致时

MongoDB副本集配置系列八:MongoDB监控

1:Mongostat MongoDB2.6版本 MongoDB3.0版本 2:db.setProfilingLevel(2):打开profiler 类似于MySQL的slow log Profiler默认是关闭的,你可以选择全部开启,或者有慢查询的时候开启. db.setProfilingLevel(level,<slowms>) 0=off 1=slow 2=all > use test switched to db test > db.setProfilingLevel(2)

MongoDB副本集配置系列九:MongoDB 常见问题

What is a namespace in MongoDB? If you remove a document, does MongoDB remove it from disk? When does MongoDB write updates to disk? How do I do transactions and locking in MongoDB? How do you aggregate data with MongoDB? Why does MongoDB log so many

MongoDB副本集配置系列六:定位MongoDB慢的原因

1:想知道哪些操作拖慢了MongoDB的速度,首先需要检查当前正在执行哪些操作. gechongrepl:PRIMARY> db.currentOp() "opid" : 78891,#操作的唯一标识符,可通过它来终止操作 "active" : true,#true表示当前正在运行,false表示此操作已交出或在等待其他操作交出锁 "secs_running" : 1,#查看执行时间,可以通过该参数定位耗时的操作 "microse

MongoDB副本集配置系列一:安装MongoDB

1:下载MongoDB 2.6版本 https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-2.6.9.zip 2:解压 tar -zxvf mongodb-linux-x86_64-2.6.9.zip mv mongodb-linux-x86_64-2.6.9 mongodb 3:在mongodb目录创建 data目录和 log 目录 和conf配置文件 同时保证data和log目录有可读写权限 4:编辑配置文件 vi mo