如何为 mongodb 副本集配置 grails 3
How to configure grails 3 for mongodb replicaset
我正在将 grails 3 应用程序部署到实时服务器。一个 mongodb 实例已在复制模式下设置,并已从现场盒子成功测试。我测试了:
mongo -u uname -authenticationDatabase dbname ip-1.ec2.internal:27017/dbname -p password
我使用了 replicaSet
和 connectionString
指定的 here and 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
我现在 运行 没有选择,任何人都可以在这里帮助我吗?谢谢。
connection strings as suggested by James Kleeh solved the issue. This is how I used it with reference from this example:
mongodb {
url = "mongodb://ip-1.ec2.internal,ip-2.ec2.internal,ip-3.ec2.internal/?replicaSet=hostname-of-mongod-instance"
port = 27017
...
}
我正在将 grails 3 应用程序部署到实时服务器。一个 mongodb 实例已在复制模式下设置,并已从现场盒子成功测试。我测试了:
mongo -u uname -authenticationDatabase dbname ip-1.ec2.internal:27017/dbname -p password
我使用了 replicaSet
和 connectionString
指定的 here and 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
我现在 运行 没有选择,任何人都可以在这里帮助我吗?谢谢。
connection strings as suggested by James Kleeh solved the issue. This is how I used it with reference from this example:
mongodb {
url = "mongodb://ip-1.ec2.internal,ip-2.ec2.internal,ip-3.ec2.internal/?replicaSet=hostname-of-mongod-instance"
port = 27017
...
}