linux使用systemctl命令配置redis自啟動


一、配置Redis

  redis解壓完成后,配置redis目錄下的redis.conf文件。bind和protected-mode兩項屬性作用可參考:關於主機連接虛擬機centOS中的redis;daemonize設置為yes后可后台運行。

bind 0.0.0.0
protected-mode no
daemonize yes

二、創建服務

  在/usr/lib/systemd/system下創建redisd.service文件,內容如下。/data/redis為redis安裝目錄路徑。

[Unit]
Description=Redis
After=network.target

[Service]
Type=forking
ExecStart=/data/redis/bin/redis-server /data/redis/redis.conf
ExecReload=/data/redis/bin/redis-server -s reload
ExecStop=/data/redis/bin/redis-server -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

三、創建軟鏈接與開機自啟

  運行命令 systemctl enable redisd 即可自動創建軟鏈接並添加開機自啟。

四、相關命令

  啟動redis服務

systemctl start redisd

  重啟redis服務

systemctl restart redisd

  停止redis服務

systemctl stop redisd

  添加開機自啟

systemctl enable redisd

  禁止開機自啟

systemctl disable redisd

  查看狀態

systemctl status redisd



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM