mongodb改用普通用户启动
时间: 2023-07-25 16:31:44 浏览: 156
要改用普通用户启动 MongoDB,需要按照以下步骤进行操作:
1. 创建一个普通用户。可以通过以下命令创建一个用户名为testuser的普通用户:
``` shell
use admin
db.createUser({
user: "testuser",
pwd: "testpassword",
roles: [
{ role: "readWrite", db: "testdb" }
]
})
```
2. 修改 MongoDB 配置文件,启用身份验证。打开 MongoDB 的配置文件(默认为/etc/mongod.conf),找到`security`部分,将`authorization`选项设置为`enabled`:
``` shell
security:
authorization: enabled
```
3. 修改 MongoDB 启动脚本,使用普通用户启动。打开 MongoDB 的启动脚本(默认为/etc/init.d/mongod),将其中的`USER`变量值修改为创建的普通用户的用户名`testuser`:
``` shell
USER=testuser
```
4. 重启 MongoDB 服务,使配置生效。
``` shell
sudo service mongod restart
```
使用以上步骤,就可以改用普通用户启动 MongoDB。
阅读全文
相关推荐














