内容纲要

反安装

[code]
sudo service mongod stop

sudo apt-get purge mongodb-org*

sudo rm -r /var/log/mongodb

sudo rm -r /var/lib/mongodb
[/code]

安装

[code]
sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list

sudo apt-get update

sudo apt-get install -y mongodb-org

sudo service mongod start

sudo service mongod stop

sudo service mongod restart

# 查看 mongo 是否在 27017 端口启动
netstat -plntu
[/code]

mongo shell

[code]
mongo –host 127.0.0.1:27017
[/code]

设置用户名密码

[code]
use admin

db.createUser({user:"admin", pwd:"admin123", roles:[{role:"root", db:"admin"}]})

exit

vim /lib/systemd/system/mongod.service
[/code]

[code]
ExecStart=/usr/bin/mongod –quiet –auth –config /etc/mongod.conf
[/code]

[code]
sudo systemctl daemon-reload
sudo service mongod restart
[/code]

重新使用用户名密码连接
[code]
mongo -u admin -p admin123 –authenticationDatabase admin
[/code]

发表评论

电子邮件地址不会被公开。 必填项已用*标注