0

I had configured a mongodb replicaSet of 3 nodes. It was running fine But WHen i created a adminUser and dbuser on primary node and enabled the authorization in mongodb.conf file of all nodes then they are not connecting. Below is the output of rs.status() after enabling authorization. Kindly Help.

{
    "set" : "replset1",
    "date" : ISODate("2017-07-15T04:09:41.796Z"),
    "myState" : 3,
    "term" : NumberLong(1),
    "heartbeatIntervalMillis" : NumberLong(2000),
    "members" : [
        {
            "_id" : 1,
            "name" : "10.10.8.1:27017",
            "health" : 1,
            "state" : 3,
            "stateStr" : "RECOVERING",
            "uptime" : 54841,
            "optime" : {
                    "ts" : Timestamp(1500033801, 1),
                    "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2017-07-14T12:03:21Z"),
            "infoMessage" : "could not find member to sync from",
            "configVersion" : 1,
            "self" : true
        },
        {
            "_id" : 2,
            "name" : "10.10.8.2:27017",
            "health" : 0,
            "state" : 6,
            "stateStr" : "(not reachable/healthy)",
            "uptime" : 0,
            "optime" : {
                    "ts" : Timestamp(0, 0),
                    "t" : NumberLong(-1)
            },
            "optimeDate" : ISODate("1970-01-01T00:00:00Z"),
            "lastHeartbeat" : ISODate("2017-07-15T04:09:37.008Z"),
            "lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
            "pingMs" : NumberLong(0),
            "authenticated" : false,
            "configVersion" : -1
        },
        {
            "_id" : 3,
            "name" : "10.10.8.3:27017",
            "health" : 0,
            "state" : 6,
            "stateStr" : "(not reachable/healthy)",
            "uptime" : 0,
            "optime" : {
                    "ts" : Timestamp(0, 0),
                    "t" : NumberLong(-1)
            },
            "optimeDate" : ISODate("1970-01-01T00:00:00Z"),
            "lastHeartbeat" : ISODate("2017-07-15T04:09:37.136Z"),
            "lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
            "pingMs" : NumberLong(0),
            "authenticated" : false,
            "configVersion" : -1
        }
    ],
    "ok" : 1
}
0

You made things in wrong order. At start you have "open" replica set. You put authorization on and you have so called "localhost exception" what means that you (still) can connect primary directly without authorization. On that connection you MUST first create "root" (super user) user

use admin
db.createUser(
{
    user: "root",
    pwd: "toor",
    roles: [ "root" ]
})

Now, your "localhost exception" is gone! You must authenticate your self. You can logout and then login again OR just give command

db.auth("root","toor")

And start creating other (normal) users.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.