Ubuntu 18.04配置MongoDB密码登录
系统:
Ubuntu 18.04
MongoDB: 4.2,3
安装MongoDB server 和client(测试用)
# 添加MongoDB GPG密钥 apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B7C549A058F8B6B # 创建MongoDB存储库 echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb.list apt-get update apt-get install mongodb-org apt-get install mongodb-clients
启动MongoDB
systemctl start mongod.service
登录MongoDB并设置密码
# 登录 mongo # 切换到admin数据库 use admin # 创建admin账号,密码::admin111 权限:root权限,授权的数据库名:admin db.createUser({user:"admin", pwd:"admin111", roles:[{role:"root", db:"admin"}]})
编辑MongoDB配置文件
vim /etc/mongod.conf net: port: 27017 # 端口 bindIp: 0.0.0.0 # 允许访问的地址,0.0.0.0表示所有 security: authorization: enabled
重启MongoDB服务
systemctl restart mongod.service
测试登录
mongo -u admin -p admin111 --authenticationDatabase admin
相关推荐
我心似明月 2020-11-09
lbyd0 2020-11-17
BigYellow 2020-11-16
sushuanglei 2020-11-12
zhushenghan 2020-11-09
sunnnyduan 2020-10-16
不要皱眉 2020-10-14
xiaohai 2020-09-29
songxiugongwang 2020-09-22
萌亖 2020-09-17
LuckyLXG 2020-09-08
sdmzhu 2020-09-01
mkhhxxttxs 2020-09-16
xiaohai 2020-09-16
newcome 2020-09-09
jaylong 2020-08-19
大秦铁骑 2020-08-19
thatway 2020-08-19