博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Centos7源码安装MongoDB-3.6
阅读量:6956 次
发布时间:2019-06-27

本文共 3059 字,大约阅读时间需要 10 分钟。

简介

MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。他支持的数据结构非常松散,是类似json的bson格式,因此可以存储比较复杂的数据类型。Mongo最大的特点是他支持的查询语言非常强大,其语法有点类似于面向对象的查询语言,几乎可以实现类似关系数据库单表查询的绝大部分功能,而且还支持对数据建立索引。

Packages包说明

MongoDB官方源中包含以下几个依赖包:

mongodb-org: MongoDB元数据包,安装时自动安装下面四个组件包:

1、mongodb-org-server: 包含MongoDB守护进程和相关的配置和初始化脚本。

2、mongodb-org-mongos: 包含mongos的守护进程。

3、mongodb-org-shell: 包含mongo shell。

4、mongodb-org-tools: 包含MongoDB的工具: mongoimport, bsondump, mongodump, mongoexport, mongofiles, mongooplog, mongoperf, mongorestore, mongostat, and mongotop。

实验环境

系统版本:centos7x3.10.0-514.el7.x86_64

mongodb版本:mongodb-linux-x86_64-rhel70-3.6.6

关闭防火墙并禁止开机自启

systemctl stop firewalld.service
systemctl disable firewalld

关闭selinux

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

重启 reboot

安装MongoDB

注:根据需求下载源码包即可!

1、前往Mongodb官网下载安装包(以下截图为下载路径)

//进入Mongodb官网(一定要使用兼容的浏览器否则可能打不开,例如火狐、谷歌等)

Centos7源码安装MongoDB-3.6

//单击选择社区服务器和linux系统

Centos7源码安装MongoDB-3.6

//单击左下方“Version下拉菜单”选择适合的版本

Centos7源码安装MongoDB-3.6

//最后根据需求下载指定版本的二进制文件并上传到服务器即可

Centos7源码安装MongoDB-3.6
Centos7源码安装MongoDB-3.6

2、解压Mongodb

1)查看压缩包 ls

Centos7源码安装MongoDB-3.6

2)解压mongodb-linux-x86_64-rhel70-3.6.6.tgz到指定目录

tar zxf mongodb-linux-x86_64-rhel70-3.6.6.tgz -C /usr/local/

3)进入解压目录

cd /usr/local/mongodb-linux-x86_64-rhel70-3.6.6/

3、创建Mongodb数据存储目录和日志存放目录

mkdir db log

Centos7源码安装MongoDB-3.6
注:这两个目录在后边的配置文件中会用到!

4、编写MongoDB配置文件

vi /usr/local/mongodb-linux-x86_64-rhel70-3.6.6/bin/mongodb.conf

systemLog:    destination: file    path: "/usr/local/mongodb-linux-x86_64-rhel70-3.6.6/log/mongodb.log"    logAppend: truestorage:    dbPath: "/usr/local/mongodb-linux-x86_64-rhel70-3.6.6/db/"    journal:         enabled: trueprocessManagement:    fork: true    pidFilePath: "/usr/local/mongodb-linux-x86_64-rhel70-3.6.6/mongodb.pid"net:    port: 27017setParameter:    enableLocalhostAuthBypass: false

Centos7源码安装MongoDB-3.6

注:这块可能有童鞋就会问了?你这mongodb.pid是什么文件?怎么没有呢?别着急这pid文件你可以理解成服务启动或者关闭时的进程代号。为啥没有找到这个文件呢?是因为这个文件默认源码安装不存在,我们提前写好路径是为了之后启动mongodb时,系统会自动按照这个路径去创建这个pid文件。

5、创建mongodb启动的脚本

vi /etc/init.d/mongodb

#!/bin/sh

#chkconfig: 2345 80 90
#description: mongodb
start() {
/usr/local/mongodb-linux-x86_64-rhel70-3.6.6/bin/mongod -f /usr/local/mongodb-linux-x86_64-rhel70-3.6.6/bin/mongodb.conf
}

stop() {

/usr/local/mongodb-linux-x86_64-rhel70-3.6.6/bin/mongod -f /usr/local/mongodb-linux-x86_64-rhel70-3.6.6/bin/mongodb.conf --shutdown
}

case "$1" in

start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac

6、给mongodb启动脚本执行权限

chmod +x /etc/init.d/mongodb

Centos7源码安装MongoDB-3.6

7、设置启动服务

1)将mongodb设置开机自启

chkconfig --level 35 mongodb on

2)将mongodb注册为系统服务

chkconfig --add mongodb

3)启动mongodb服务

/etc/init.d/mongodb start

Centos7源码安装MongoDB-3.6

4)停止mongodb服务

/etc/init.d/mongodb stop

Centos7源码安装MongoDB-3.6

5)重启mongodb服务

/etc/init.d/mongodb restart

Centos7源码安装MongoDB-3.6

8、开启防火墙,打开27017端口

1)开启防火墙

systemclt start firewalld

2)永久打开27017端口

firewall-cmd --add-port=27017/tcp --permanent

3)重启防火墙使配置生效

systemctl restart firewalld

4)查看是否生效

firewall-cmd --list-all

9、配置环境变量

1)编辑环境变量并在最后添加一行文件如下

vi /etc/profile

export PATH=$PATH:/usr/local/mongodb-linux-x86_64-rhel70-3.6.6/bin

Centos7源码安装MongoDB-3.6

2)执行环境变量

source /etc/profile

10、测试mongodb是否安装成功

1)使用mongo命令进入到mongodb控制台

Centos7源码安装MongoDB-3.6

2)切换数据库管理用户

use admin

Centos7源码安装MongoDB-3.6
注:到这里就完成了mongodb数据库的×××!

转载于:https://blog.51cto.com/13043516/2162072

你可能感兴趣的文章
python基础知识~ 序列化
查看>>
Activity的启动模式(android:launchMode)
查看>>
UML 依赖 泛化 关联关系的区别
查看>>
DOS查看端口占用及杀掉进程命令
查看>>
animate动画解析
查看>>
如何查找完全二叉树最后一层的最右边的结点
查看>>
java设计模式演示样例
查看>>
创建与删除索引
查看>>
HTML5新增核心工具——canvas
查看>>
改动file header (測)
查看>>
微软职位内部推荐-Senior Speech TTS
查看>>
UVA - 10574 Counting Rectangles
查看>>
HDU3336-Count the string(KMP)
查看>>
常用API接口签名验证参考
查看>>
Linux中find常见用法示例
查看>>
bootstrap 模态框动态加载数据
查看>>
初始化构造函数中定义的实体集合,方便嵌套类型的遍历
查看>>
深入理解css3中nth-child和 nth-of-type的区别
查看>>
MySQL慢查询Explain Plan分析
查看>>
MyBatis原理分析之三:初始化(配置文件读取和解析)
查看>>