我已经接管了无证件的Mongo 4.4.8集群(PSA)。我正试着把它整理一下,然后好好地测试一下。
原始连接字符串:
MONGODB_URI=mongodb://${USER}:${PASS}@10.0.0.3:27017,10.0.0.6:27017,10.0.0.2:27017/bud?replicaSet=bud-replica&authSource=admin我已经启用了本地主机和套接字连接。我可以从cmdline登录
mongo -u ${USER} -p ${PASS}
MongoDB shell version v4.4.8
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("492e331b-417e-458a-83c7-9db6eaae0869") }
MongoDB server version: 4.4.8我可以将db切换到bud并执行查询。但如果我只是
mongo然后具有相同凭据的身份验证无效:
bud-replica:PRIMARY> db.auth('admin','admin');
Error: Authentication failed.
0我试图搜索用户,但没有显示:
bud-replica:PRIMARY> db.getUsers()
[ ]
bud-replica:PRIMARY> use bud
switched to db bud
bud-replica:PRIMARY> db.getUsers()
[ ]这是mongod.conf安全部分:
security:
authorization: enabled
keyFile: "/etc/bud-rs"最后,我需要在做实验之前导出我的数据。尽管cmd行接口看起来类似,但是mongoexport不能获取数据,不管我设置了user/password还是跳过了这些参数。
mongoexport -h localhost --db=bud -u ${USER} -p ${PASS} -c=accidents --jsonArray > accidents.json
2021-08-25T19:30:30.631+0200 could not connect to server: connection() error occured during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
mongoexport -h localhost --db=bud -u ${USER} -p ${PASS} -c=accidents --jsonArray --authenticationDatabase “admin” > accidents.json
2021-08-25T19:36:18.738+0200 could not connect to server: connection() error occured during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
root@10:~# mongoexport -h localhost --db=bud -u ${USER} -p ${PASS} -c=accidents --jsonArray --authenticationDatabase “bud” > accidents.json
2021-08-25T19:38:21.174+0200 could not connect to server: connection() error occured during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.我真的很困惑,也没能在Google上找到解决方案。
第二个相关问题:
如果我需要创建新用户,我应该在所有的副本上这样做,还是它是自动同步的?
第一次更新
这是解决办法,但我的问题仍然有效。我想要理解。
root@10:~# mongoexport --db=bud -u ${USER} -p ${PASS} -c=accidents --jsonArray "mongodb://admin:admin@10.0.0.3:27017/bud?authSource=admin" > accidents.json
2021-08-25T20:46:54.777+0200 connected to: mongodb://[**REDACTED**]@10.0.0.3:27017/bud?authSource=admin
2021-08-25T20:46:55.778+0200 [........................] bud.accidents 0/4379 (0.0%)
2021-08-25T20:46:56.497+0200 [########################] bud.accidents 4379/4379 (100.0%)
2021-08-25T20:46:56.497+0200 exported 4379 records第二次更新
bud-replica:PRIMARY> use admin
bud-replica:PRIMARY> show collections
system.keys
system.users
system.version
bud-replica:PRIMARY> db.system.users.find()
{ "_id" : "admin.admin", "userId" : UUID("769e4f5c-6f46-4153-857e-47d7d8730066"), "user" : "admin", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "32/AP4019eome36j8n发布于 2021-08-26 11:19:46
在管理数据库中创建了用户凭据。
连接芒果壳时,在运行use admin之前使用db.auth进行切换
工作的mongoexport命令在连接字符串中使用了authSource=admin。
将--authenticationDatabase=admin添加到另一个命令行,以指导它也使用admin数据库。
发布于 2022-09-10 11:37:17
如下所示的整个示例命令都适用于我。
Mongodb版本: 5.x.x,也适用于Mongodb版本: 8.x.x
mongodump --authenticationDatabase=admin --uri mongodb://username:password@mongodb-host/db-name?ssl=false&authSource=adminhttps://stackoverflow.com/questions/68927857
复制相似问题