1、下载安装包
wget https://codeload.github.com/redis/redis/tar.gz/refs/tags/7.0.11
2、解压
tar -xvf redis-7.0.11.tar.gz
3、安装gcc依赖
yum install gcc
4、进入解压目录,并编译
cd redis-7.0.11
make
5、编译完成后进入src目录
cd ./src
6、创建安装目录
mkdir /usr/local/redis
7、安装
make install PREFIX=/usr/local/redis
8、拷贝配置文件
cd redis-7.0.11
cp redis.conf /usr/local/redis/bin/
9、赋予权限
chmod +x /etc/redis/
10、编写redis.service文件
cd /etc/systemd/system/ #切换目录
vim redis.service
[Unit]
Description=Redis
After=network.target
[Service]
#更改成自己的路径
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
ExecReload=/usr/redis/redis-server -s reload
ExecStop=/usr/redis/redis-server -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
11、编写redis文件并赋予权限
cd /etc/init.d
vim redis
#!/bin/bash
### BEGIN INIT INFO
# Provides: Redis
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Redis daemon at boot time
# Description: Start Redis daemon at boot time
### END INIT INFO
#redis服务器监听的端口
REDISPORT=6379
#服务端所处位置
EXEC=/usr/redis/redis-server
#客户端位置
CLIEXEC=/usr/redis/redis-cli
#redis的PID文件位置,需要修改
PIDFILE=/var/run/redis_${REDISPORT}.pid
#redis的配置文件位置,需将${REDISPORT}修改为文件名
CONF="/etc/redis/${REDISPORT}.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF &
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
chmod +x redis
12、设置开机自启
#开启redis
systemctl start redis
#关闭redis
systemctl stop redis
#查看状态
systemctl status redis
#设置开机自启
systemctl enable redis