zoukankan      html  css  js  c++  java
  • centos7 源码安装redis设置开机自启

    通过源码安装的redis,设置开机自启方式(亲测可用)

    1.编译安装的目录是:/usr/local/redis
    所以配置⽂件⽬录为:/usr/local/redis/redis.conf
    然后移动到/etc/redis/⽬录下
    sudo cp /usr/local/redis/redis.conf /etc/redis/

    2.在系统服务目录里创建redis.service文件
    vim /lib/systemd/system/redis.service
    3.写入以下内容:

    [Unit]
    Description=redis-server
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/usr/local/redis/src/redis-server /etc/redis/redis.conf
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target

    注意:ExecStart要改为自己的目录
    4.配置描述:
    Description:描述服务
    After:描述服务类别
    [Service]服务运行参数的设置
    Type=forking是后台运行的形式
    ExecStart为服务的具体运行命令
    ExecReload为重启命令
    ExecStop为停止命令
    PrivateTmp=True表示给服务分配独立的临时空间
    注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
    [Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3

    5.测试并加入开机自启
    先关闭redis-server
    systemctl stop redis.service

    6.开启redis-server
    systemctl start redis.service #如果服务是开启状态,使用此命令会启动失败。

    7.开启成功,将服务加入开机自启
    systemctl enable redis.service #注意后面不能跟空格

    8.重启服务器,查看是否开机启动
    reboot #重启

    9.查看服务运行状态
    systemctl status redis.service

    10.操作命令
    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 #查看所有已启动的服务

     

  • 相关阅读:
    鼠标和滚轮事件
    UI事件
    跨浏览器的事件对象
    DOM中的事件对象和IE事件对象
    Monolog手册参考
    nginx 配置
    es elasticsearch-head安装
    es ik分词插件安装
    yii2.0+es
    php分词工具scws
  • 原文地址:https://www.cnblogs.com/FZlion/p/13938051.html
Copyright © 2011-2022 走看看