4
我正在將一個grails 3應用程序部署到活動服務器。已經在複製模式下設置了一個mongodb實例,並且從live box成功進行了測試。我測試了:如何爲mongodb複製組配置grails 3
mongo -u uname -authenticationDatabase dbname ip-1.ec2.internal:27017/dbname -p password
我已經使用了replicaSet
和connectionString
作爲指定here和here。但是在兩種情況下,它的行爲就好像沒有提供主機配置,因此默認爲localhost。而且由於沒有設置,它失敗了。這裏是application.groovy:
mongodb {
replicaSet = [ "ip-1.ec2.internal", "ip-12.ec2.internal", "ip-3.ec2.internal"]
host = "ip-1.ec2.internal" //This works for any of the hosts
port = 27017
username = "username"
password = "password"
databaseName = "dbname"
}
我使用的是最新版本:
grailsVersion=3.2.8 //It was the same for 3.2.5
gormVersion=6.0.9.RELEASE
gradleWrapperVersion=3.4.1 //It was the same for 3.0
這裏有插件與它們的版本列表:
compile 'org.grails.plugins:mongodb:6.1.0'
compile 'org.grails:grails-datastore-rest-client:6.0.9.RELEASE'
這是我遇到的錯誤:
01:22:26.410 - [localhost-startStop-1] INFO org.mongodb.driver.cluster - No server chosen by
ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE,
all=[ServerDescription{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException:
Exception authenticating MongoCredential{mechanism=null, userName='username', source='dbname', password=<hidden>,
mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18:
'Authentication failed.' on server 127.0.0.1:27017. The full response
is { "ok" : 0.0, "code" : 18, "errmsg" : "Authentication failed." }}}]}. Waiting for 30000 ms before timing out
我已經跑出了選擇現在,任何人都可以請點幫助我在這裏?謝謝。
這是文檔http://gorm.grails.org/latest/mongodb/manual/index.html#advancedConfig。我沒有看到能夠以這種方式指定副本集的任何內容。我認爲你只需要設置url字符串 –
@JamesKleeh謝謝,這很好。 – Godfred