Redis实战-Linux上安装Redis步骤(图文详解)
一、Redis简介
Remote Dictionary Server(远程字典服务器),是一个用C语言编写的、开源的、基于内存运行并支持持久化的、高性能的NoSQL数据库.也是当前热门的NoSQL数据库之一。
开始之前,分享给大家我看过的Redis视频,讲的很不错,适合入门,通过视频的学习:
带你了解NoSQL是什么,NoSQL和关系型数据库的对比优缺点。
掌握Redis是什么、能干什么、如何用;
掌握Redis在Windows和Linux下的安装配置、五大数据类型、常用操作命令、Redis持久化、主从复制、事务控制以及用Jedis操作进行Java开发等技术点。
在线观看:
Redis实战精讲-13小时彻底搞定Redis_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili
资料、源码下载:
二、Redis的特点
1、支持数据持久化
Redis支持数据的持久化,可以将内存中的数据保持在磁盘中,重启的时候可以再次加载进行使用。
2、支持多种数据结构
Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存储。
3、支持数据备份
Redis支持数据的备份,即master-slave模式的数据备份。
三、Linux上安装Redis
第一步:下载redis
https://redis.io/

第二步:使用Xftp工具上传redis-5.0.2.tar.gz到linux 系统。

第三步:解压redis-5.0.2.tar.gz到/opt目录

第四步:编译redis,进入解压目录,并且执行make命令:

报错:gcc命令未找到

第五步:安装gcc。
1)什么是 gcc ?
gcc是GNU compiler collection的缩写,它是Linux下一个编译器集合(相当于javac ),是c或c++程序的编器。
2)怎么安装gcc ?
方式一:在有外网的情况下,使用yum进行安装。执行命令:yum -y install gcc。
方式二:在没有外网的情况下,从光盘里进行安装。
1、从终端进入目录:/run/media/root/CentOS 7 x86_64/Packages

2、依次执行命令:
rpm -ivh libmpc-1.0.1-3.el7.x86_64.rpm 回车
rpm -ivh cpp-4.8.5-11.el7.x86_64.rpm 回车
rpm -ivh kernel-headers-3.10.0-514.el7.x86_64.rpm 回车
rpm -ivh glibc-headers-2.17-157.el7.x86_64.rpm 回车
rpm -ivh glibc-devel-2.17-157.el7.x86_64.rpm回车
rpm -ivh libgomp-4.8.5-11.el7.x86_64.rpm回车
rpm -ivh gcc-4.8.5-11.el7.x86_64.rpm回车

3、执行gcc –v查看Linux内核版本

第六步:再次回到redis解压目录执行make命令进行编译

第七步:进行清理工作

第八步:再次执行make指令进行编译:

第九步:执行make install安装redis:

注意:在make执行之后再执行 make install,该操作则将 src下的许多可执行文件复制到/usr/local/bin 目录下,这样做可以在任意目录执行redis的软件的命令(例如启动,停止,客户端连接服务器等), make install 可以不用执行,看个人习惯。查看make编译结果,cd src目录


第十步:启动Redis
启动方式:
① 前台启动 redis-server

②后台启动 redis-server &

③根据配置文件启动 启动命令 配置文件 &

注意:如果修改了redis的配置文件redis.conf,必须在启动时指定配置文件,否则修改无效!
第十一步:关闭Redis服务
关闭方式:
①使用redis客户端关闭,向服务器发出关闭命令
任意目录下执行 指令redis-cli shutdown
推荐使用这种方式, redis先完成数据操作,然后再关闭。
例如:

②kill pid 或者 kill -9 pid
这种不会考虑当前应用是否有数据正在执行操作,直接就关闭应用。
先使用 ps -ef | grep redis 查出进程号,在使用 kill pid
