MongoDB安装(Centos7)

1、MongoDB简介
MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need

MongoDB是一个文档数据库,具有您需要的可查询性和索引所需的可伸缩性和灵活性。
2、MongoDB下载

//下载MongoDB
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.12.tgz
//重命名
mv mongodb-linux-x86_64-4.0.12 mongodb

也可进官网选择合适的版本下载:

下载地址:https://www.mongodb.com/download-center/community
3、进入MongoDB的目录,创建db和logs,用来保存数据和日志

cd mongodb

mkdir db

mkdir logs

4、进入bin目录,新建mongodb.conf

//数据存储目录

dbpath=/usr/soft/mongodb/db

//日志文件目录

logpath=/usr/soft/mongodb/logs/mongodb.log

//启动端口

port=27017

//允许线程在后台运行

fork=true

5、mongodb的启动与关闭

./mongo -f mongo.conf --bind_ip_all

-f 表示配置文件的位置

--bind_ip_all 表示允许所有远程地址连接


再次执行mongo则进入mongodb的控制台

./mongo

db.version()执行后能看到版本信息代表安装完成

MongoDB安装(Centos7)_第1张图片
6、MongoDB的退出

mongodb默认连接的是test,推出需要切换到admin

use admin

db.shutdownServer();

exit

7、安全认证(设置数据库密码)

为数据库创建用户waggag及密码123456,对test数据库具有读写权限

db.createUser({user:"waggag",pwd:"123456",roles:[{role:"readWrite",db:"test"}]})


用户创建成功后重新启动mongodb

./mongod -f mongo.conf --auth --bind_ip_all


切换到admin下进行认证

use admin

./mongodb

db.auth("waggag","123456")

如果执行结果为1,代表认证成功,可以执行对test的读写操作了

你可能感兴趣的:(数据库,NoSql,Linux)