Ubuntu

Redis 不是從 systemctl 開始的

  • December 13, 2020

我已經在 ubuntu 16.04 機器上安裝了 redis,如果我執行/usr/local/bin/redis-server /etc/redis/cluster/7000/redis.conf它就會啟動,我可以毫無問題地連接到它。

但是我想使用它來啟動它systemctl start redis,所以我創建了以下文件/etc/systemd/system/redis7000.service

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/cluster/7000/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

並且 redis 配置已supervised systemd設置

我認為這看起來不錯,但我收到以下錯誤:

Jan 19 14:54:27 ip-172-31-42-18 systemd[1]: Started Redis In-Memory Data Store.
Jan 19 14:54:27 ip-172-31-42-18 redis-server[21661]: 21661:C 19 Jan 14:54:27.680 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
Jan 19 14:54:27 ip-172-31-42-18 redis-server[21661]: 21661:C 19 Jan 14:54:27.680 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=21661, just started
Jan 19 14:54:27 ip-172-31-42-18 redis-server[21661]: 21661:C 19 Jan 14:54:27.680 # Configuration loaded
Jan 19 14:54:27 ip-172-31-42-18 redis-server[21661]: 21661:C 19 Jan 14:54:27.680 # systemd supervision requested, but NOTIFY_SOCKET not found
Jan 19 14:54:27 ip-172-31-42-18 systemd[1]: redis7000.service: Main process exited, code=exited, status=1/FAILURE
Jan 19 14:54:27 ip-172-31-42-18 systemd[1]: redis7000.service: Unit entered failed state.
Jan 19 14:54:27 ip-172-31-42-18 systemd[1]: redis7000.service: Failed with result 'exit-code'.
Jan 19 14:54:27 ip-172-31-42-18 systemd[1]: redis7000.service: Service hold-off time over, scheduling restart.
Jan 19 14:54:27 ip-172-31-42-18 systemd[1]: Stopped Redis In-Memory Data Store.

而且我什至不確定這意味著什麼,所以有人可以指導我正確的方向嗎?

要在 systemd 下執行 redis,需要設置supervised systemd.

查看配置文件:

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.
supervised no

需要改為:

supervised systemd

您也可以在命令行上傳遞它,它會覆蓋redis.conf. 基於 Red Hat 的系統可以做到這一點。這也允許在不更改配置文件的情況下手動或從 systemd 執行相同的 redis 實例。

ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd

此外,您還需要通過Type=notify在該[Service]部分中的設置告訴 systemd redis 將在此模式下執行。

引用自:https://serverfault.com/questions/893066