无法从外部replicaSet对mongo进行身份验证

时间:2015-04-01 08:45:49

标签: mongodb

我已经创建了一个新的ReplicaSet,如以下教程中所述:

http://docs.mongodb.org/manual/tutorial/deploy-replica-set/

http://docs.mongodb.org/manual/tutorial/deploy-replica-set-with-auth/

我的节点配置如下所示:

logpath=/var/log/mongodb/mongod.log
logappend=true
fork=true
dbpath=/home/mongo/data
pidfilepath=/var/run/mongodb/mongod.pid
auth=true
replSet=rs01
keyFile=/home/mongo/key/keyfile

ReplicaSet按预期工作:

rs01:PRIMARY> rs.status()
{
    "set" : "rs01",
    "date" : ISODate("2015-04-01T07:57:50.727Z"),
    "myState" : 1,
    "members" : [
            {
                    "_id" : 0,
                    "name" : "mongo04.mydomain.de:27017",
                    "health" : 1,
                    "state" : 2,
                    "stateStr" : "SECONDARY",
                    "uptime" : 495477,
                    "optime" : Timestamp(1427742130, 1),
                    "optimeDate" : ISODate("2015-03-30T19:02:10Z"),
                    "lastHeartbeat" : ISODate("2015-04-01T07:57:49.204Z"),
                    "lastHeartbeatRecv" : ISODate("2015-04-01T07:57:49.210Z"),
                    "pingMs" : 0,
                    "syncingTo" : "mongo03.mydomain.de:27017",
                    "configVersion" : 3
            },
            {
                    "_id" : 1,
                    "name" : "mongo02.mydomain.de:27017",
                    "health" : 1,
                    "state" : 2,
                    "stateStr" : "SECONDARY",
                    "uptime" : 500568,
                    "optime" : Timestamp(1427742130, 1),
                    "optimeDate" : ISODate("2015-03-30T19:02:10Z"),
                    "lastHeartbeat" : ISODate("2015-04-01T07:57:49.196Z"),
                    "lastHeartbeatRecv" : ISODate("2015-04-01T07:57:49.222Z"),
                    "pingMs" : 0,
                    "syncingTo" : "mongo03.mydomain.de:27017",
                    "configVersion" : 3
            },
            {
                    "_id" : 2,
                    "name" : "mongo03.mydomain.de:27017",
                    "health" : 1,
                    "state" : 1,
                    "stateStr" : "PRIMARY",
                    "uptime" : 501402,
                    "optime" : Timestamp(1427742130, 1),
                    "optimeDate" : ISODate("2015-03-30T19:02:10Z"),
                    "electionTime" : Timestamp(1427379457, 1),
                    "electionDate" : ISODate("2015-03-26T14:17:37Z"),
                    "configVersion" : 3,
                    "self" : true
            }
    ],
    "ok" : 1
}

我创建了一个新的数据库“testdb”,并添加了一个用户“test”,其中包含角色“readWrite”和“dbAdmin”。 我可以从ReplicatSet的任何节点连接到ReplicaSet中的任何节点:

[root@mongo04 ~]# mongo -u test -p --host mongo03.mydomain.de testdb
MongoDB shell version: 3.0.1
Enter password:
connecting to: mongo03.mydomain.de:27017/testdb
rs01:PRIMARY>

但我无法从ReplicaSet外的服务器连接:

[root@mongo01 ~]# mongo -u test -p --host mongo03.mydomain.de testdb
MongoDB shell version: 2.6.7
Enter password:
connecting to: mongo03.mydomain.de:27017/testdb
2015-04-01T10:12:30.958+0200 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed

我经常搜索,但我没有找到任何理由无法从副本集外的服务器进行连接。

有没有任何想法,我在配置中忘记或做错了什么?

0 个答案:

没有答案