我添加了一个角色为
的用户["readWrite","dbAdmin","clusterAdmin", "readWriteAnyDatabase", "dbAdminAnyDatabase"]
但是当我登录mongodb并执行db.repairDatabase()
时,我收到错误:
{ "ok" : 0, "errmsg" : "unauthorized"}.
一开始,我刚刚添加了角色readWrite
和dbAdmin
,并添加了越来越多的角色,但遇到了这个错误。
我读了https://docs.mongodb.org/manual/reference/built-in-roles/#built-in-roles,看来我们有dbAdmin角色时可以使用repairDatabase
。但这似乎不起作用。有人可以帮我解决这个问题吗?如果您想了解更多信息,请告诉我。
这是我的测试脚本:
CONTROLLER_IP=myip
DB_PWD='password'
openstack-config --set /etc/mongodb.conf '' auth false
systemctl restart mongod
mongo --host ${CONTROLLER_IP} --eval 'db = db.getSiblingDB("admin");db.removeUser("admin")'
mongo --host ${CONTROLLER_IP} --eval 'db = db.getSiblingDB("ceilometer");db.removeUser("ceilometer")'
systemctl restart mongod
mongo --host ${CONTROLLER_IP} --eval 'db = db.getSiblingDB("admin");db.addUser({user: "admin",pwd: "'${DB_PWD}'",roles: [ "readWrite","dbAdmin","clusterAdmin","readWriteAnyDatabase", "dbAdminAnyDatabase"]})'
mongo --host ${CONTROLLER_IP} --eval 'db = db.getSiblingDB("ceilometer");db.addUser({user: "ceilometer",pwd: "'${DB_PWD}'",roles: [ "readWrite","dbAdmin","clusterAdmin", "readWriteAnyDatabase", "dbAdminAnyDatabase" ]})'
openstack-config --set /etc/mongodb.conf '' auth true
systemctl restart mongod
mongo ceilometer -uceilometer -p
答案 0 :(得分:1)
这是版本2.4.9(https://jira.mongodb.org/browse/SERVER-11027)中的MongoDB错误,我按照https://docs.mongodb.org/master/tutorial/install-mongodb-on-red-hat/升级到版本2.6.11,它可以工作。