天天看點

Centos7 設定redis開機自啟Centos7 設定redis開機自啟

Centos7 設定redis開機自啟

标簽(空格分隔):Linux

環境

Centos7.1
redis-3.0.6
           

chkconfig方式

**service和chkconfig指令的功能好像都被閹割了,而且好像已經被systemctl指令取代了**
           
  1. 找到redis安裝包
    Centos7 設定redis開機自啟Centos7 設定redis開機自啟
  2. 複制redis_init_script檔案到/etc/init.d/
    Centos7 設定redis開機自啟Centos7 設定redis開機自啟
  3. 修改下檔案内容
    Centos7 設定redis開機自啟Centos7 設定redis開機自啟
    Centos7 設定redis開機自啟Centos7 設定redis開機自啟
  4. 設定可執行權限
    Centos7 設定redis開機自啟Centos7 設定redis開機自啟
  5. 開自啟
    Centos7 設定redis開機自啟Centos7 設定redis開機自啟
  6. 棄用[提示不能用]
    Centos7 設定redis開機自啟Centos7 設定redis開機自啟

systemctl方式

  1. 建立redis.service服務檔案

    vim /usr/lib/systemd/system/redis.service

    Centos7 設定redis開機自啟Centos7 設定redis開機自啟
  2. 修改redis.service檔案内容
    Centos7 設定redis開機自啟Centos7 設定redis開機自啟
  3. 建立軟連接配接

    ln -s /usr/lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants/redis.service

  4. 重新整理systemctl

    systemctl daemon-reload

  5. 設定開機自啟動

    systemctl enable redis

    systemctl disable redis

  6. 啟動redis

    systemctl start redis

    systemctl stop redis

  7. 重新開機

    reboot

    7.常用指令

    systemctl 檢視正在運作的服務

    systemctl list-units 檢視激活的單元

    systemctl --failed 檢視運作失敗的單元

    systemctl list-unit-files 檢視所有已安裝服務

    8.配置檔案

    Unit]:服務的說明

    Unit]:服務的說明

    Description:描述服務

    After:依賴,當依賴的服務啟動之後再啟動自定義的服務

    [Service]服務運作參數的設定

    Type=forking|Simple 父程序fork,此方式必須指定PIDFile=,|主程序啟動

    ExecStart為服務的具體運作指令

    ExecReload為重新開機指令

    ExecStop為停止指令

    PrivateTmp=True表示給服務配置設定獨立的臨時空間

    注意:啟動、重新開機、停止指令全部要求使用絕對路徑

    [Install]服務安裝的相關設定,可設定為多使用者

轉載于:https://www.cnblogs.com/yanweifeng/p/11571871.html