Convert转变a Secondary to an Arbiter
cookqq ›博客列表 ›MongoDB

Convert转变a Secondary to an Arbiter

2015-12-08 15:37:32.0|分类: MongoDB|浏览量: 2470

摘要: 如果你的副本集一个次副本节点不需要保持数据了,但是为了选举主副本,需要把次副本转变成arbiter 1、修改程序以致以不能从这个次副本查询数据。比如改变读取策略 2、停止次副本 3、在主副本中执行rs.remove("<:port>") 4 mv mongodb mongodb-old 5 mkdir mongodb 6 mongod --port 27021 --dbpath /data/db --replSet rs 7 rs.addArb("host2:27017") 8 验证rs.conf()

如果你的副本集一个次副本节点不需要保持数据了,但是为了选举主副本,需要把次副本转变成arbiter

  • 1、修改程序以致以不能从这个次副本查询数据。比如改变读取策略

  • 2、停止次副本

  • 3、在主副本中执行rs.remove("<hostname><:port>")

  • 4 mv mongodb mongodb-old

  • 5  mkdir mongodb

  • 6 mongod --port 27021 --dbpath /data/db --replSet rs

  • 7 rs.addArb("host2:27017")

  • 8 验证rs.conf()



  • You may operate the arbiter on the same port as the former secondary. In this procedure程序, you must shut down the secondary 停止这个次副本 and remove its data 重启前删除数据 before restarting and reconfiguring it as an arbiter 配置成arbiter .

    For this procedure, see Convert Secondary to Arbiter and Reuse the Port Number.

  • Run the arbiter on a new port. In this procedure, you can reconfigure the server as an arbiter before shutting down the instance running as a secondary.

    For this procedure, see Convert Secondary to Arbiter Running on a New Port Number.

Convert Secondary to Arbiter and Reuse the Port Number  Secondary转变成Arbiter 再用端口号

  1. If your application is connecting directly to the secondary,如果你的程序直接连接次副本 modify the application so that MongoDB queries don’t reach the secondary.修改程序以致以不能从这个次副本查询数据。比如改变读取策略

  2. Shut down the secondary.停止次副本

  3. Remove the secondary from the replica set by calling the rs.remove() method. Perform this operation while connected to the current primary in the mongo shell:在主副本中执行rs.remove()

    rs.remove("<hostname><:port>")   官网代码   == rs.remove("host2:27017") 自己执行的代码
  4. Verify that the replica set no longer includes the secondary by calling the rs.conf() method in themongo shell:验证这个副本集是否还包含这个节点

    rs.conf()
  5. Move the secondary’s data directory to an archive folder. For example: 移除这个mongodb老的数据文件

    mv /data/db /data/db-old  官网代码 === mv mongodb mongodb-old 自己执行的代码

    OPTIONAL

    You may remove the data instead.

  6. Create a new, empty data directory to point to when restarting the mongod instance. You can reuse the previous name. For example: 创建写的数据文件

    mkdir /data/db ==   mkdir mongodb
  7. Restart the mongod instance for the secondary, specifying the port number, the empty data directory, and the replica set. You can use the same port number you used before. Issue a command similar to the following: 重启这个节点的mongo进程

    mongod --port 27021 --dbpath /data/db --replSet rs
  8. In the mongo shell convert the secondary to an arbiter using the rs.addArb() method: 增加arbiter节点

    rs.addArb("<hostname><:port>")  === rs.addArb("host2:27017")
  9. Verify the arbiter belongs to the replica set by calling the rs.conf() method in the mongo shell.:验证这个副本集是否还包含这个arbiter节点

    rs.conf()

    The arbiter member should include the following:

    "arbiterOnly" : true

Convert Secondary to Arbiter Running on a New Port Number

  1. If your application is connecting directly to the secondary or has a connection string referencing the secondary, modify the application so that MongoDB queries don’t reach the secondary.

  2. Create a new, empty data directory to be used with the new port number. For example:

    mkdir /data/db-temp
  3. Start a new mongod instance on the new port number, specifying the new data directory and the existing replica set. Issue a command similar to the following:

    mongod --port 27021 --dbpath /data/db-temp --replSet rs
  4. In the mongo shell connected to the current primary, convert the new mongod instance to an arbiter using the rs.addArb() method:

    rs.addArb("<hostname><:port>")
  5. Verify the arbiter has been added to the replica set by calling the rs.conf() method in the mongoshell.

    rs.conf()

    The arbiter member should include the following:

    "arbiterOnly" : true
  6. Shut down the secondary.

  7. Remove the secondary from the replica set by calling the rs.remove() method in the mongo shell:

    rs.remove("<hostname><:port>")
  8. Verify that the replica set no longer includes the old secondary by calling the rs.conf() method in the mongo shell:

    rs.conf()
  9. Move the secondary’s data directory to an archive folder. For example:

    mv /data/db /data/db-old

    OPTIONAL

    You may remove the data instead.



一键分享文章

分类列表

  • • struts源码分析
  • • flink
  • • struts
  • • redis
  • • kafka
  • • ubuntu
  • • zookeeper
  • • hadoop
  • • activiti
  • • linux
  • • 成长
  • • NIO
  • • 关键词提取
  • • mysql
  • • android studio
  • • zabbix
  • • 云计算
  • • mahout
  • • jmeter
  • • hive
  • • ActiveMQ
  • • lucene
  • • MongoDB
  • • netty
  • • flume
  • • 我遇到的问题
  • • GRUB
  • • nginx
  • • 大家好的文章
  • • android
  • • tomcat
  • • Python
  • • luke
  • • android源码编译
  • • 安全
  • • MPAndroidChart
  • • swing
  • • POI
  • • powerdesigner
  • • jquery
  • • html
  • • java
  • • eclipse
  • • shell
  • • jvm
  • • highcharts
  • • 设计模式
  • • 列式数据库
  • • spring cloud
  • • docker+node.js+zookeeper构建微服务
版权所有 cookqq 感谢访问 支持开源 京ICP备15030920号
CopyRight 2015-2018 cookqq.com All Right Reserved.