【发布时间】:2017-09-01 11:50:11
【问题描述】:
我正在将 grails 3 应用程序部署到实时服务器。一个 mongodb 实例已设置为复制模式,并在 live box 中成功测试。我测试过:
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
我现在已经用完了选项,有人可以在这里指点帮助我吗?谢谢。
【问题讨论】:
-
这是文档gorm.grails.org/latest/mongodb/manual/index.html#advancedConfig。我看不到任何关于能够以这种方式指定副本集的信息。我想你只需要设置 url 字符串
-
@JamesKleeh 谢谢,效果很好。
标签: mongodb grails database-replication