mongodb 如何修改副本集配置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10953752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to modify replica set config?
提问by Saeed Akhtar
I have a mongo 2 node cluster running, with this replica set config.
我有一个 mongo 2 节点集群正在运行,并带有此副本集配置。
config = {_id: "repl1", members:[
{_id: 0, host: 'localhost:15000'},
{_id: 1, host: '192.168.2.100:15000'}]
}
I have to move these both nodes on to new servers. I have copied everything from old to new servers, but I'm running into issues while reconfiguring the replica config due to ip change on the 2nd node.
我必须将这两个节点移动到新服务器上。我已将所有内容从旧服务器复制到新服务器,但由于第二个节点上的 ip 更改,我在重新配置副本配置时遇到了问题。
I have tried this.
我试过这个。
config = {_id: "repl1", members:[
{_id: 0, host: 'localhost:15000'},
{_id: 1, host: '192.168.2.200:15000'}]
}
rs.reconfig(config)
{
"startupStatus" : 1,
"errmsg" : "loading local.system.replset config (LOADINGCONFIG)",
"ok" : 0
}
It shows above message, but change is not happening.
它显示了上面的消息,但没有发生变化。
I also tried changing replica set name but pointing to the same data dirs. I am getting the following error:
我也尝试更改副本集名称但指向相同的数据目录。我收到以下错误:
rs.initiate()
{
"errmsg" : "local.oplog.rs is not empty on the initiating member. cannot initiate.",
"ok" : 0
}
What are the right steps to change the IP but keeping the data on the 2nd node, or do i need to recreate/resync the 2nd node?
更改 IP 但将数据保留在第二个节点上的正确步骤是什么,或者我是否需要重新创建/重新同步第二个节点?
回答by Erhan A
Well , I had the same problem.
嗯,我有同样的问题。
I had to delete all replication and oplog.
我不得不删除所有复制和 oplog。
use local
db.dropDatabase()
restart your mongo with new set name
用新的集合名称重新启动你的 mongo
config = {_id: "repl1", members:[
{_id: 0, host: 'localhost:15000'},
{_id: 1, host: '192.168.2.100:15000'}]
}
rs.initiate(config)
I hope this works for you too
我希望这对你也有用
回答by Christian P
You can use force option when reconfiguring replica set:
您可以在重新配置副本集时使用 force 选项:
rs.reconfig(config, {force: true})
Note that, as Adam already suggested in the comments, you should have at least 3 nodes: 2 full nodes and 1 arbiter (minimum supported configuration) or 3 full nodes (minimum recommended configuration) so that primary node can be elected.
请注意,正如 Adam 在评论中已经建议的那样,您应该至少拥有 3 个节点:2 个完整节点和 1 个仲裁器(最低支持配置)或 3 个完整节点(最低推荐配置),以便可以选举主节点。
回答by Jim Rippon
I realise this is an old post, but I discovered I was getting this exact same error when trying to change the port used by secondaries in my replica set.
我意识到这是一篇旧帖子,但我发现在尝试更改副本集中辅助节点使用的端口时遇到了完全相同的错误。
In my case, I needed to stop the secondary whose config I was changing, and bring it up on its new address and port BEFORE applying the changed config on the Primary.
在我的情况下,我需要停止我正在更改其配置的辅助节点,并在将更改的配置应用于主节点之前将其启动到其新地址和端口上。
This is in the mongo documentation, but the order in which I had to bring things up and down was something I'd mis-read on the first pass, so for clarity I've repeated that here:
这是在 mongo 文档中,但是我必须上下移动的顺序是我在第一遍时误读的东西,所以为了清楚起见,我在这里重复了一遍:
- Shut down the secondary member of the replica set you are moving.
- Bring that secondary back up at its new address
- Make the configuration change as detailed in the original post above
- 关闭您正在移动的副本集的次要成员。
- 将该辅助备份到其新地址
- 按照上面原始帖子中的详细说明进行配置更改