首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >spring启动导致Mongodb副本集身份验证失败

spring启动导致Mongodb副本集身份验证失败
EN

Stack Overflow用户
提问于 2020-09-27 22:52:39
回答 1查看 585关注 0票数 0

我有3个实例mongodb副本集,包括3个不同ec2实例中的1个仲裁器。从mongo控制台,我可以连接到副本集。但是,当我尝试在主ec2实例中构建/部署我的停靠的spring boot应用程序时,它给出了以下异常

代码语言:javascript
复制
Caused by: org.springframework.data.mongodb.UncategorizedMongoDbException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='<usrName>', source='<source>', password=<hidden>, mechanismProperties=<hidden>}; nested exception is com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='<usrName>', source='<source>', password=<hidden>, mechanismProperties=<hidden>}
Caused by: com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='<usrName>', source='<source>', password=<hidden>, mechanismProperties=<hidden>}
Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server <Primary-Host>:27017. The full response is {"operationTime": {"$timestamp": {"t": 1601217500, "i": 1}}, "ok": 0.0, "errmsg": "Authentication failed.", "code": 18, "codeName": "AuthenticationFailed", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1601217500, "i": 1}}, "signature": {"hash": {"$binary": {"base64": "KSwBAZHnhcqmjdsAy9HHVB8+yZQ=", "subType": "00"}}, "keyId": 6876114453302083588}}}

连接到副本集时使用的Spring data mongodb属性

代码语言:javascript
复制
spring.data.mongodb.uri=mongodb://<usrName>:<password>@<host-primary>:27017,<host-secondary>:27017/<dbName>?<replicaset name>
spring.data.mongodb.auto-index-creation = true

当我尝试使用以下属性(即单节点连接)构建/部署时,这是成功的

代码语言:javascript
复制
spring.data.mongodb.host=<Primary-Host>
spring.data.mongodb.port=27017
spring.data.mongodb.database=<database name>
spring.data.mongodb.authentication-database=admin
spring.data.mongodb.username=<user name>
spring.data.mongodb.password=<password>
spring.data.mongodb.auto-index-creation = true
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-27 23:23:02

usernamepassword是否包含at符号@、冒号:、斜杠/或百分号%字符?

如果是,请检查您是否使用了正确的编码。

还可以尝试像这样在uri中添加authSource

?authSource=admin&replicaSet=myRepl

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64089783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档