天天看点

CentOS7 安装redis6

1、环境检查

yum -y install gcc
yum -y install epel-release
           

# 查看gcc版本是否在5.3以上,centos7.6默认安装4.8.5

gcc -v
           

# 升级gcc到5.3及以上,如下:

升级到gcc 9.3:

yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
#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命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。

如果要长期使用gcc 9.3的话:

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

这样退出shell重新打开就是新版的gcc了

准备Redis安装包

wget https://download.redis.io/releases/redis-6.0.10.tar.gz
           

-bash: wget: 未找到命令

rpm 安装

下载wget的RPM包:

# http://mirrors.163.com/centos/6.8/os/x86_64/Packages/wget-1.12-8.el6.x86_64.rpm
# 执行
rpm -ivh wget-1.12-8.el6.x86_64.rpm 
           

yum安装

yum -y install wget
           

下载Redis6 压缩包

wget https://download.redis.io/releases/redis-6.0.10.tar.gz
           

复制redis-6.0.10.tar.gz 到 指定目录 /usr/local/redis

解压redis   tar -zxvf redis-6.0.10.tar.gz

编译安装:进入redis-6.0.10目录编译 make && make install

试运行一把:

    进入src目录  cd src

    启动Redis   ./redis-server

配置Redis

设置开机自启动

将redis.conf中daemonize设置为yes,确保守护进程开启。

打开加入

 vim /etc/profile    

 文件末尾添加

 export REDIS_HOME=/usr/local
 export PATH=$PATH:$REDIS_HOME/bin
           

 保存并退出

 刷新profile

 . /etc/profile
           

 下面执行安装服务,交互设置根据自己的需要,我都是直接回车

./redis-6.0.10/utils/install_server.sh
           

 在这里报错

 Welcome to the redis service installer

This script will help you easily set up a running redis server

This systems seems to use systemd.

Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!

打开install_server.sh,注释掉下面的内容:注释内容参考

CentOS7 安装redis6

重新执行,一路选择默认配置即可。

继续阅读