centos7系统安装mongodb5
1、上传 mongodb-linux-x86_64-rhel70-5.0.28.tgz 到centos7服务器,解压安装
tar -zxvf mongodb-linux-x86_64-rhel70-5.0.28.tgz -C /usr/local
cd /usr/local/
mv mongodb-linux-x86_64-rhel70-5.0.28 mongodb #重命名
vi /etc/profile
export MONGODB_HOME=/usr/local/mongodb export PATH=$PATH:$MONGODB_HOME/bin
source /etc/profile
2、创建data和logs目录,创建mongodb.conf配置文件,启动mongod服务
cd /usr/local/mongodb
mkdir data logs
vi mongodb.conf
#端口号 port=27017 #db目录 dbpath=/usr/local/mongodb/data #日志目录 logpath=/usr/local/mongodb/logs/mongodb.log #后台 fork=true #日志输出 logappend=true #允许远程IP连接 bind_ip=0.0.0.0 #开启认证 ,默认为false auth=true
启动服务
bin/mongod -f mongodb.conf
停止服务
bin/mongod -f mongodb.conf --shutdown
3、控制台连接(第一次连接需要创建管理员用户)
mongo --port 27017
use admin
db.createUser({
user: 'admin',
pwd: 'yourpassword',
roles: [{ role: 'root', db: 'admin' }]
})
在admin库中创建一个超级管理员用户:admin,密码为:yourpassword 超级管理员账户可以使用所有的db,且对所有db具有所有权限
use rmc
db.createUser({
user: 'riskmage',
pwd: 'somepassword',
roles: [{ role: 'readWrite', db: 'rmc' },{"role":"dbAdmin","db":"rmc"}]
})
在rmc库中创建一个普通账户:riskmage, 密码为: somepassword
客户端连接 :
mongo --port 27017 -u "admin" -p "yourpassword" --authenticationDatabase "admin"
mongo --port 27017 -u "riskmage" -p "somepassword" --authenticationDatabase "rmc"
4、navicat工具连接mongodb
查询数据
Copyright © 叮叮声的奶酪 版权所有
备案号:鄂ICP备17018671号-1