redis 设置了 bind 后开机自启动报错
虚拟机中安装的redis
,在配置文件中设置了 bind
,开机自启动时遇到:
[root@localhost ~]# tail -f /var/log/redis/redis.log
849:C 18 Apr 2024 07:18:49.475 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
849:C 18 Apr 2024 07:18:49.476 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=849, just started
849:C 18 Apr 2024 07:18:49.476 # Configuration loaded
849:C 18 Apr 2024 07:18:49.476 * supervised by systemd, will signal readiness
849:M 18 Apr 2024 07:18:49.479 # Could not create server TCP listening socket 192.168.133.130:6379: bind: Cannot assign requested address
849:M 18 Apr 2024 07:18:49.479 # Configured to not listen anywhere, exiting.
redis
服务的 systemd
脚本中,After
默认指定的是 network.target
,将其改为 network-online.target
network.target
是一个系统级别的目标,它代表着网络服务已经启动并准备好提供服务。它是网络服务的默认目标,也是多数网络服务所依赖的目标。
network-online.target
是一个延伸的系统级别的目标,它代表着网络连接已经建立,并且可以提供 Internet 访问。它可以被用来作为其他服务的依赖,以确保这些服务在网络连接已经建立之后再启动。
[Unit]
Description=Redis persistent key-value database
#After=network.target
After=network-online.target
[Service]
ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd
ExecStop=/usr/libexec/redis-shutdown
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl start redis
Warning: The unit file, source configuration file or drop-ins of redis.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[root@localhost ~]#
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start redis
参考文章:
network.target vs network-online.target
标签:target,bind,redis,849,2024,报错,18,自启动,network From: https://www.cnblogs.com/zhpj/p/18144312/redis-set-up-bind-and-start-self-starting-an-error