在CentOS系统中,要设置Redis自动重启,您可以使用systemd服务来实现。请按照以下步骤操作:
sudo yum install epel-release
sudo yum install redis
sudo vi /etc/systemd/system/redis.service
[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
User=redis
Group=redis
ExecStart=/usr/bin/redis-server /etc/redis.conf
ExecStop=/usr/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
这里,我们指定了Redis服务在网络启动后运行,并设置了自动重启(Restart=always)。同时,我们指定了Redis服务的用户和组(默认为redis),以及启动和停止命令。
保存并关闭文件。
重新加载systemd配置:
sudo systemctl daemon-reload
sudo systemctl enable redis.service
sudo systemctl start redis.service
sudo systemctl stop redis.service
sudo systemctl status redis.service
至此,您已经成功设置了CentOS系统中Redis的自动重启。