一、环境
centos7.6
redis-6.2.5
二、步骤
1、在 /lib/systemd/system 目录添加 nginx.service 文件
#进入自启文件目录 cd /lib/systemd/system #自定义nginx自启文件 touch redis.service
2、编辑redis.service
添加一下内容
[Unit] Description=redis-server After=network.target [Service] Type=forking ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf ExecStop=/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown PrivateTmp=true Restart=always [Install] WantedBy=multi-user.target
3、设置开机自启
# 设置开机启动 systemctl enable redis.service
4、其他命令
#启动redis systemctl start redis #重启redis systemctl restart redis #停止redis systemctl stop redis #查看redis状态 systemctl status redis