我想通过 systemd 启动 3 个 Redis 6 实例。系统信息:
root@ubnt:/home/test11# uname -a Linux ubnt 4.15.0-88-generic #88-Ubuntu
SMP Tue Feb 11 20:11:34 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
root@ubnt:/home/test11# lsb_release -a No LSB modules are available.
Distributor ID: Ubuntu Description: Ubuntu 18.04.4 LTS Release:
18.04 Codename: bionic
我创建了服务 /lib/systemd/system/redis_server_7000.service,内容如下:
[Unit]
Description=Redis data structure server - instance 7000
Documentation=https://redis.io/documentation
After=network.target
[Service]
ExecStart=/etc/redis/redis-server /etc/redis/redis_7000.conf
ExecStop=/etc/redis/redis-cli -p 7000 shutdown
Restart=always
LimitNOFILE=65000
NoNewPrivileges=yes
Type=notify
UMask=0077
User=redis
Group=redis
[Install]
WantedBy=multi-user.target
并且它解决了问题。它启动了 Redis 实例,但因超时而失败
root@ubnt:/home/test11# ps -aux | grep redis
redis 30468 0.4 0.5 64320 5616 ? Ssl 11:15 0:00 /etc/redis/redis-server 127.0.0.1:7000 [cluster]
Feb 29 11:09:55 ubnt systemd[1]: redis_server_7000.service: Start operation timed out. Terminating.
Feb 29 11:09:55 ubnt systemd[1]: redis_server_7000.service: Failed with result 'timeout'.
Feb 29 11:09:55 ubnt systemd[1]: Failed to start Redis data structure server - instance 7000.
root@ubnt:/home/test11# systemctl status redis_server_7000.service
● redis_server_7000.service - Redis data structure server - instance 7000
Loaded: loaded (/lib/systemd/system/redis_server_7000.service; enabled; vendor preset: enabled)
Active: activating (start) since Sat 2020-02-29 11:28:03 UTC; 12s ago
Docs: https://redis.io/documentation
Main PID: 30679 (redis-server)
Tasks: 5 (limit: 1108)
CGroup: /system.slice/redis_server_7000.service
└─30679 /etc/redis/redis-server 127.0.0.1:7000 [cluster]
Feb 29 11:28:03 ubnt systemd[1]: Starting Redis data structure server - instance 7000...
Redis 配置文件:
root@ubnt:/home/test11# cat /etc/redis/redis_7000.conf
#daemonize yes
maxmemory 2G
maxmemory-policy volatile-ttl
dir /var/lib/redis_7000
loglevel notice
supervised systemd
tcp-backlog 1000
bind 127.0.0.1
pidfile /var/run/redis_7000.pid
logfile /var/log/redis/redis-server-7000.log
port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
我检查了 systemd 服务的类型:
I checked types of systemd units simple - A long-running process that does not background its self and stays attached to the shell.
forking - A typical daemon that forks itself detaching it from the process that ran it, effectively backgrounding itself.
oneshot - A short-lived process that is expected to exit.
dbus - Like simple, but notification of processes startup finishing is sent over dbus.
notify - Like simple, but notification of processes startup finishing is sent over inotify.
idle - Like simple, but the binary is started after the job has been dispatched.
我使用了通知类型,但看起来 redis 已经启动了,但没有向 systemd 发送通知。
所以我的问题是:-如何更改服务文件以正确启动一个实例?-是否可以从一个服务文件运行 3 个 Redis 实例?或者最好创建 3 个单独的文件?