重启redis服务时报错:Failed to start redis.service: Unit not found
redis配合安全修改了bind和auth配置,重启的时候报错了,试了很多方法,最后才通过日志解决了
1 重新加载systemd 配置并启动:
sudo systemctl daemon-reload
sudo systemctl start redis
powershell
> sudo systemctl daemon-reload
> sudo systemctl start redis
Failed to start redis.service: Unit not found.
2 查看当前redis状态
sudo systemctl status redis
bash
> sudo systemctl status redis
● redis.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/redis.service.d
└─limit.conf
Active: failed (Result: exit-code) since Thu 2024-08-08 18:01:26 CST; 16h ago
Process: 2375 ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd (code=exited, status=1/FAILURE)
Main PID: 2375 (code=exited, status=1/FAILURE)
Aug 08 18:01:26 yangxiuqing-linux.bcc-bdbl.baidu.com systemd[1]: Starting Redis persistent key-value database...
Aug 08 18:01:26 yangxiuqing-linux.bcc-bdbl.baidu.com systemd[1]: Started Redis persistent key-value database.
Aug 08 18:01:26 yangxiuqing-linux.bcc-bdbl.baidu.com systemd[1]: redis.service: main process exited, code=exited, status=1/FAILURE
Aug 08 18:01:26 yangxiuqing-linux.bcc-bdbl.baidu.com systemd[1]: Unit redis.service entered failed state.
Aug 08 18:01:26 yangxiuqing-linux.bcc-bdbl.baidu.com systemd[1]: redis.service failed.
3 发现是失败的,接着看下日志
cat /var/log/redis/redis.log
bash
> cat /var/log/redis/redis.log
25420:C 08 Aug 17:53:45.282 * supervised by systemd, will signal readiness
25420:M 08 Aug 17:53:45.283 # Creating Server TCP listening socket 127.0.0.1:6379: bind: Address already in use
2101:M 08 Aug 18:01:11.325 # Creating Server TCP listening socket 127.0.0.1:6379: bind: Address already in use
2375:C 08 Aug 18:01:26.974 * supervised by systemd, will signal readiness
2375:M 08 Aug 18:01:26.975 # Creating Server TCP listening socket 127.0.0.1:6379: bind: Address already in use
错误信息 "Creating Server TCP listening socket 127.0.0.1:6379: bind: Address already in use" 表明 Redis 试图绑定到本地地址 127.0.0.1:6379,但该端口已经被其他进程占用。可以按照以下步骤来解决这个问题:
bash
> sudo lsof -i :6379
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
redis-ser 2407 root 6u IPv4 391104235 0t0 TCP *:6379 (LISTEN)
> sudo kill 2407
杀掉原进程 再次重启并观察状态
bash
> sudo systemctl daemon-reload
> sudo systemctl start redis
> sudo systemctl status redis
查看状态
bash
● redis.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/redis.service.d
└─limit.conf
Active: active (running) since Fri 2024-08-09 10:16:07 CST; 8s ago
Main PID: 21028 (redis-server)
CGroup: /system.slice/redis.service
└─21028 /usr/bin/redis-server 127.0.0.1:6379
Aug 09 10:16:07 yangxiuqing-linux.bcc-bdbl.baidu.com systemd[1]: Starting Redis persistent key-value database...
Aug 09 10:16:07 yangxiuqing-linux.bcc-bdbl.baidu.com systemd[1]: Started Redis persistent key-value database.
成功了!
在Linux系统中使用nano
文本编辑器时,保存文件并退出操作步骤
1 保存:按下 Ctrl + O
(即 Control 键和字母O键同时按)
2 确认文件名:如果不需要改变文件名,按 Enter
键确认
3 退出:按下 Ctrl + X
(即 Control 键和字母X键同时按)