导入mongodbGPG公钥
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
创建下载地址文件
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
更新软件仓库
sudo apt-get update
安装mongodb
sudo apt-get install -y mongodb-org
便捷配置文件
开启认证
db.createUser(
{
user: "myUserAdmin",
pwd: "abc123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
然后修改配置文件,增加
security:
authorization: enabled
重启实例
mongo --port 40029 -u admin -authenticationDatabase admin
连接实例
mongo --port 40029 -u admin -authenticationDatabase admin