2017-04-06 35 views
4

我正在将一个grails 3应用程序部署到活动服务器。已经在复制模式下设置了一个mongodb实例,并且从live box成功进行了测试。我测试了:如何为mongodb复制组配置grails 3

mongo -u uname -authenticationDatabase dbname ip-1.ec2.internal:27017/dbname -p password 

我已经使用了replicaSetconnectionString作为指定herehere。但是在两种情况下,它的行为就好像没有提供主机配置,因此默认为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 

我已经跑出了选择现在,任何人都可以请点帮助我在这里?谢谢。

+0

这是文档http://gorm.grails.org/latest/mongodb/manual/index.html#advancedConfig。我没有看到能够以这种方式指定副本集的任何内容。我认为你只需要设置url字符串 –

+0

@JamesKleeh谢谢,这很好。 – Godfred

回答

2

James Kleeh建议的connection strings解决了这个问题。这是我参照使用从这个example

mongodb { 
    url = "mongodb://ip-1.ec2.internal,ip-2.ec2.internal,ip-3.ec2.internal/?replicaSet=hostname-of-mongod-instance" 
    port = 27017 
    ... 
}