创建service文件
vi /usr/lib/systemd/system/redis.service
[Unit]
Description = redis
After = network.target syslog.target
Wants = network.target
[Service]
Type = simple
WorkingDirectory = /opt/Redis-6.2.1
Restart = always
ExecStart = /opt/Redis-6.2.1/redis-server /root/RedisData/redis-conf.conf
ExecStop = kill -9 $(pidof redis-server)
ExecReload = kill -9 $(pidof redis-server) && /opt/Redis-6.2.1/redis-server /root/RedisData/redis-conf.conf
[Install]
WantedBy = multi-user.target
创建软连接
ln -s /usr/lib/systemd/system/redis.service /etc/systemd/system/
启动服务
systemctl daemon-reload //重新加载
systemctl start redis.service //启动服务
systemctl enable redis.service //添加自启动
systemctl status redis.service //查看状态