【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

相关推荐
Traced back几秒前
SQL Server 核心语法+进阶知识点大全(小白版)
数据库·sqlserver
资深web全栈开发5 分钟前
PostgreSQL枚举还是字符串:ENUM vs VARCHAR + CHECK 的权衡
数据库·postgresql
凯子坚持 c18 分钟前
C++基于微服务脚手架的视频点播系统---客户端(4)
数据库·c++·微服务
OceanBase数据库官方博客24 分钟前
OceanBase场景解码系列三|OB Cloud 如何稳定支撑中企出海实现数 10 倍的高速增长?
数据库·oceanbase·分布式数据库
m0_5613596734 分钟前
使用Python处理计算机图形学(PIL/Pillow)
jvm·数据库·python
山岚的运维笔记38 分钟前
SQL Server笔记 -- 第14章:CASE语句
数据库·笔记·sql·microsoft·sqlserver
Data_Journal44 分钟前
如何使用 Python 解析 JSON 数据
大数据·开发语言·前端·数据库·人工智能·php
ASS-ASH1 小时前
AI时代之向量数据库概览
数据库·人工智能·python·llm·embedding·向量数据库·vlm
xixixi777771 小时前
互联网和数据分析中的核心指标 DAU (日活跃用户数)
大数据·网络·数据库·数据·dau·mau·留存率
乔江seven1 小时前
【Flask 进阶】3 从同步到异步:基于 Redis 任务队列解决 API 高并发与长耗时任务阻塞
redis·python·flask