markdown 在Ubuntu中安装MongoDB,启用访问控制,为MongoDB创建管理员用户和数据库用户

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 在Ubuntu中安装MongoDB,启用访问控制,为MongoDB创建管理员用户和数据库用户相关的知识,希望对你有一定的参考价值。

# MongoDB Kickstart in Ubuntu
> Install and enable access control, create Admin and database User via MongoDB Shell

## Installation and Enable Access Control

Use apt-get install for installation
```bash
$ apt-get install mongodb
$ systemctl status mongodb
```
Access control can be enabled via configuration file which default in `/etc/mongodb.conf` or via parameters when starting mongodb service `--auth`.
Before enable access control create an Admin User first, this admin have the privileges to create user and give access to any database in the server.

## Create Admin User via Shell

Connect to MongoDB service via mongo shell; and create user in database admin.

``` bash
$ mongo
> use admin
> db.createUser({user:"Admin", pwd:"PasswordAdmin", roles:[{role:"userAdminAnyDatabase", db:"admin"}]})
```
Role `userAdminAnyDatabase` is a built-in role for managing users in the server.
After creating the Admin user change the configuration, restart the service and reconnect.

## Create Database User

``` bash
$ vim /etc/mongodb.conf
# Comment out auth=true, by default configuration use auth=false
$ systemctl restart mongodb
```

Reconnect to the server and authenticate to create other user using `db.createUser` and different role.

```bash
$ mongo
> db.auth("Admin","PasswordAdmin")
> db.createUser({user:"DbUser", password:"DbAdminPass", roles:[{role: "readWrite", db:"db_name"}]})
```

以上是关于markdown 在Ubuntu中安装MongoDB,启用访问控制,为MongoDB创建管理员用户和数据库用户的主要内容,如果未能解决你的问题,请参考以下文章

markdown 在Ubuntu中安装MongoDB,启用访问控制,为MongoDB创建管理员用户和数据库用户

如何在ubuntu中安装scrapy

如何在 apache2 tomcat6 中安装 ffmpeg 或在 ubuntu 中安装 xampp?

markdown 在MacOS中安装PHP MSSQL驱动程序(Mojave)

markdown 在MacOS中安装和配置Oh My Zsh! :)

我可以在 ubuntu 中安装 xcode 吗?