文件准备redis
下载redis
wget http://download.redis.io/releases/redis-6.2.3.tar.gz
解压
tar -zxvf redis-6.2.3.tar.gz
进入redis目录进行编译
cd redis-6.2.3
编译环境
安装编译器环境,redis6.X需要新版本的编译器,centos7默认的比较旧,需要升级新版本;
安装gcc
yum install gcc
升级gcc
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
查看版本
gcc -v
切换新版本
echo source /opt/rh/devtoolset-9/enable >> /etc/profile
source /etc/profile
编译
指定目录编译
make PREFIX=/usr/local/redis install
配置
将配置文件拷贝到编译好的目录中
cp redis.conf /usr/local/redis/
修改配置文件
#注销掉绑定本地连接
#bind 127.0.0.1
#去掉保护模式
protected-mode no
#后台启动
daemonize yes
具体其它的配置可以根据场景自行配置
启动
cd /usr/local/redis
./bin/redis-server redis.conf
添加开机启动服务
vim /etc/systemd/system/redis.service
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
对应命令
systemctl start redis.service
systemctl stop redis.service
systemctl restart redis.service
systemctl status redis.service
设置开机启动
systemctl enable redis.service