-
安装依赖包
[root@redis-node1 ~]# dnf install make gcc initscripts -y
注释 :gcc 和 make 是源码编译必需的工具,initscripts 用于支持服务管理脚本。
-
下载并解压源码
[root@redis-node1 ~]# wget https://download.redis.io/releases/redis-7.4.8.tar.gz
[root@redis-node1 ~]# tar zxf redis-7.4.8.tar.gz
[root@redis-node1 ~]# cd redis-7.4.8/ -
编译与安装
[root@redis-node1 redis-7.4.8]# make && make install
注释 :make 编译源码,make install 将二进制文件安装到 /usr/local/bin 目录下。
-
安装服务脚本(关键步骤)
[root@redis-node1 redis-7.4.8]# cd utils/
[root@redis-node1 utils]# vim install_server.sh
修改内容:注释掉检测 systemd 的代码段,防止脚本因检测到 systemd 而退出。
# 注释掉以下部分,以便在 systemd 系统上强制使用 init 脚本安装
# 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
注释 :Redis 官方脚本默认检测到 systemd 会拒绝安装 init 脚本。注释掉后可强制生成 /etc/init.d/redis_6379 脚本,方便后续使用 systemctl 管理。
-
执行安装脚本并启动
[root@redis-node1 utils]# ./install_server.sh
按回车接受默认配置(端口 6379,配置文件 /etc/redis/redis.conf 等)
[root@redis-node1 utils]# systemctl daemon-reload
[root@redis-node1 utils]# systemctl start redis_6379.service
[root@redis-node1 utils]# systemctl status redis_6379.service
注释 :其他节点(node2, node3)需重复上述安装步骤。安装完成后检查端口监听情况:netstat -antlpe | grep redis。