Redis 僅在啟動時失敗
每次我啟動我們的 CentOS 7/openvas 伺服器時,Redis 都無法啟動。伺服器啟動後,我可以手動啟動 redis,使用
systemctl start redis.service
.以下是來自的相關部分
journalctl
Jan 29 06:29:28 openvas01 systemd[1]: Reached target Network is Online. Jan 29 06:29:28 openvas01 systemd[1]: Starting Network is Online. Jan 29 06:29:28 openvas01 systemd[1]: Started Azure Linux Agent. Jan 29 06:29:28 openvas01 systemd[853]: Failed at step RUNTIME_DIRECTORY spawning /usr/bin/redis-server: File exists Jan 29 06:29:28 openvas01 systemd[1]: Starting Azure Linux Agent... Jan 29 06:29:28 openvas01 systemd[1]: Started DNS caching server.. Jan 29 06:29:28 openvas01 systemd[1]: Starting DNS caching server.... Jan 29 06:29:28 openvas01 systemd[1]: redis.service: main process exited, code=exited, status=233/RUNTIME_DIRECTORY Jan 29 06:29:28 openvas01 systemd[860]: Failed at step RUNTIME_DIRECTORY spawning /usr/libexec/redis-shutdown: File exists Jan 29 06:29:28 openvas01 systemd[1]: redis.service: control process exited, code=exited status=233 Jan 29 06:29:28 openvas01 systemd[1]: Failed to start Redis persistent key-value database. Jan 29 06:29:28 openvas01 systemd[1]: Unit redis.service entered failed state. Jan 29 06:29:28 openvas01 systemd[1]: redis.service failed.
我不知道它在抱怨哪個文件已經存在。
/var/log/redis/redis.log
沒有提及有關此啟動問題的任何內容,因此我認為這與 systemd 有關。我在網上搜尋並沒有找到任何明顯的解決方案。該服務未設置為作為守護程序啟動,我
supervised systemd
在 redis 配置文件中有。有任何想法嗎?
經過更多故障排除後,我發現該
/var/run/redis
目錄是由其他程序而不是 redissystemd
服務創建的。進一步的故障排除顯示,我們的伺服器管理員意外創建了在服務之前/etc/tmpfiles.d/redis.conf
創建/var/run/redis
目錄的目錄。刪除這個文件,其中只有這個目錄,解決了這個問題。
TL;DR:禁用 Redis 服務,重置,重新載入,然後重新啟動,最後重新啟用該服務。
在 Redis 從 Redis6 更新到 Redis7 之後,我在 CentOS7.9 (Virtuzzo) 上遇到了同樣的問題。我有幾個實例,每個單獨的網站都有 1 或 2 個,但我沒有意識到只有原始的 redis.service 已經關閉了將近一周,直到我在使用 status 命令後嘗試重新啟動它:
systemctl status -l redis.service redis.service - Redis persistent key-value database Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled) Drop-In: /etc/systemd/system/redis.service.d └─limit.conf Active: failed (Result: exit-code) since Thu 2022-05-05 23:02:50 BST; 28s ago Process: 6425 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --daemonize no --supervised systemd (code=exited, status=233/RUNTIME_DIRECTORY) Main PID: 6425 (code=exited, status=233/RUNTIME_DIRECTORY)
重新啟動我的實例(redis2、redis3 等)除了這個之外都有效。
Failed at step RUNTIME_DIRECTORY spawning /usr/bin/redis-server: File exists redis.service: main process exited, code=exited, status=233/RUNTIME_DIRECTORY Failed to start Redis persistent key-value database. Unit redis.service entered failed state. redis.service failed.
無需刪除任何文件或文件夾對我有用的是禁用 redis.service,然後使用 reset failed services 命令,重新載入 SystemD 守護程序,啟動 redis.service(現在第一次工作),然後重新啟用它所以它應該在將來自動重啟。
這些是命令,依次輸入每一行……
systemctl disable redis systemctl reset-failed systemctl daemon-reload systemctl start redis systemctl enable redis Outputs message: Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service. systemctl status -l redis.service Outputs message: redis.service - Redis persistent key-value database Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled) Drop-In: /etc/systemd/system/redis.service.d └─limit.conf Active: active (running) since Thu 2022-05-05 23:08:03 BST; 31s ago Main PID: 6899 (redis-server) Status: "Ready to accept connections" CGroup: /system.slice/redis.service └─6899 /usr/bin/redis-server 127.0.0.1:6379 /var/lib/redis/redis.sock 6379 /etc/redis/redis.conf Starting Redis persistent key-value database... Started Redis persistent key-value database.