我最近轉移到 Debian 8“Jessie”,它現在使用 systemd,但我找不到運行多個 Redis 實例的方法。
我發現有一個/lib/systemd/system/redis-server.service
檔案可以在重新啟動時啟動redis-server。所以我創建了一個/lib/systemd/system/redis-server-2.service
包含以下內容的新檔案呼叫:
[Unit]
Description=Advanced key-value store
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/redis-server /etc/redis/redis-2.conf
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
[Install]
WantedBy=multi-user.target
但是當我嘗試像這樣啟動服務時:service redis-server-2 start
我收到此錯誤:
Job for redis-server-2.service failed. See 'systemctl status redis-server-2.service' and 'journalctl -xn' for details.
並systemctl status redis-server-2.service
給我:
● redis-server-2.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server-2.service; disabled)
Active: failed (Result: start-limit) since Sat 2015-10-10 11:09:54 CEST; 33s ago
Process: 2473 ExecStart=/usr/bin/redis-server /etc/redis/redis-2.conf (code=exited, status=1/FAILURE)
Main PID: 2371 (code=exited, status=1/FAILURE)
Oct 10 11:09:54 server101 systemd[1]: redis-server-2.service: control process exited, code=exited status=1
Oct 10 11:09:54 server101 systemd[1]: Failed to start Advanced key-value store.
Oct 10 11:09:54 server101 systemd[1]: Unit redis-server-2.service entered failed state.
Oct 10 11:09:54 server101 systemd[1]: redis-server-2.service start request repeated too quickly, refusing to start.
Oct 10 11:09:54 server101 systemd[1]: Failed to start Advanced key-value store.
Oct 10 11:09:54 server101 systemd[1]: Unit redis-server-2.service entered failed state.
這並沒有真正幫助我。
但是如果我運行/usr/bin/redis-server /etc/redis/redis-2.conf
我的 redis 實例就可以正確啟動。
那你知道為什麼 systemd 不自己啟動這個實例嗎?
先謝謝您的幫忙。
答案1
正如邁克爾漢普頓(Michael Hampton)的建議,我檢查了系統日誌,發現:
Oct 10 11:33:46 server101 redis-server[1947]: *** FATAL CONFIG FILE ERROR ***
Oct 10 11:33:46 server101 redis-server[1947]: Reading the configuration file, at line 5
Oct 10 11:33:46 server101 redis-server[1947]: >>> 'logfile /var/log/redis/redis-server-2.log'
Oct 10 11:33:46 server101 redis-server[1947]: Can't open the log file: Permission denied
所以我只需要這樣做來解決這個問題:
chown redis:redis /var/log/redis/redis-server-2.log