centos7 安装redis6教程

redis版本:6.0.15

下载页面

https://redis.io/download

1、下载

https://download.redis.io/releases/redis-6.0.15.tar.gz

2、环境准备

编译安装需要gcc5.3以上,可以用gcc -v 命令查看当前版本号,使用下面的命令升级到gcc9.1

 

 更换gcc版本

yum install centos-release-scl scl-utils-build #安装scl源

yum install -y devtoolset-9-toolchain  #安装9版本的gcc、gcc-c++、gdb工具链

scl enable devtoolset-9 bash         #设置版本生效,并再次查看版本(gcc -v)

注意:scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。

设置版本长期生效: echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

3、安装redis

tar -xzf redis-6.0.15.tar.gz

cd redis-6.0.15

make

make PREFIX=/usr/local/redis install

4、修改配置文件

mkdir -p /usr/local/redis/{conf,data,logs}

grep -Ev '^#|^$' redis-6.0.15/redis.conf > /usr/local/redis/conf/redis.conf

vim /usr/local/redis/conf/redis.conf

bind 127.0.0.1 192.168.1.61

logfile "/usr/local/redis/logs/redis_6379.log"  #日志存储路径

dir /usr/local/redis/data    #数据存储目录

daemonize yes           #设置后台运行

requirepass 123456       #设置密码

maxclients 100000        #配置连接数

5、启动

/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf

6、添加到启动项

vim /lib/systemd/system/redis.service 

[Unit]

Description=Redis

After=network.target

[Service]

Type=forking

PIDFile=/var/run/redis_6379.pid

ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s QUIT $MAINPID

PrivateTmp=true

 

[Install]

WantedBy=multi-user.target

 

systemctl daemon-reload  #加载

systemctl start redis      #启动

systemctl enable redis     #开启启动

7、添加到环境变量

vim /etc/profile

#redis

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

source /etc/profile  #生效

 

原文地址:https://www.cnblogs.com/qiansm/p/15241159.html