MongoDB安装(Centos7)

客官°小女子只卖身不卖艺 2023-07-24 13:22 129阅读 0赞

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下载

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

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

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

  1. cd mongodb
  2. mkdir db
  3. mkdir logs

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

  1. //数据存储目录
  2. dbpath=/usr/soft/mongodb/db
  3. //日志文件目录
  4. logpath=/usr/soft/mongodb/logs/mongodb.log
  5. //启动端口
  6. port=27017
  7. //允许线程在后台运行
  8. fork=true

5、mongodb的启动与关闭

  1. ./mongo -f mongo.conf --bind_ip_all
  2. -f 表示配置文件的位置
  3. --bind_ip_all 表示允许所有远程地址连接
  4. 再次执行mongo则进入mongodb的控制台
  5. ./mongo
  6. db.version()执行后能看到版本信息代表安装完成

MongoDB启动log
6、MongoDB的退出

  1. mongodb默认连接的是test,推出需要切换到admin
  2. use admin
  3. db.shutdownServer();
  4. exit

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

  1. 为数据库创建用户waggag及密码123456,对test数据库具有读写权限
  2. db.createUser({user:"waggag",pwd:"123456",roles:[{role:"readWrite",db:"test"}]})
  3. 用户创建成功后重新启动mongodb
  4. ./mongod -f mongo.conf --auth --bind_ip_all
  5. 切换到admin下进行认证
  6. use admin
  7. ./mongodb
  8. db.auth("waggag","123456")
  9. 如果执行结果为1,代表认证成功,可以执行对test的读写操作了

发表评论

表情:
评论列表 (有 0 条评论,129人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CentOS 7安装MongoDB

    简介 因为公司监控系统获取的应用监控指标数据,需要存放在mongo数据库,最近就开始研究一下mongo数据库,先从最简单的mongo数据库安装和简单使用,和大家做一下分享