设置一个成员 MongoDB 副本集

Setup one member MongoDB replica set

我想 convert a standalone machine into one member replica set 通过在 /etc/init.d/mongodb.

中配置相同的内容

我遇到了执行相同操作的以下命令:

sudo mongod --port 27017 --dbpath /srv/mongodb/db0 --replSet rs0

但是没有成功。我的 mongo 在自动启动时配置为 运行。 我 运行 以下命令在 运行 --replSet 选项之前停止 运行ning 实例。

sudo service mongod stop

上面的两个命令 运行 都没有任何 output/error 但是当我 运行 rs.initiate() 时,我得到以下错误:

{
    "ok" : 0,
    "errmsg" : "not authorized on admin to execute command { replSetInitiate: undefined }",
    "code" : 13
}

从错误消息来看,问题似乎是可以访问的。谁能指点一下?

此外,如果我成功执行上述命令,我是否需要对 /etc/mongod.conf 或 /etc/init.d/mongodb 进行任何更改,以便实例继续 运行作为单节点副本?

首先:设置mongod进程的配置有两种方式;或者(如在您找到的命令中)作为命令行参数, 或配置文件 mongod.conf 中的 。您的设置似乎正在使用配置文件,因此您需要在命令行上put the replica set settings in the mongod.conf file而不是

其次:在 authentication is enabled, as yours is, you must be authenticated as a user who has permission to run this command

的系统上 运行 rs.initiate() 命令