errmsg has data already, cannot initiate set

今天在做mongoDB主从的时候,遇到了"has data already, cannot initiate set"的问题,正好看到之前有人也遇到这个问题,老师回答说是要把从的数据全部清空,结果我在从上清空,也会报错。(:<(, woops)
主上初始化的时候提示信息如下:
> rs.initiate(config)
{
    "ok" : 0,
    "errmsg" : "'192.168.3.220:27017' has data already, cannot initiate set.",
    "code" : 110
}

从上清空数据报错信息如下:
> db.dropDatabase()
{ "note" : "from execCommand", "ok" : 0, "errmsg" : "<span style="color:#CC0000;"><strong>not master</strong></span>" } ## CAUTION: 已经配置主从了,赶紧把主从配置取消掉,怀疑就是主从配置导致数据无法正常清空。
>
> show dbs
2016-04-25T22:18:50.226+0800 E QUERY    Error: listDatabases failed:{ "note" : "from execCommand", "ok" : 0, "errmsg" : "not master" }
    at Error (<anonymous>)
    at Mongo.getDBs (src/mongo/shell/mongo.js:47:15)
    at shellHelper.show (src/mongo/shell/utils.js:630:33)
    at shellHelper (src/mongo/shell/utils.js:524:36)
    at (shellhelp2):1:1 at src/mongo/shell/mongo.js:47

排错步骤:
1、把从配置文件主从配置去掉
2、重启服务
3、在从上执行db.dropDatabase(),清空所有的数据库,一个也不要留,直到show dbs为空
4、主上初始化,执行rs.initiate(config),这个时候又开悲摧了,
holy shit!!!!! ^__^

> rs.initiate(config)
{
    "ok" : 0,
    "errmsg" : "replSetInitiate quorum check failed because not all proposed set members responded affirmatively: 192.168.3.221:27017 failed with Failed attempt to connect to 192.168.3.221:27017; couldn't connect to server 192.168.3.221:27017 (192.168.3.221), connection attempt failed",
    "code" : 74
}

"errmsg" : "replSetInitiate quorum check failed because not all proposed set members responded affirmatively: ##这里说是不是所有的成员都已经果断的响应,我英文不怎么样就直译了,离成功不远了,再去从上找问题。


a、查看selinux是关闭的,这个先排除
b、iptables -nvL, wps, 天呐,这么多防火墙规则,关了它。
[root@A ~]# getenforce
Disabled
[root@A ~]# iptables -nvL
Chain INPUT (policy ACCEPT 3058 packets, 344K bytes)
pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     udp  --  virbr0 *       0.0.0.0/0            0.0.0.0/0           udp dpt:53
    0     0 ACCEPT     tcp  --  virbr0 *       0.0.0.0/0            0.0.0.0/0           tcp dpt:53
    0     0 ACCEPT     udp  --  virbr0 *       0.0.0.0/0            0.0.0.0/0           udp dpt:67
    0     0 ACCEPT     tcp  --  virbr0 *       0.0.0.0/0            0.0.0.0/0           tcp dpt:67

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  *      virbr0  0.0.0.0/0            192.168.122.0/24    state RELATED,ESTABLISHED
    0     0 ACCEPT     all  --  virbr0 *       192.168.122.0/24     0.0.0.0/0           
    0     0 ACCEPT     all  --  virbr0 virbr0  0.0.0.0/0            0.0.0.0/0           
    0     0 REJECT     all  --  *      virbr0  0.0.0.0/0            0.0.0.0/0           reject-with icmp-port-unreachable
    0     0 REJECT     all  --  virbr0 *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-port-unreachable

Chain OUTPUT (policy ACCEPT 3499 packets, 375K bytes)
pkts bytes target     prot opt in     out     source               destination         
[root@A ~]# iptables -F
[root@A ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[root@A ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: nat mangle filte[  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]

c、重新启动mongod服务

d、在主上继续执行初始化命令,成功了。

> rs.initiate(config)
{ "ok" : 1 }
changfeng:OTHER> rs.status()
{
	"set" : "changfeng",
	"date" : ISODate("2016-04-25T15:20:32.062Z"),
	"myState" : 1,
	"members" : [
		{
			"_id" : 0,
			"name" : "192.168.3.219:27017",
			"health" : 1,
			"state" : 1,
			"stateStr" : "<span style="color:#FF0000;">PRIMARY</span>",
			"uptime" : 3263,
			"optime" : Timestamp(1461596226, 1),
			"optimeDate" : ISODate("2016-04-25T14:57:06Z"),
			"electionTime" : Timestamp(1461596228, 1),
			"electionDate" : ISODate("2016-04-25T14:57:08Z"),
			"configVersion" : 1,
			"self" : true
		},
		{
			"_id" : 1,
			"name" : "192.168.3.220:27017",
			"health" : 1,
			"state" : 2,
			"stateStr" : "<span style="color:#FF0000;">SECONDARY</span>",
			"uptime" : 1405,
			"optime" : Timestamp(1461596226, 1),
			"optimeDate" : ISODate("2016-04-25T14:57:06Z"),
			"lastHeartbeat" : ISODate("2016-04-25T15:20:30.162Z"),
			"lastHeartbeatRecv" : ISODate("2016-04-25T15:20:30.168Z"),
			"pingMs" : 0,
			"configVersion" : 1
		},
		{
			"_id" : 2,
			"name" : "192.168.3.221:27017",
			"health" : 1,
			"state" : 2,
			"stateStr" : "<span style="color:#FF0000;">SECONDARY</span>",
			"uptime" : 1405,
			"optime" : Timestamp(1461596226, 1),
			"optimeDate" : ISODate("2016-04-25T14:57:06Z"),
			"lastHeartbeat" : ISODate("2016-04-25T15:20:31.037Z"),
			"lastHeartbeatRecv" : ISODate("2016-04-25T15:20:31.044Z"),
			"pingMs" : 0,
			"configVersion" : 1
		}
	],
	"ok" : 1
}



好了,遇到问题不要着急,先静下心来,保持平静,一步一步的查。肯定有解决的时候。加油。
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值