Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1987093
  • 博文数量: 176
  • 博客积分: 1857
  • 博客等级: 上尉
  • 技术积分: 2729
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-14 22:55
个人简介

吾生有涯,而知无涯,适当止学.循序渐进,步步提升 Talk is cheap, show me the code.

文章分类

全部博文(176)

文章存档

2019年(1)

2018年(14)

2017年(20)

2016年(31)

2015年(15)

2014年(5)

2013年(10)

2012年(80)

分类: NOSQL

2017-12-22 15:22:02

思路:
1.为了保证数据的一致性,必须先关闭应用的写服务。
2.提升要升级为Primary节点的Secondary节点的优先级。

操作如下:

点击(此处)折叠或打开

  1. arps:PRIMARY> config=rs.conf()                //查看当前配置,存入config变量中。
  2. arps:PRIMARY> config.members[2].priority =//修改config变量,第三组成员的优先级为3.
  3. arps:PRIMARY> rs.reconfig(config)             //配置生效                       
  4. ......
  5. ......
  6. 2017-12-22T15:19:56.596+0800 I NETWORK trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
  7. 2017-12-22T15:19:56.597+0800 I NETWORK reconnect 127.0.0.1:27017 (127.0.0.1) ok

  8. arps:SECONDARY> rs.conf()                    //查看当前配置
  9. {
  10.         "_id" : "arps",
  11.         "version" : 4,
  12.         "members" : [
  13.                 {
  14.                         "_id" : 0,
  15.                         "host" : "172.17.4.37:27017",
  16.                         "arbiterOnly" : false,
  17.                         "buildIndexes" : true,
  18.                         "hidden" : false,
  19.                         "priority" : 1,
  20.                         "tags" : {

  21.                         },
  22.                         "slaveDelay" : 0,
  23.                         "votes" : 1
  24.                 },
  25.                 {
  26.                         "_id" : 1,
  27.                         "host" : "172.17.4.38:27017",
  28.                         "arbiterOnly" : false,
  29.                         "buildIndexes" : true,
  30.                         "hidden" : false,
  31.                         "priority" : 1,
  32.                         "tags" : {

  33.                         },
  34.                         "slaveDelay" : 0,
  35.                         "votes" : 1
  36.                 },
  37.                 {
  38.                         "_id" : 2,
  39.                         "host" : "172.17.4.39:27017",
  40.                         "arbiterOnly" : false,
  41.                         "buildIndexes" : true,
  42.                         "hidden" : false,
  43.                         "priority" : 3,             //优先级变为3
  44.                         "tags" : {

  45.                         },
  46.                         "slaveDelay" : 0,
  47.                         "votes" : 1
  48.                 }
  49.         ],
  50.         "settings" : {
  51.                 "chainingAllowed" : true,
  52.                 "heartbeatTimeoutSecs" : 10,
  53.                 "getLastErrorModes" : {

  54.                 },
  55.                 "getLastErrorDefaults" : {
  56.                         "w" : 1,
  57.                         "wtimeout" : 0
  58.                 }
  59.         }
  60. }

  61. arps:SECONDARY> rs.status()
  62. {
  63.         "set" : "arps",
  64.         "date" : ISODate("2017-12-22T07:25:04.641Z"),
  65.         "myState" : 2,
  66.         "syncingTo" : "172.17.4.39:27017",
  67.         "members" : [
  68.                 {
  69.                         "_id" : 0,
  70.                         "name" : "172.17.4.37:27017",
  71.                         "health" : 1,
  72.                         "state" : 2,
  73.                         "stateStr" : "SECONDARY",
  74.                         "uptime" : 7597536,
  75.                         "optime" : Timestamp(1513927481, 3),
  76.                         "optimeDate" : ISODate("2017-12-22T07:24:41Z"),
  77.                         "syncingTo" : "172.17.4.39:27017",
  78.                         "configVersion" : 4,
  79.                         "self" : true
  80.                 },
  81.                 {
  82.                         "_id" : 1,
  83.                         "name" : "172.17.4.38:27017",
  84.                         "health" : 1,
  85.                         "state" : 2,
  86.                         "stateStr" : "SECONDARY",
  87.                         "uptime" : 7597426,
  88.                         "optime" : Timestamp(1513927481, 3),
  89.                         "optimeDate" : ISODate("2017-12-22T07:24:41Z"),
  90.                         "lastHeartbeat" : ISODate("2017-12-22T07:25:02.961Z"),
  91.                         "lastHeartbeatRecv" : ISODate("2017-12-22T07:25:04.091Z"),
  92.                         "pingMs" : 0,
  93.                         "syncingTo" : "172.17.4.39:27017",
  94.                         "configVersion" : 4
  95.                 },
  96.                 {
  97.                         "_id" : 2,
  98.                         "name" : "172.17.4.39:27017",
  99.                         "health" : 1,
  100.                         "state" : 1,
  101.                         "stateStr" : "PRIMARY",    //最后一个节点升级为PRIMARY
  102.                         "uptime" : 3202,
  103.                         "optime" : Timestamp(1513927481, 3),
  104.                         "optimeDate" : ISODate("2017-12-22T07:24:41Z"),
  105.                         "lastHeartbeat" : ISODate("2017-12-22T07:25:02.951Z"),
  106.                         "lastHeartbeatRecv" : ISODate("2017-12-22T07:25:04.344Z"),
  107.                         "pingMs" : 0,
  108.                         "electionTime" : Timestamp(1513927190, 2),
  109.                         "electionDate" : ISODate("2017-12-22T07:19:50Z"),
  110.                         "configVersion" : 4
  111.                 }
  112.         ],
  113.         "ok" : 1
  114. }


阅读(8370) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~