【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

相关推荐
计算机毕设VX:Fegn08959 分钟前
计算机毕业设计|基于springboot + vue动物园管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
冉冰学姐32 分钟前
SSM校园排球联赛管理系统y513u(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面
数据库·ssm 框架应用·开题报告、
Tony Bai1 小时前
【分布式系统】03 复制(上):“权威中心”的秩序 —— 主从架构、一致性与权衡
大数据·数据库·分布式·架构
wb043072012 小时前
SQL工坊不只是一个ORM框架
数据库·sql
至善迎风2 小时前
Redis完全指南:从诞生到实战
数据库·redis·缓存
QQ_4376643144 小时前
Redis协议与异步方式
数据库·redis·bootstrap
纪莫4 小时前
技术面:MySQL篇(InnoDB事务执行过程、事务隔离级别、事务并发异常)
数据库·java面试⑧股
Nerd Nirvana4 小时前
数据库模型全景:从原理到实践的系统性指南
数据库·oracle·电力行业
SelectDB4 小时前
从 Greenplum 到 Doris:集群缩减 2/3、年省数百万,度小满构建超大规模数据分析平台经验
数据库·数据分析·apache
alonewolf_995 小时前
MySQL索引优化实战二:分页、关联查询与Count优化深度解析
数据库·mysql