mongodb普通用户启动配置啥
时间: 2023-09-05 12:10:58 浏览: 109
要启动MongoDB普通用户,需要进行以下配置:
1. 创建一个新的用户账户,例如"mongouser",并为该账户分配合适的角色权限。
2. 在MongoDB配置文件中,启用身份验证功能,即在配置文件中添加如下行:
```
security:
authorization: enabled
```
3. 重启MongoDB服务,使配置生效。
4. 使用mongouser账户进行登录,例如:
```
mongo -u mongouser -p --authenticationDatabase admin
```
其中,"-u"选项指定用户名,"-p"选项指定密码,"--authenticationDatabase"选项指定身份验证数据库。登录成功后,即可进行普通用户的操作。
相关问题
mongodb改用普通用户启动
要改用普通用户启动 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。
mongodb如何使用普通用户启动
使用普通用户启动 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 服务,使配置生效。
``` shell
sudo systemctl restart mongod
```
4. 使用普通用户连接 MongoDB。可以使用以下命令连接 MongoDB:
``` shell
mongo -u testuser -p testpassword --authenticationDatabase testdb
```
其中,`testuser`和`testpassword`分别为创建的普通用户的用户名和密码,`testdb`为普通用户拥有权限的数据库名。
使用以上步骤,就可以使用普通用户启动 MongoDB。
阅读全文
相关推荐












