Question

I'm trying to deploy sharded cluster in Mongodb

I followed up the tutorial here

http://docs.mongodb.org/manual/tutorial/convert-replica-set-to-replicated-shard-cluster/

first I deployed a Replica set with test data on a separate machine with IP 192.168.1.212

and this is the status after I finished deploying it

firstset:PRIMARY> rs.status();
{
    "set" : "firstset",
    "date" : ISODate("2014-03-24T10:54:06Z"),
    "myState" : 1,
    "members" : [
        {
            "_id" : 1,
            "name" : "localhost:10001",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 117,
            "optime" : Timestamp(1395650164, 10507),
            "optimeDate" : ISODate("2014-03-24T08:36:04Z"),
            "self" : true
        },
        {
            "_id" : 2,
            "name" : "localhost:10002",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 65,
            "optime" : Timestamp(1395650164, 10507),
            "optimeDate" : ISODate("2014-03-24T08:36:04Z"),
            "lastHeartbeat" : ISODate("2014-03-24T10:54:05Z"),
            "lastHeartbeatRecv" : ISODate("2014-03-24T10:54:05Z"),
            "pingMs" : 0,
            "lastHeartbeatMessage" : "syncing to: localhost:10001",
            "syncingTo" : "localhost:10001"
        },
        {
            "_id" : 3,
            "name" : "localhost:10003",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 51,
            "optime" : Timestamp(1395650164, 10507),
            "optimeDate" : ISODate("2014-03-24T08:36:04Z"),
            "lastHeartbeat" : ISODate("2014-03-24T10:54:05Z"),
            "lastHeartbeatRecv" : ISODate("2014-03-24T10:54:04Z"),
            "pingMs" : 0,
            "lastHeartbeatMessage" : "syncing to: localhost:10001",
            "syncingTo" : "localhost:10001"
        }
    ],
    "ok" : 1
}

Then I deployed three config server on separate machine then run mongos instance on another machine

Then I wanted to add Replica shard using the following command

sh.addShard("firstset/192.168.1.212:10001,192.168.1.212:10002,192.168.1.212:10003")

But I get the following error

mongos> sh.addShard('firstset/192.168.1.212:10001,192.168.1.212:10002,192.168.1.212:10003');
{
    "ok" : 0,
    "errmsg" : "couldn't connect to new shard ReplicaSetMonitor no master found for set: firstset"
}
Was it helpful?

Solution

I found the solution to this problem with Sammaye's help

the problem was that when replica set is initiated you should take care of the IPs you use because when the router will try to connect to the replica set, it reads its configuration file So if you use rs.initiate() with setting your configuration, the configuration will be like that

{
    "_id" : "firstset",
    "version" : 1,
    "members" : [
        {
            "_id" : 1,
            "host" : "localhost:10001"
        },
        {
            "_id" : 2,
            "host" : "localhost:10002"
        },
        {
            "_id" : 3,
            "host" : "localhost:10003"
        }
    ]
}

So the router will try to search at localhost to find the primary replica set but it won't find it because it is on other machine

If you use different machines for testing so initialize Replica set manually as following

rsconf ={
    "_id" : "firstset",
    "version" : 1,
    "members" : [
        {
            "_id" : 1,
            "host" : "machine_ip:machine_port"
        },
        {
            "_id" : 2,
            "host" : "machine_ip:machine_port"
        },
        {
            "_id" : 3,
            "host" : "machine_ip:machine_port"
        }
    ]
}
rs.initiate(rsconf);

Also if you use either “localhost” or “127.0.0.1” as the host identifier, then you must use “localhost” or “127.0.0.1” for all host settings for any MongoDB instances in the cluster. This applies to both the host argument to addShard and the value to the mongos --configdb run time option. If you mix localhost addresses with remote host address, MongoDB will produce errors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top