最全Linux安装最新Redis服务

  • 前言
  • 一、安装步骤
  • 1、下载安装包:https://redis.io/
  • 2、上传至Linux解压缩
  • 3、基本的命令环境安装
  • 4、make命令所有基本文件配置
  • 5、make配置出错解决
  • 5.1 make错误如下
  • 5.1 make错误原因
  • 5.1 解决方式
  • 6、服务安装成功后检查
  • 二、查看Redis默认安装路径
  • 三、拷贝Redis配置文件备份
  • 四、Redis设置默认后台启动
  • 五、启动Redis服务
  • 六、Redis客户端连接
  • 七、关闭Redis服务
  • 八、客户端连接工具连接Redis
  • 8、1 修改配置文件redis.conf:
  • 总结



前言

1、Redis是一款内存高速缓存数据库。Redis全称为:Remote Dictionary Server(远程数据服务),使用C 语言编写,Redis是一个key-value存储系统(键值存储系统),支持丰富的数据类型,如:String、list、set、 zset、hash。

2、Redis是一种支持key-value等多种数据结构的存储系统。可用于缓存,事件发布或订阅,高速队列等场景。使用C语言编写,支持网络,提供字符串,哈希,列表,队列,集合结构直接存取,基于内存,可持久化

一、安装步骤

1、下载安装包:https://redis.io/

linux redis解压版 redis linux安装包_linux redis解压版

2、上传至Linux解压缩

cd /user/local/myredis
tar -zxvf redis-6.0.9.tar.gz

linux redis解压版 redis linux安装包_redis_02

3、基本的命令环境安装

yum install g-c++

注意:如果yum install g-c++这个命令找不到,可以使用这个命令安装

yum install gcc-c++

linux redis解压版 redis linux安装包_linux redis解压版_03

4、make命令所有基本文件配置

cd redis-6.0.9
make

5、make配置出错解决

server.c:5166:39: error: ‘struct redisServer’ has no member named ‘maxmemory’

5.1 make错误如下

server.c:5151:94: error: ‘struct redisServer’ has no member named ‘unixsocket’
serverLog(LL_NOTICE,“The server is now ready to accept connections at %s”, server.unixsocket);
^
server.c:5152:19: error: ‘struct redisServer’ has no member named ‘supervised_mode’
if (server.supervised_mode == SUPERVISED_SYSTEMD) {
^
server.c:5153:24: error: ‘struct redisServer’ has no member named ‘masterhost’
if (!server.masterhost) {
^
server.c:5166:15: error: ‘struct redisServer’ has no member named ‘maxmemory’
if (server.maxmemory > 0 && server.maxmemory < 10241024) {
^
server.c:5166:39: error: ‘struct redisServer’ has no member named ‘maxmemory’
if (server.maxmemory > 0 && server.maxmemory < 10241024) {
^
server.c:5167:176: error: ‘struct redisServer’ has no member named ‘maxmemory’
serverLog(LL_WARNING,“WARNING: You specified a maxmemory value that is less than 1MB (current value is %llu bytes). Are you sure this is what you really want?”, server.maxmemory);
^
server.c:5170:31: error: ‘struct redisServer’ has no member named ‘server_cpulist’
redisSetCpuAffinity(server.server_cpulist);

5.1 make错误原因

gcc版本问题,redis6.0以上,升级到新版本的;

gcc -v

5.1 解决方式

升级gcc

yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils 
scl enable devtoolset-9 bash

#注意:scl命令启用只是临时的,当退出xshell或者重启就会恢复到原来的gcc版本。
#如果要长期生效的话,执行如下:

echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

6、服务安装成功后检查

linux redis解压版 redis linux安装包_Redis_04


再次输入make以及make install命令检查:

make

linux redis解压版 redis linux安装包_Redis_05

make install

linux redis解压版 redis linux安装包_redis_06

二、查看Redis默认安装路径

cd /usr/local/bin

linux redis解压版 redis linux安装包_linux redis解压版_07

三、拷贝Redis配置文件备份

新建目录,将Redis的配置文件进行拷贝:

[root@izhkyje12i9nrez bin]# mkdir dtconfig
[root@izhkyje12i9nrez bin]# cp /usr/local/myredis/redis-6.0.9/redis.conf dtconfig

linux redis解压版 redis linux安装包_Redis_08

四、Redis设置默认后台启动

linux redis解压版 redis linux安装包_Redis_09

vim redis.conf

linux redis解压版 redis linux安装包_Server_10


默认为no将其改为yes:

daemonize yes

五、启动Redis服务

通过指定的配置文件启动服务:

redis-server dtconfig/redis.conf

查看进程端口号:

netstat -tlunp

linux redis解压版 redis linux安装包_Server_11

六、Redis客户端连接

redis-cli -p 6379

linux redis解压版 redis linux安装包_linux_12

七、关闭Redis服务

shutdown
exit

linux redis解压版 redis linux安装包_linux redis解压版_13


linux redis解压版 redis linux安装包_linux_14

八、客户端连接工具连接Redis

8、1 修改配置文件redis.conf:

1、修改Redis服务保护模式

protected-mode yes :将yes修改为protected-mode no

2、注释掉 bind 127.0.0.1

#bind  127.0.0.1

然后重启服务

总结

以上就是Redis的完整安装教程,Redis应用场景,能做什么?下一篇我们会继续说道。