【Redis】centos7 systemctl 启动 Redis 失败

今天启动 Redis 时阻塞很长时间,之后显示启动失败,启动状态如下。

  1. systemd[1]: redis.service start operation timed out. Terminating.

  2. systemd[1]: Failed to start A persistent key-value database.

  3. systemd[1]: Unit redis.service entered failed state.

看了下 service 文件,发现 Systemd 启动命令如下

复制代码
ExecStart=/usr/sbin/redis-server /etc/redis.conf

手动运行这条命令,发现是正常的,所以猜想是 service 文件的问题,后来发现只需要把 Service 部分的Type=forking注释掉就行了。

  1. [Service]

  2. # Type=forking

  3. # PIDFile=/var/run/redis/redis.pid

  4. ExecStart=/usr/sbin/redis-server /etc/redis.conf

  5. User=redis

  6. Group=redis

之后重新加载 Service 文件并启动 Redis 服务

复制代码
sudo systemctl daemon-reload

sudo systemctl start redis

Man pages 对 Systemd 服务启动类型 Type 的解释如下

复制代码
If set to forking, it is expected that the process configured with ExecStart= will call fork() as part of its start-up. The parent process is expected to exit when start-up is complete and all communication channels are set up. The child continues to run as the main daemon process. This is the behavior of traditional UNIX daemons. If this setting is used, it is recommended to also use the PIDFile= option, so that systemd can identify the main process of the daemon. systemd will proceed with starting follow-up units as soon as the parent process exits.

因为 Redis 配置文件里配置的是
daemonize no

相关推荐
hweiyu0014 分钟前
Redis命令:LPOS
redis·缓存
guo_wen_qiang20 分钟前
云服务器redis主从复制-哨兵模式
运维·服务器·redis
架构师伯子明22 分钟前
QT+Opengl (1):渲染一个三角形
数据库
for_ever_love__26 分钟前
LangGraph State 设计:多节点之间怎么安全地共享数据
redis·mysql·状态模式·checkpoint·state·状态图·langgraph
A-刘晨阳28 分钟前
金仓时序数据库:以高效压缩、快速写入与时序优化,破解工业海量数据管理难题
数据库·时序数据库
2603_9651481129 分钟前
终极清单:构建自动化选品比价系统的所有组件与资源
大数据·运维·数据库·数据挖掘·自动化
打工仔折腾 AI41 分钟前
SQL 编辑器不是高级记事本:KStudio 与 KSQL Developer 的建表与增删改查手法
数据库·人工智能·后端·python·sql·编辑器·ai agent 实战
CNSSIRD数据库1 小时前
中国省地县乡四级行政建制及区划代码-2025年版
大数据·数据库·数据分析·论文笔记
for_ever_love__1 小时前
LangGraph Checkpointer:持久化、断点续跑与多轮记忆
服务器·数据库·学习·持久化·langgraph·checkpointer·断点续跑
Data analyse4561 小时前
用户路径SQL按会话起止时间聚合的方法
大数据·服务器·前端·数据库·人工智能·sql·数据分析