开始部署之前,建议先按照Ubuntu切换到国内镜像源操作一下,能省下大把宝贵时间!
安装mongodb
$ sudo apt-get install mongodb
mongodb
默认是监听在127.0.0.1
端口的,要开启外网连接,需要修改mongodb
配置文件:
$ vim /etc/mongodb.conf
# bind_ip = 127.0.0.1
bind_ip = 0.0.0.0
连接mongodb
使用工具robo 3t,添加连接信息
启用密码访问
mongodb
默认是不开启密码登录的,如果要开启,修改mongodb
配置文件
$ vim /etc/mongodb.conf
auth = true
$ sudo service mongodb restart
常用命令
# 使用数据库,如果没有则新建
use test_db;
# 创建新用户,并为其赋予test_db的读写权限
db.createUser({user:'cool', pwd:'cool', roles: [ { role: "readWrite", db: "test_db" } ]});
连接mongodb
连接方式跟上面类似,唯一不同的是要添加authentication
,指定database
,username
,password
,以及选择Mongodb-CR
验证方式
如果本篇博客对您有一定的帮助,大家记得留言+点赞+收藏哦。
我是阿晨,在技术的道路上我们一起砥砺前行!