温馨提示×

centos怎样启动redis配置

小樊
33
2026-09-02 19:42:15
栏目: 云计算

在 CentOS 上启动 Redis 并加载配置文件,通常有以下几种方式,按使用场景说明:


一、使用 systemd 启动(推荐,CentOS 7+)

1. 安装 Redis

yum install epel-release -y
yum install redis -y

2. 修改配置文件(可选)

默认配置文件路径:

/etc/redis.conf

常见修改项:

bind 0.0.0.0          # 允许远程连接
protected-mode no     # 关闭保护模式(测试用)
requirepass 123456    # 设置密码
daemonize yes         # 后台运行

3. 启动 Redis

systemctl start redis

4. 设置开机自启

systemctl enable redis

5. 查看状态

systemctl status redis

二、手动指定配置文件启动(开发/调试常用)

1. 启动命令

redis-server /etc/redis.conf

2. 后台启动(如果配置中未设 daemonize)

redis-server /etc/redis.conf --daemonize yes

3. 连接测试

redis-cli

如果设置了密码:

redis-cli -a 123456

三、自定义配置启动(多实例)

例如新配置:

cp /etc/redis.conf /etc/redis-6380.conf
vim /etc/redis-6380.conf

修改:

port 6380
pidfile /var/run/redis_6380.pid
logfile /var/log/redis/redis-6380.log

启动:

redis-server /etc/redis-6380.conf

四、常见问题排查

Redis 启动失败

journalctl -xe
cat /var/log/redis/redis.log

端口未监听

netstat -lntp | grep 6379

总结

  • 生产环境:用 systemctl + /etc/redis.conf
  • 测试/多实例redis-server 指定配置文件

如果你是 CentOS 6源码安装 Redis,我也可以给你对应方式。

0