supervised systemd
在 Ubuntu Server 20.04 上,设置后 Redis (5.0.7) 无法启动/etc/redis/redis.conf
,但使用 手动运行它时不会打印任何错误/usr/bin/redis-server /etc/redis/redis.conf
。
另外,手动运行时,可能会发现它正在监听端口 6379 netstat -tulpn
。
复制
以 root 身份:
- 使用以下方法更新软件包并安装 Redis
apt update && apt install redis-server
- 在上
/etc/redis/redis.conf
,将行更改supervised no
为supervised systemd
- 尝试使用
service redis-server restart
或重新启动 Redissystemctl restart redis
上述命令的输出是:
Job for redis-server.service failed because the control process exited with error code.
See "systemctl status redis-server.service" and "journalctl -xe" for details.
输出为systemctl status redis-server.service
:
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-02-03 12:15:56 -03; 28s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 3851 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=1/FAILURE)
Feb 03 12:15:56 mywebsite.com systemd[1]: redis-server.service: Scheduled restart job, restart counter is at 5.
Feb 03 12:15:56 mywebsite.com systemd[1]: Stopped Advanced key-value store.
Feb 03 12:15:56 mywebsite.com systemd[1]: redis-server.service: Start request repeated too quickly.
Feb 03 12:15:56 mywebsite.com systemd[1]: redis-server.service: Failed with result 'exit-code'.
Feb 03 12:15:56 mywebsite.com systemd[1]: Failed to start Advanced key-value store.
尝试重新启动 Redis 服务时没有打印任何日志/var/log/redis/redis-server.log
,但手动运行时会打印以下文本:
4231:C 03 Feb 2021 12:27:52.053 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
4231:C 03 Feb 2021 12:27:52.053 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=4231, just started
4231:C 03 Feb 2021 12:27:52.053 # Configuration loaded
4232:M 03 Feb 2021 12:27:52.063 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.7 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 4232
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
4232:M 03 Feb 2021 12:27:52.065 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
4232:M 03 Feb 2021 12:27:52.065 # Server initialized
4232:M 03 Feb 2021 12:27:52.066 * Ready to accept connections
软件版本:
Redis 服务器 v=5.0.7 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=636cde3b5c7a3923
Ubuntu 20.04.2 LTS - 64 位
systemd 245(245.4-4ubuntu3.4)
答案1
这很奇怪,但是 Ubuntu 安装 redis-server才不是使用 redis 与 systemd 通信的能力。在此平台上,您应保留 redis.conf 的设置,就像它出厂时一样:supervised no
。
如果你真的如果由于某种原因想要启用此功能,则必须自定义 systemd 单元,例如:
ubuntu@vmtest-ubuntu2004:~$ sudo systemctl edit redis-server.service
在 nano 中,你应该只添加以下内容:
[Service]
Type=notify
然后告诉 systemd 加载更改。
ubuntu@vmtest-ubuntu2004:~$ sudo systemctl daemon-reload
现在您需要编辑 redis.conf:
ubuntu@vmtest-ubuntu2004:~$ sudo nano /etc/redis/redis.conf
并进行以下更改:
daemonize no
supervised systemd
现在可以重新启动 redis-server:
ubuntu@vmtest-ubuntu2004:~$ sudo systemctl start redis-server
ubuntu@vmtest-ubuntu2004:~$ sudo systemctl status redis-server
* redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/redis-server.service.d
`-override.conf
Active: active (running) since Wed 2021-02-03 11:55:09 EST; 1min 8s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 1768 (redis-server)
Tasks: 4 (limit: 2318)
Memory: 1.8M
CGroup: /system.slice/redis-server.service
`-1768 /usr/bin/redis-server 127.0.0.1:6379
Feb 03 11:55:09 vmtest-ubuntu2004 systemd[1]: Starting Advanced key-value store...
Feb 03 11:55:09 vmtest-ubuntu2004 systemd[1]: Started Advanced key-value store.
答案2
sudo systemctl start redis.service
首次使用