从 mongodb 中的副本配置重新开始
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13603096/
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
Starting over with replica configuration in mongodb
提问by obeq
I did a mistake when configuring replica sets in mongodb. I think that what I did wrong is that I did a rs.initialize() on both nodes, which made them confused in some way. I'm not sure.
我在mongodb中配置副本集时出错了。我认为我做错的是我在两个节点上都做了一个 rs.initialize() ,这让他们在某种程度上感到困惑。我不知道。
Now all I want to do is start over, but I couldn't find a way to de-initialize a node. So I followed the advice to delete the local* db files, thus resetting the configurations. I did that, and now nothing works.
现在我想做的就是重新开始,但我找不到取消初始化节点的方法。所以我按照建议删除了本地* db 文件,从而重置了配置。我这样做了,现在没有任何效果。
> rs.initiate()
{
"info2" : "no configuration explicitly specified -- making one",
"me" : "0.0.0.0:27017",
"errmsg" : "couldn't initiate : can't find self in the replset config",
"ok" : 0
}
> rs.conf()
null
I tried to remove and reinstall the package (I'm doing this on Ubuntu servers) which just meant that my mongodb.conf disappeared and my init script stopped working. This is of course easy enough to solve.
我试图删除并重新安装这个包(我在 Ubuntu 服务器上这样做)这只是意味着我的 mongodb.conf 消失了,我的 init 脚本停止工作。这当然很容易解决。
So how do I start over?
那么我该如何重新开始呢?
Note: I did look at this answer, but since rs.conf() doesn't work this doesn't work either.
注意:我确实看过这个答案,但由于 rs.conf() 不起作用,这也不起作用。
回答by rbrc
You'll also get this error if your machine's hostname doesn't map back to 127.0.0.1. Update your /etc/hosts and/or your /etc/hostname, and rs.initiate() with no config should work.
如果您机器的主机名没有映射回 127.0.0.1,您也会收到此错误。更新您的 /etc/hosts 和/或您的 /etc/hostname,并且没有配置的 rs.initiate() 应该可以工作。
回答by Andre de Frere
If you force a reconfig with a config that you have generated, does it resolve the issue?
如果您使用已生成的配置强制重新配置,是否可以解决问题?
You could do this similar to the follow from the {{mongo}} shell:
您可以执行类似于 {{mongo}} shell 中的以下操作:
> cfg = {
... "_id" : "rs0",
... "version" : 1,
... "members" : [
... {
... "_id" : 0,
... "host" : "0.0.0.0:27017"
... }
... ]
... }
>rs.reconfig(cfg, {force:true})
You may need to tune the cfg
variable to have your hostname and portname, as the can't find self in new replset config
error will be returned to the shell if the repl set can't find the node it is running from in the config.
您可能需要调整cfg
变量以获得您的主机名和端口名,因为can't find self in new replset config
如果 repl 集在配置中找不到它正在运行的节点,则错误将返回到 shell。
回答by occasl
If you just comment out bind_ip
in /etc/mongod.conf
this will achieve the correct result so that you can reissue a rs.initiate()
command to set-up or reconfig the replica.
如果您只是bind_ip
在/etc/mongod.conf
此注释掉将获得正确的结果,以便您可以重新发出rs.initiate()
命令来设置或重新配置副本。