在CentOS上管理MongoDB用戶,您需要遵循以下步驟:
登錄到您的CentOS服務器。
啟動MongoDB服務(如果尚未啟動):
sudo systemctl start mongod
mongo命令連接到MongoDB shell:mongo
admin數據庫:use admin
db.createUser({
user: "adminUser",
pwd: "your_password",
roles: ["root"]
})
exit
mongo -u adminUser -p your_password --authenticationDatabase admin
myDatabase的數據庫中創建一個名為myUser的用戶,請執行以下命令:use myDatabase
db.createUser({
user: "myUser",
pwd: "your_password",
roles: [
{
role: "readWrite",
db: "myDatabase"
}
]
})
db.updateUser("myUser", {
pwd: "new_password",
roles: [
{
role: "readWrite",
db: "myDatabase"
}
]
})
db.dropUser("myUser")
mongo -u adminUser -p your_password --authenticationDatabase admin
現在您已經在CentOS上成功管理了MongoDB用戶。請確保為每個數據庫創建具有適當角色的用戶,以便根據需要限制訪問權限。