创建 redis.service
cd /usr/lib/systemd/system
touch redis.service
vim redis.service
[Unit]
Description=Redis Server
After=network.target
[Service]
# pid文件和redis配置设置的pid一致
PIDFile=/var/run/redis_6379.pid
# redis-server路径和配置文件
ExecStart=/var/local/redis-5.0.7/src/redis-server /etc/redis.conf
# redis-cli
# ExecStop=/var/local/redis-5.0.7/src/redis-cli -a password shutdown
ExecStop=/bin/kill -s QUIT $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID
[Install]
WantedBy=mutli-user.target
编辑完后保存
systemctl enable redis.service //加入开机启动,先执行这个
systemctl start redis //开启redis服务
systemctl status redis //查看redis运行状态