MongoDB rs.initiate()返回错误

时间:2017-07-26 14:37:46

标签: mongodb ubuntu

我在Ubuntu 16.04 LTS上运行MongoDB 3.2.15

我无法执行rs.initiate();。它返回以下错误

{
  "ok" : 0,
  "errmsg" : "assertion src/mongo/db/repl/replset_commands.cpp:275",
  "code" : 8
}

使用以下参数打开mongo

mongod --config /etc/mongod.conf --replSet rs0

配置文件:

storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
net:
  port: 27017
  bindIp: 0.0.0.0

日志文件:

2017-07-26T08:25:38.400+0000 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2017-07-26T08:25:42.186+0000 I COMMAND  [conn1] initiate : no configuration specified. Using a default configuration for the set
2017-07-26T08:25:42.186+0000 I -        [conn1] Assertion failure h != "localhost" src/mongo/db/repl/replset_commands.cpp 275

1 个答案:

答案 0 :(得分:1)

试试这个(我的成功):

mongo
> config = {_id:"rs0", members:[ {_id:0, host:"127.0.0.1:27017"}]}
{
    "_id" : "rs0",
    "members" : [
        {
            "_id" : 0,
            "host" : "127.0.0.1:27017"
        }
    ]
}
> rs.initiate(config)
{ "ok" : 1 }

参考:http://blog.csdn.net/Aegeaner/article/details/56277129