在 Debian 10 机器上,我只需输入
redis-server
即可启动 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'.
这里可能出了什么问题,我该如何解决这个问题?
好吧,我意识到这是由于
redis.conf
上的权限问题造成的。
当 chown -R redis:redis /etc/redis/redis.conf
问题就消失了。
希望这也能帮助其他人。
我必须将 Redis 用户和组更改为
root
,在服务中为了使其工作,它被设置为 redis
并且无法工作
nano /usr/lib/systemd/system/redis.service
User=root
Group=root