18

我正在 linux 上配置一个 3 节点 mongodb 副本集。我正在使用以下配置

fork = true
bind_ip = 127.0.0.1
port = 27017
verbose = true
dbpath =  /opt/mongoDB/data/db
logpath = /opt/mongoDB/log/mongod.log
logappend = true
journal = true
replSet = rs1
keyFile = /opt/mongoDB/mongodb/bin/conf/keyfile

启动服务器。我启动了服务器,当我运行时使用 mongo 命令行工具连接到服务器。

rs.initiate()我得到

{
    "info2" : "no configuration explicitly specified -- making one",
    "me" : "host-ip:27017",
    "ok" : 0,
    "errmsg" : "couldn't initiate : can't find self in the replset config"
}

我尝试提供 cfginitiate()并仍然得到相同的错误。

这就是日志文件中显示的内容。

Mon Oct 14 13:27:33.218 [rsStart] replSet info no seed hosts were specified on the --replSet command line
Mon Oct 14 13:27:34.118 [conn1] run command admin.$cmd { replSetInitiate: { _id: "rs1", members: [ { _id: 0.0, host: "host-ip:27017" } ] } }
Mon Oct 14 13:27:34.118 [conn1] replSet replSetInitiate admin command received from client
Mon Oct 14 13:27:34.118 [conn1] replSet replSetInitiate config object parses ok, 1 members specified
Mon Oct 14 13:27:34.118 [conn1] getallIPs("host-ip"): [ip address]
Mon Oct 14 13:27:34.118 BackgroundJob starting: ConnectBG
Mon Oct 14 13:27:34.118 [conn1] User Assertion: 13279:can't find self in the replset config
Mon Oct 14 13:27:34.119 [conn1] replSet replSetInitiate exception: can't find self in the replset config
Mon Oct 14 13:27:34.119 [conn1] command admin.$cmd command: { replSetInitiate: { _id: "rs1", members: [ { _id: 0.0, host: "host-ip:27017" } ] } } ntoreturn:1 keyUpdates:0 locks(micros) W:230 reslen:107 1ms

我应该什么时候解决这个错误?

4

2 回答 2

23

我无法在 CentOS 机器上启动 MongoDB 副本集。

http://docs.mongodb.org/manual/tutorial/deploy-replica-set

mongodb replset

rs.initiate()


{
    "errmsg":"couldn't initiate : can't find self in the replset config on port 27011"
}

然后我只是使用 JSON 对象参数来rs.initiate(rsconfig)

var rsconfig = {"_id":"rs1","members":[{"_id":1,"host":"127.0.0.1:27011"}]}

然后 rs.add(..) 或一次全部

var rsconfig = {"_id":"rs1","members":[{"_id":1,"host":"127.0.0.1:27011"},{"_id":2,"host":"127.0.0.1:27012"},{"_id":3,"host":"127.0.0.1:27013"}]}

print(JSON.stringify(rsconfig))然后检查

rs.initiate(rsconfig)

几秒钟后检查

rs.status()

在此处输入图像描述

于 2013-11-12T08:52:39.203 回答
11

不要设置127.0.0.1bind_ip,改成bind_ip机器名或ip地址(如192.168.0.1)。

于 2013-10-15T02:46:09.963 回答