1、创建服务文件:
sudo vim /lib/systemd/system/redis.service
2、redis.service文件写入以下内容
[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli -a 123456 shutdown
User=root
Restart=always
[Install]
WantedBy=multi-user.target
3、重载配置并设置自启
sudo systemctl daemon-reload
sudo systemctl enable redis
sudo systemctl start redis
4、验证
sudo sytemctl status redis