创建配置服务器以部署分片群集时无法启动副本集

时间:2020-05-11 12:32:25

标签: mongodb mongodb-replica-set

我正在尝试在Mac的MongoDB中部署分片群集。我正在关注this页面。为了为分片群集创建配置服务器,我执行了以下步骤

mkdir -p /data/config/config-a /data/config/config-b /data/config/config-c
mongod --logpath "cfg-a.log" --dbpath /data/config/config-a --port 57040 --fork --configsvr --smallfiles
mongod --logpath "cfg-b.log" --dbpath /data/config/config-b --port 57041 --fork --configsvr --smallfiles
mongod --logpath "cfg-c.log" --dbpath /data/config/config-c --port 57042 --fork --configsvr --smallfiles

然后,我尝试启动副本集,如下所示

$ mongo --port 57040

> config = { _id : "cs", members : [{ _id:0, host:"localhost:57040"}, { _id:1, host: "localhost:57041"}, { _id:2, host:"localhost:57042"}]};
{
    "_id" : "cs",
    "members" : [
        {
            "_id" : 0,
            "host" : "localhost:57040"
        },
        {
            "_id" : 1,
            "host" : "localhost:57041"
        },
        {
            "_id" : 2,
            "host" : "localhost:57042"
        }
    ]
> rs.initiate(config)
{
    "ok" : 0,
    "errmsg" : "This node was not started with the replSet option",
    "code" : 76,
    "codeName" : "NoReplicationEnabled"
}

为什么会出现此错误?初始化其他副本集时没有出现任何错误,但是在此过程中出现了错误。有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

您正在遵循的指南已过时。 MongoDB文档具有tutorial that configures a sharded cluster。它同时提供--replSet--configsvr参数:

mongod --configsvr --replSet <replica set name> --dbpath <path> --bind_ip localhost,<hostname(s)|ip address(es)>