errmsg has data already, cannot initiate set

来源:互联网 发布:c语言软件 编辑:程序博客网 时间:2024/06/01 10:39
今天在做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 dbs2016-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 ~]# getenforceDisabled[root@A ~]# iptables -nvLChain 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:67Chain 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-unreachableChain OUTPUT (policy ACCEPT 3499 packets, 375K bytes)pkts bytes target     prot opt in     out     source               destination         [root@A ~]# iptables -F[root@A ~]# service iptables saveiptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ][root@A ~]# service iptables stopiptables: 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}



好了,遇到问题不要着急,先静下心来,保持平静,一步一步的查。肯定有解决的时候。加油。
0 0
原创粉丝点击