Linux上怎么设置redis开启自启动

redis在centos7中的开机自启
在系统服务目录里创建redis.service文件
vi /etc/systemd/system/redis.service

写入以下内容:
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf (这里填写你redis的配置文件所在的路径)
PrivateTmp=true
[Install]
WantedBy=multi-user.target

测试并加入开机自启
先关闭redis-server
systemctl stop redis.service
开启redis-server
  systemctl start redis.service #如果服务是开启状态,使用此命令会启动 失败。
开启成功,将服务加入开机自启
  systemctl enable redis.service #注意后面不能跟空格
reboot #重启
查看服务运行状态:systemctl status redis.service

全部命令
systemctl start redis.service #启动redis服务
  systemctl enable redis.service #设置开机自启动
  systemctl disable redis.service #停止开机自启动
  systemctl status redis.service #查看服务当前状态
  systemctl restart redis.service  #重新启动服务
  systemctl list-units –type=service #查看所有已启动的服务

备注:上面的方式不仅仅适用于redis,也适用于其他的服务部署

以上就是Linux上怎么设置redis开启自启动的详细内容,更多请关注www.sxiaw.com其它相关文章!