我想從SERVER-1連接到我在其他服務器上運行的mongo服務器SERVER-2 所以我的grails應用程序在SERVER-1中運行。所以我給了這樣的外部配置。MongoDB用戶認證問題
grails {
mongo {
host = "<SERVER-2>-host"
port = 27017
username = "myapp"
password = "myapp"
databaseName = "myapp"
options {
autoConnectRetry = true
connectTimeout = 3000
}
}
}
以及服務器-2我創建的myapp數據庫,並使用相同的用戶和憑據
use myapp
db.createUser({ "user" : "myapp",
"pwd": "myapp",
"roles" : [] },
{ w: "majority" , wtimeout: 5000 })
和我能看到用戶列表如下圖所示
> db.getUsers()
[
{
"_id" : "myapp.myapp",
"user" : "myapp",
"db" : "myapp",
"roles" : [ ]
}
]
Mongo配置包含「noauth = true」, 並且從SERVER-1,我可以使用以下命令連接到SERVER-2 mongo
mongo SERVER-2-HOST:27017/myapp -u myapp -p myapp
但是,當我試圖從SERVER-1 Grails應用程序連接,它給下面的錯誤
| Error Error executing script LoadVars: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'mongoTransactionManager' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mongodb.CannotGetMongoDbConnectionException: Failed to authenticate to database [myapp], username = [myapp], password = [m***p]
我mongod.conf文件
# mongod.conf
logpath=/var/log/mongodb/mongod.log
logappend=true
fork=true
#port=27017
dbpath=/var/lib/mongo
pidfilepath=/var/run/mongodb/mongod.pid
# Listen to local interface only. Comment out to listen on all interfaces.
#bind_ip=127.0.0.1
# nojournal=true
#cpu=true
#noauth=false
auth=true
我在這裏缺少什麼?
你在使用MongoDB 3和Grails 2.4.x或2.5.x嗎? –
如果是,請參閱我的更新答案。這一定是你的問題。 –