简体   繁体   中英

Cannot connect to my mongoDB replicaset

I create a replicaset rs0 on which I have:

mongo1.mydomain.com
mongo2.mydomain.com
mongo3.mydomain.com

Here is my rs.conf

rs0:PRIMARY> rs.conf()
{
        "_id" : "rs0",
        "version" : 3,
        "protocolVersion" : NumberLong(1),
        "members" : [
                {
                        "_id" : 0,
                        "host" : "mongo1.mydomain.com:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 1,
                        "host" : "mongo2.mydomain.com:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 2,
                        "host" : "mongo3.mydomain.com:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                }
        ],
        "settings" : {
                "chainingAllowed" : true,
                "heartbeatIntervalMillis" : 2000,
                "heartbeatTimeoutSecs" : 10,
                "electionTimeoutMillis" : 10000,
                "catchUpTimeoutMillis" : 60000,
                "getLastErrorModes" : {

                },
                "getLastErrorDefaults" : {
                        "w" : 1,
                        "wtimeout" : 0
                },
                "replicaSetId" : ObjectId("5a0ca4fe5e8a441fcd6aa77d")
        }
}

Currently mongo3 is primary (I shutted down mongo1 which was the primary then restarted it)

Then I have a DB myDB for which a user (with dash) has been created (with read and write rights):

rs0:PRIMARY> use myDB
switched to db myDB
rs0:PRIMARY> db.auth("my-server-user", "Test1234");
1
rs0:PRIMARY>

I now try to connect to my replicaset (all port are open for the moment to my servers) with URI but I get error:

MongoDB server version: 3.4.10
2017-11-15T22:13:01.241+0100 E QUERY    [thread1] Error: Authentication failed.
DB.prototype._authOrThrow@src/mongo/shell/db.js:1461:20
@(auth):6:1
@(auth):1:2
exception: login failed

To connect I use:

mongo "mongodb://mongo1.mydomain.com:27017,mongo2.mydomain.com:27017,mongo3.mydomain.com:27017/myDB?replicaSet=rs0" --authenticationDatabase admin --username my-server-user --password Test1234

Do you have an idea?

Thanks in advance

Ok found by removing:

--authenticationDatabase admin

I get:

mongo "mongodb://mongo1.mydomain.com:27017,mongo2.mydomain.com:27017,mongo3.mydomain.com:27017/myDB?replicaSet=rs0" --username my-server-user --password Test1234

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM