114 字
1 分钟
CentOS 编译安装 Redis 6.2 并配置 Systemd 服务
2026-01-14

Redis 版本:6.2.6

通过源码下载本地编译,配置 systemd 服务文件,使用 systemctl 进行管理。

一、下载解压#

# 下载 redis
wget https://cdn.olinl.com/redis-6.2.6.tar.gz
# 官方地址
# wget https://download.redis.io/releases/redis-6.2.6.tar.gz
# 解压并移动到 /opt
tar xzf redis-6.2.6.tar.gz
mv redis-6.2.6 /opt/redis

二、编译安装#

# 安装编译依赖
yum -y install gcc automake autoconf libtool make
# 进入目录并编译
cd /opt/redis
make MALLOC=libc
# 安装到指定目录
make install PREFIX=/opt/redis
# 验证启动
./bin/redis-server redis.conf

三、修改配置文件#

编辑 /opt/redis/redis.conf

设置访问密码(第 901 行附近)

/opt/redis/redis.conf
requirepass your_password

允许外部访问(第 75 行附近)

/opt/redis/redis.conf
bind 0.0.0.0

设置后台运行(第 257 行附近)

/opt/redis/redis.conf
daemonize yes

四、注册 Systemd 服务#

创建服务文件:

/etc/systemd/system/redis.service
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/opt/redis/bin/redis-server /opt/redis/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target

服务操作命令:

# 重载 systemd 配置
systemctl daemon-reload
# 启动
systemctl start redis
# 停止
systemctl stop redis
# 重启
systemctl restart redis
# 查看状态
systemctl status redis
# 开机自启
systemctl enable redis
# 确认进程是否运行
ps -ef | grep redis
分享

如果这篇文章对你有帮助,欢迎分享给更多人!

CentOS 编译安装 Redis 6.2 并配置 Systemd 服务
https://blog.olinl.com/posts/centos-redis-install/
作者
顾拾柒
发布于
2026-01-14
许可协议
CC BY-NC-SA 4.0

目录