官网提供的源码下载地址:
https://github.com/redis/redis/archive/7.0.5.tar.gz

# 将解压缩后的文件放置在同目录的source文件夹下
tar -zxvf redis-7.0.5.tar.gz -C ./source
对源码进行编译、安装
# PREFIX参数表示安装在哪个目录下
make PREFIX=/home/ubuntu/redis/redis-7.0.5 install
# 将源码提供的配置文件复制到安装目录下
cp /home/ubuntu/redis/source/redis-7.0.5/redis.conf /home/ubuntu/redis/redis-7.0.5/bin/
# 启动redis时需要指定配置文件
./redis-server /home/ubuntu/redis/redis-7.0.5/bin/redis.conf
# 将下面一行配置添加注释,使其他主机可以访问redis服务
# bind 127.0.0.1 -::1
# 将以下配置取消注释,修改密码
requirepass ********
# 下面配置必须打开,密码才能生效
protected-mode yes
# 修改日志文件
logfile "/home/ubuntu/redis/redis.7.0.5/bin/redis.log"
# 将源码文件中utils/install_server.sh文件以下脚本注释
#bail if this system is managed by systemd
#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
# echo "This systems seems to use systemd."
# echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
# exit 1
#fi
创建服务脚本
sudo REDIS_PORT=6379 \
REDIS_CONFIG_FILE=/home/ubuntu/redis/redis-7.0.5/bin/redis.conf \
REDIS_LOG_FILE=/home/ubuntu/redis/redis.7.0.5/bin/redis.log \
REDIS_DATA_DIR=/home/ubuntu/redis/redis.7.0.5/bin/ \
REDIS_EXECUTABLE=`command -v /home/ubuntu/redis/redis-7.0.5/bin/redis-server` \
/home/ubuntu/redis/source/redis-7.0.5/utils/install_server.sh
创建服务文件
[Unit]
Description=Redis
After=network.target
[Service]
ExecStart=/home/ubuntu/redis/redis-7.0.5/bin/redis-server /home/ubuntu/redis/redis-7.0.5/bin/redis.conf --daemonize no
ExecStop=/home/ubuntu/redis/redis-7.0.5/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown
[Install]
WantedBy=multi-user.target
创建软链接,为服务自启动准备
ln -s /lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants/redis.service
systemctl daemon-reload
ps aux|grep redis
kill -9 [pid]
systemctl start redis