整理篇之《Centos7下MongoDB的安装步骤,启动及关闭》

环境:本机windows,虚拟机Centos7,mongodb版本3.4.10

1. 官网下载安装介质:https://www.mongodb.com/download-center,选择适当的版本,这里以linux版本为例; 

2. 解压到系统某路径, tar -xvzf mongodb-linux-x86_64-rhel70-3.4.10.tgz,并在安装目录创建data目录,以及logs目录和logs/mongodb.log文件 
3. 使用vim在mongodb的bin目录创建mongodb的配置文件:vim bin/mongodb.conf
4. 编写shell脚本,命名为start-mongodb.sh,脚本: nohup ./mongod -f mongodb.conf & 
5. 给文件start-mongodb.sh赋权限:chmod 777 start-mongodb.sh
6. 使用start-mongodb.sh启动mongodb实例,如:./start-mongodb 
7. 连接mongodb数据库:./mongo localhost:27022
8. 使用mongoClient进行测试,通过restAPI地址测试(端口加1000) http://IP:28022/
9. 查看mongodb的进程:ps -aux | grep mongo

10. 关闭mongodb:db.shutdownServer({force : true})

配置文件(mongodb.conf)

storage:
   dbPath: "/usr/local/apache/mongoDB/mongodb-linux-x86_64-rhel70-3.4.10/data"
systemLog:
   destination: file
   path: "/usr/local/apache/mongoDB/mongodb-linux-x86_64-rhel70-3.4.10/logs/mongodb.log"
net:
   port: 27022
   http:
      RESTInterfaceEnabled: true
processManagement:
   fork: false
参数解释:
-dbPath:数据存储路径 
systemLog path日志文件存储路径 
net port mongodb端口 
http RESTInterfaceEnabled:true开启RESTAPI接口(正常情况下不用开启,需要占用一定的性能)

备注:
如果本机连不上虚拟机mongodb,有可能是虚拟机防火墙没有关闭,关闭防火墙命令如下:systemctl stop firewalld

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值