Mongodb 副本集身份验证从 spring 引导失败
Mongodb replicaset authetication failing from spring boot
我有 3 个实例 mongodb 副本集,包括 3 个不同 ec2 实例中的 1 个仲裁器。从 mongo 控制台我可以连接到副本集。
但是当我尝试 build/deploy 我的 dockerized spring 在主 ec2 实例中启动应用程序时,它给出了以下异常
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数据mongo连接到副本集时使用的数据库属性
spring.data.mongodb.uri=mongodb://<usrName>:<password>@<host-primary>:27017,<host-secondary>:27017/<dbName>?<replicaset name>
spring.data.mongodb.auto-index-creation = true
当我尝试 build/deploy 使用以下属性时,即单节点连接,这是成功的
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
username
或 password
是否包含 @ 符号、冒号 :、斜线 / 或百分号 % 字符?
如果是,请检查您使用的编码是否正确。
也尝试像这样在 uri 中添加 authSource
:
?authSource=admin&replicaSet=myRepl
我有 3 个实例 mongodb 副本集,包括 3 个不同 ec2 实例中的 1 个仲裁器。从 mongo 控制台我可以连接到副本集。 但是当我尝试 build/deploy 我的 dockerized spring 在主 ec2 实例中启动应用程序时,它给出了以下异常
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数据mongo连接到副本集时使用的数据库属性
spring.data.mongodb.uri=mongodb://<usrName>:<password>@<host-primary>:27017,<host-secondary>:27017/<dbName>?<replicaset name>
spring.data.mongodb.auto-index-creation = true
当我尝试 build/deploy 使用以下属性时,即单节点连接,这是成功的
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
username
或 password
是否包含 @ 符号、冒号 :、斜线 / 或百分号 % 字符?
如果是,请检查您使用的编码是否正确。
也尝试像这样在 uri 中添加 authSource
:
?authSource=admin&replicaSet=myRepl