如果你的副本集一个次副本节点不需要保持数据了,但是为了选举主副本,需要把次副本转变成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 再用端口号If your application is connecting directly to the secondary,如果你的程序直接连接次副本 modify the application so that MongoDB queries don’t reach the secondary.修改程序以致以不能从这个次副本查询数据。比如改变读取策略 Shut down the secondary.停止次副本 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") 自己执行的代码 Verify that the replica set no longer includes the secondary by calling the rs.conf() method in themongo shell:验证这个副本集是否还包含这个节点 rs.conf() 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. 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 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 In the mongo shell convert the secondary to an arbiter using the rs.addArb() method: 增加arbiter节点 rs.addArb("<hostname><:port>") === rs.addArb("host2:27017") 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 NumberIf 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. Create a new, empty data directory to be used with the new port number. For example: mkdir /data/db-temp 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 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>") 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 Shut down the secondary. Remove the secondary from the replica set by calling the rs.remove() method in the mongo shell: rs.remove("<hostname><:port>") Verify that the replica set no longer includes the old secondary by calling the rs.conf() method in the mongo shell: rs.conf() 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.
|