温馨提示×

centos如何启动redis

小樊
44
2026-07-08 07:05:07
栏目: 云计算

CentOS 上启动 Redis,常见有以下几种方式,按使用场景说明(以 CentOS 7/8 为主,Redis 3.x/5.x/6.x 通用)。


一、使用 systemd 启动(推荐 ✅)

1️⃣ 查看 Redis 服务名

常见服务名:

redis
redis-server

查看:

systemctl list-unit-files | grep redis

2️⃣ 启动 Redis

sudo systemctl start redis

或(如果服务名不同):

sudo systemctl start redis-server

3️⃣ 设置开机自启

sudo systemctl enable redis

4️⃣ 查看 Redis 状态

sudo systemctl status redis

正常应看到:

Active: active (running)

二、使用 redis-server 直接启动(不推荐生产)

1️⃣ 前台启动

redis-server

2️⃣ 后台启动

redis-server --daemonize yes

⚠️ 这种方式 不会随系统启动


三、指定配置文件启动

1️⃣ 常见配置文件路径

/etc/redis.conf
/etc/redis/redis.conf

2️⃣ 启动命令

redis-server /etc/redis.conf

或 systemd 方式:

sudo systemctl start redis

四、验证 Redis 是否启动成功

1️⃣ 查看进程

ps -ef | grep redis

2️⃣ 使用 redis-cli 测试

redis-cli
127.0.0.1:6379> ping
PONG

五、常见问题排查

❌ Redis 启动失败

查看日志:

journalctl -u redis -xe

或:

tail -f /var/log/redis/redis.log

❌ 端口被占用

netstat -tunlp | grep 6379

❌ 配置文件问题

检查:

redis-server /etc/redis.conf --test-config

六、CentOS 6(老系统,不推荐)

service redis start
chkconfig redis on

✅ 推荐总结

场景 建议
CentOS 7/8 systemctl start redis
生产环境 使用 systemd + 配置文件
临时测试 redis-server --daemonize yes

如果你愿意,可以告诉我:

  • CentOS 版本(cat /etc/centos-release
  • Redis 安装方式(yum / 编译)

我可以给你 精确到命令级别 的启动方案 ✅

0