0

在 Debian 10 机器上,我只需键入redis-server. 但是我想将它作为守护进程运行。我可以看到/etc/systemd/system它的符号链接如下:

lrwxrwxrwx 1 root root 40 Sep 12 2019 redis.service -> /lib/systemd/system/redis-server.service

/lib/systemd/system/redis-server.service我有:

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

[Service]
#Type=forking
Type=notify
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
PIDFile=/var/run/redis/redis-server.pid
TimeoutStopSec=0
Restart=always
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

但是,当我从终端杀死redis-server运行良好的终端并尝试使用启动服务时,systemctl start redis出现此错误:

● redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2021-01-26 11:03:50 CST; 10s ago
     Docs: http://redis.io/documentation,
           man:redis-server(1)
  Process: 29998 ExecStopPost=/bin/run-parts --verbose /etc/redis/redis-server.post-down.d (code=exited, status=0/SUCCESS)
  Process: 29995 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=1/FAILURE)
  Process: 29992 ExecStop=/bin/run-parts --verbose /etc/redis/redis-server.pre-down.d (code=exited, status=0/SUCCESS)
  Process: 29989 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=1/FAILURE)
  Process: 29986 ExecStartPre=/bin/run-parts --verbose /etc/redis/redis-server.pre-up.d (code=exited, status=0/SUCCESS)
 Main PID: 29989 (code=exited, status=1/FAILURE)
      CPU: 22ms

Jan 26 11:03:49 front systemd[1]: redis-server.service: Unit entered failed state.
Jan 26 11:03:49 front systemd[1]: redis-server.service: Failed with result 'exit-code'.
Jan 26 11:03:50 front systemd[1]: redis-server.service: Service hold-off time over, scheduling restart.
Jan 26 11:03:50 front systemd[1]: Stopped Advanced key-value store.
Jan 26 11:03:50 front systemd[1]: redis-server.service: Start request repeated too quickly.
Jan 26 11:03:50 front systemd[1]: Failed to start Advanced key-value store.
Jan 26 11:03:50 front systemd[1]: redis-server.service: Unit entered failed state.
Jan 26 11:03:50 front systemd[1]: redis-server.service: Failed with result 'exit-code'.

这里可能有什么问题,我该如何解决?

4

1 回答 1

0

好吧,我意识到这是由于redis.conf. 当chown -R redis:redis /etc/redis/redis.conf问题消失时。

希望这也可以帮助其他人。

于 2021-01-26T17:43:48.480 回答