Systemd:Redis 服务器作为服务运行时无法启动 - 符号链接级别过多

Systemd:Redis 服务器作为服务运行时无法启动 - 符号链接级别过多

我最近遇到了这个问题。我已经安装了 Debian 9 作为 Web 服务器(带有 nginx、php7.0-fpm 和其他一些东西),我想在我的 PHP 安装中使用 redis。从官方存储库安装时,软件包安装正常,但 systemd 单元无法启动或启用。当我尝试手动从单元文件中运行“ExecStart”命令时,redis 启动正常并可运行。

这是单元文件(由 Debian 包提供,我没有做任何修改):

[Unit]
Description=Advanced key-value store
After=network.target
Documentation=http://redis.io/documentation, man:redis-server(1)

[Service]
Type=forking
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
PIDFile=/var/run/redis/redis-server.pid
TimeoutStopSec=0
User=redis
Group=redis
RunTimeDirectory=redis

ExecStartPre=-/bin/run-parts --verbose /etc/redis/redis-server.pre-up.d
ExecStartPost=-/bin/run-parts --verbose /etc/redis/redis-server.post-up.d
ExecStop=-/bin/run-parts --verbose /etc/redis/redis-server.pre-down.d
ExecStop=/bin/kill -s TERM $MAINPID
ExecStopPost=-/bin/run-parts --verbose /etc/redis/redis-server.post-down.d

UMask=007
PrivateTmp=yes
LimitNOFILE=65535
PrivateDevices=yes
ProtectHome=yes
ReadOnlyDirectories=/
ReadWriteDirectories=-/var/lib/redis
ReadWriteDirectories=-/var/log/redis
ReadWriteDirectories=-/var/run/redis
CapabilityBoundingSet=~CAP_SYS_PTRACE

# redis-server writes its own config file when in cluster mode so we allow
# writing there (NB. ProtectSystem=true over ProtectSystem=full)
ProtectSystem=true
ReadWriteDirectories=-/etc/redis

[Install]
WantedBy=multi-user.target
Alias=redis.service

运行“systemctl start redis”后,以下是 journalctl -xe 的输出:

-- Subject: Unit redis-server.service has begun start-up
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- Unit redis-server.service has begun starting up.
Aug 16 10:39:05 hathor systemd[9337]: redis-server.service: Failed at step NAMESPACE spawning /bin/run-parts: Too many levels of symbolic links
-- Subject: Process /bin/run-parts could not be executed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- The process /bin/run-parts could not be executed and failed.
-- 
-- The error number returned by this process is 40.
Aug 16 10:39:05 hathor systemd[9340]: redis-server.service: Failed at step NAMESPACE spawning /usr/bin/redis-server: Too many levels of symbolic links
-- Subject: Process /usr/bin/redis-server could not be executed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- The process /usr/bin/redis-server could not be executed and failed.
-- 
-- The error number returned by this process is 40.
Aug 16 10:39:05 hathor systemd[1]: redis-server.service: Control process exited, code=exited status=226
Aug 16 10:39:05 hathor systemd[1]: Failed to start Advanced key-value store.
-- Subject: Unit redis-server.service has failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- Unit redis-server.service has failed.
-- 
-- The result is failed.
Aug 16 10:39:05 hathor systemd[1]: redis-server.service: Unit entered failed state.
Aug 16 10:39:05 hathor systemd[1]: redis-server.service: Failed with result 'exit-code'.

下面是“systemctl enable redis”给出的错误消息,对我来说是最神秘的:

root /lib/systemd/system $ systemctl enable redis
Failed to enable unit: Refusing to operate on linked unit file redis.service

root /lib/systemd/system $ systemctl enable redis-server
Synchronizing state of redis-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable redis-server

该单元文件不是符号链接,它是一个常规文件:

-rw-r--r--  1 root root 1.2K Aug 16 10:32 redis-server.service

/etc/、/var/run 中没有符号链接或挂载点。此服务器上的 /mnt/backup 中只有一个挂载点。我还应该提到,此服务器是 OpenVZ 主机上的 VPS。Systemd 版本为 232,Debian 已完全升级到最新版本的软件包,内核为 3.16.6-042stab123.8。

提前感谢任何建议!谢谢,Johny

答案1

该单元文件不是符号链接,它是一个常规文件:

-rw-r--r-- 1 root root 1.2K Aug 16 10:32 redis-server.service

您正在检查错误的文件。错误消息是关于 的redis.service。请检查它是否是符号链接。

顺便说一下,包文件列表没有提到该redis.service文件。它真的在那里吗?或者你自己创建了它?

在任何情况下,当 systemd 拒绝对符号链接执行“启用”时,启用单元文件按路径可能会起作用:

$ sudo systemctl enable /lib/systemd/system/redis-server.service

答案2

这个问题似乎在这里讨论https://github.com/systemd/systemd/issues/6318。systemd 232 中有一个错误,似乎可以通过在单元文件中将“ReadWriteDirectories=-/var/run/redis”更改为“ReadWriteDirectories=-/run/redis”来修复。

答案3

问题简单地说就是您使用的是名称redis而不是实际名称redis-server

显然,这个redis名字是别名,以使事情变得更容易,但正如您所说,还存在其他问题。

systemctl redis-server start

这将正确启动它:

root@luna:# service redis-server status
● redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Fri 2021-09-03 11:48:50 CDT; 4s ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
    Process: 986762 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
   Main PID: 986779 (code=exited, status=0/SUCCESS)

Sep 03 11:48:17 luna systemd[1]: Starting Advanced key-value store...
Sep 03 11:48:17 luna systemd[1]: redis-server.service: Can't open PID file /run/redis/redis-server.pid (yet?) after start: Op>
Sep 03 11:48:17 luna systemd[1]: Started Advanced key-value store.
Sep 03 11:48:50 luna systemd[1]: Stopping Advanced key-value store...
Sep 03 11:48:50 luna systemd[1]: redis-server.service: Succeeded.
Sep 03 11:48:50 luna systemd[1]: Stopped Advanced key-value store.

要使服务在启动时运行:

systemctl redis-server enable

相关内容