首页  >  文章  >  数据库  >  Linux上怎么设置redis开启自启动

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

王林
王林转载
2023-06-02 17:58:093818浏览

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开启自启动的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:yisu.com。如有侵权,请联系admin@php.cn删除