mongodb副本集添加新的节点
2021/5/2 2:25:31
本文主要是介绍mongodb副本集添加新的节点,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
monodb副本集集群,能支撑多个secondary节点,一般刚开始可能部署少量一些节点,减轻成本费用,随着业务增加,会需要增加更多的节点,需要手动在上面添加新节点,那如何添加新节点呢?官方上有详细的文档说明,见:https://docs.mongodb.com/manual/tutorial/expand-replica-set/,这是域名在国外,有时候会打开比较慢,需要多点耐心去打开的。
Maximum Voting Members
A replica set can have a maximum of seven voting members. To add a member to a replica set that already has seven voting members, you must either add the member as a non-voting member or remove a vote from an existing member
.
一个副本集,最多可以拥有50个secondary,最多可以有7个投票成员,在副本集里面添加一个新成员,如果之前副本集已经有了7个成员,那么可以设置成非投票成员,或者你从移除之前一个投票成员出来。
Requirements¶
- An active replica set.
- A new MongoDB system capable of supporting your data set, accessible by the active replica set through the network.
添加之前,需要保障的是:
1、一个正在使用的副本集,一个新的MongoDB成员,网络互通。
2、保证新成员和老的成员有同样的数据目录、配置文件目录、日志目录等
Add a Member to an Existing Replica Set
操作步骤有大概以下:
1、启动一个新的mongod进程服务
Start the new mongod
instance. Specify the data directory and the replica set name. The following example specifies the /srv/mongodb/db0
data directory and the rs0
replica set:
mongod --dbpath /srv/mongodb/db0 --replSet rs0 --bind_ip localhost,<hostname(s)|ip address(es)> |
2、确认副本集的master,Connect to the replica set's primary.
You can only add members while connected to the primary. If you do not know which member is the primary, log into any member of the replica set and issue the db.isMaster()
command.
3、开始添加成员
Use rs.add()
to add the new member to the replica set. Pass the member configuration document
to the method. For example, to add a member at host mongodb3.example.net
, issue the following command:
rs.add( { host: "mongodb3.example.net:27017", priority: 0, votes: 0 } ) |
这里votes:0,就是没有投票特性,这一步耗时比较长,因为是从主库拉全量数据进行数据同步,所以需要注意对线上业务的影响
When a newly added secondary has its votes
and priority
settings greater than zero, during its initial sync, the secondary still counts as a voting member even though it cannot serve reads nor become primary because its data is not yet consistent.
This can lead to a case where a majority of the voting members are online but no primary can be elected. To avoid such situations, consider adding the new secondary initially with priority :0
and votes :0
. Then, once the member has transitioned into SECONDARY
state, use rs.reconfig()
to update its priority and votes.
4、查看新成员状态
Ensure that the new member has reached SECONDARY
state. To check the state of the replica set members, run rs.status()
:
rs.status() |
5、重置priority和votes属性
Once the newly added member has transitioned into SECONDARY
state, use rs.reconfig()
to update the newly added member's priority
and votes
if needed.
For example, if rs.conf()
returns the configuration document for mongodb3.example.net:27017
as the fifth element in the members
array, to update its priority and votes to 1
, use the following sequence of operations:
var cfg = rs.conf(); |
cfg.members[4].priority = 1 |
cfg.members[4].votes = 1 |
rs.reconfig(cfg) |
这篇关于mongodb副本集添加新的节点的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23MongoDB身份认证机制揭秘!
- 2024-11-20MongoDB教程:从入门到实践详解
- 2024-11-17执行 Google Ads API 查询后返回的是空数组什么原因?-icode9专业技术文章分享
- 2024-11-17google广告数据不同经理账户下的凭证可以获取对方的api数据吗?-icode9专业技术文章分享
- 2024-11-15SendGrid 的 Go 客户端库怎么实现同时向多个邮箱发送邮件?-icode9专业技术文章分享
- 2024-11-15SendGrid 的 Go 客户端库怎么设置header 和 标签tag 呢?-icode9专业技术文章分享
- 2024-11-12Cargo deny安装指路
- 2024-11-02MongoDB项目实战:从入门到初级应用
- 2024-11-01随时随地一键转录,Google Cloud 新模型 Chirp 2 让语音识别更上一层楼
- 2024-10-25Google Cloud动手实验详解:如何在Cloud Run上开发无服务器应用