如何使用 systemd 运行多个 redis 实例

如何使用 systemd 运行多个 redis 实例

我最近转到了 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

相关内容