CentOS Stream 9 编译安装 Redis 7.2.7 完整版详细步骤

CentOS Stream 9 编译安装 Redis 7.2.7 完整版详细步骤


一、安装编译依赖

bash 复制代码
dnf install -y gcc gcc-c++ make openssl-devel

二、下载 Redis 7.2.7 源码

bash 复制代码
cd /usr/local/src
wget https://download.redis.io/releases/redis-7.2.7.tar.gz

三、解压并编译

bash 复制代码
tar -zxvf redis-7.2.7.tar.gz
cd redis-7.2.7

# 编译(时间很短)
make

出现 Hint: It's a good idea to run 'make test' 表示编译成功。


四、安装到系统目录

bash 复制代码
make install PREFIX=/usr/local/redis

安装后路径:

  • 命令:/usr/local/redis/bin/
  • 配置文件:我们后面手动创建

五、创建配置、数据、日志目录

bash 复制代码
mkdir -p /usr/local/redis/conf
mkdir -p /data/redis
mkdir -p /var/log/redis

六、复制配置文件

bash 复制代码
cp redis.conf /usr/local/redis/conf/redis.conf

七、修改 redis.conf(关键配置)

bash 复制代码
vim /usr/local/redis/conf/redis.conf

修改以下内容(直接搜关键词):

ini 复制代码
bind 127.0.0.0  192.168.1.149
protected-mode no
port 6379
daemonize no
pidfile /var/run/redis.pid
logfile /var/log/redis/redis.log
dir /data/redis
requirepass 123456   # Redis 密码
appendonly yes       # 开启AOF持久化

八、创建 systemd 服务

ini 复制代码
cat > /etc/systemd/system/redis.service <<EOF
[Unit]
Description=Redis Custom Server
After=network.target

[Service]
Type=forking
PIDFile=/var/run/redis.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
EOF

九、权限设置

bash 复制代码
# 目录权限
chown -R root:root /usr/local/redis
chmod 755 /data/redis
chmod 755 /var/log/redis

十、重载服务并启动

bash 复制代码
systemctl daemon-reload
systemctl enable --now redis
systemctl status redis

看到 active (running) 即成功。


十一、加入全局命令(可选)

  1. 想直接用 redis-cli 命令(加软链接)
bash 复制代码
ln -s /usr/local/redis/bin/redis-cli /usr/local/bin/
bash 复制代码
echo 'export PATH=$PATH:/usr/local/redis/bin' >> /etc/profile
source /etc/profile

测试:

bash 复制代码
redis-server -v
redis-cli -v

十二、连接测试

bash 复制代码
redis-cli
127.0.0.1:6379> AUTH 123456
127.0.0.1:6379> set test hello
127.0.0.1:6379> get test

常用命令

bash 复制代码
systemctl start redis
systemctl stop redis
systemctl restart redis
systemctl status redis

兼容说明

Redis 7.2.7 完美兼容 CentOS Stream 9

  • 支持 jemalloc
  • 支持 systemd
  • 支持 TLS
  • 无依赖冲突
  • 生产环境稳定可用

相关推荐
笨笨饿4 分钟前
#138_解决Codex要五次回复的问题
linux·stm32·单片机·嵌入式硬件·mcu·物联网·嵌入式实时数据库
m0_459872925 分钟前
Linux 系统基础
linux·运维·服务器
吴声子夜歌20 分钟前
Shell编程——数组
linux·运维·shell
blueSatchel1 小时前
ros-humble仿真-建图-导航
linux·ros2
Lucis__1 小时前
基于责任链模式的消息队列—异步处理流水线的最佳实践
linux·c++·消息队列·责任链模式·ipc
程序员-Benothing1 小时前
Shell 脚本条件判断与流程控制:if for while case 详解
linux·运维·服务器
mounter6251 小时前
统一安全域:KVM Planes 如何驾驭硬件特权级
linux·安全·linux kernel·kernel
君生我老2 小时前
Linux动静态库
linux·服务器
宵时待雨2 小时前
linux笔记归纳19:网络层协议IP
linux·网络·笔记·网络协议·tcp/ip
做运维的阿瑞3 小时前
Linux下DNS服务器搭建
linux·运维·服务器