- 進入到redis安裝目錄,具體位置看你安裝時的路徑了。
# cd /root/tools/redis-5.0.4/
複制
- 編輯配置檔案
# vim redis.conf
複制
- 将如下配置項注釋掉
#bind 127.0.0.1
複制
- 如下項修改為yes,預設是no
daemonize yes
複制
- 修改pid檔案路徑,此處可選,使用預設路徑也可以。
# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
#
# When the server runs non daemonized, no pid file is created if none is
# specified in the configuration. When the server is daemonized, the pid file
# is used even if not specified, defaulting to "/var/run/redis.pid".
#
# Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally.
pidfile /var/run/redis_6379.pid
複制
- 取消保護模式,此處可選。取消了便不要求使用密碼驗證了。
protected-mode no
複制
- 儲存檔案。
- 建立 service 檔案
sudo vim /usr/lib/systemd/system/redis.service
複制
- 建立 pid 檔案
# cd /var/run/
# touch redis_6379.pid
複制
- 寫入如下内容,具體檔案路徑,各異。
[Unit]
Description=Redis
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/root/tools/redis-5.0.4/src/redis-server /root/tools/redis-5.0.4/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
複制
- 重載系統服務
sudo systemctl daemon-reload
複制
- 啟動redis
sudo systemctl start redis
複制
END
iotisan 部落格專家
釋出了251 篇原創文章 · 獲贊 253 · 通路量 84萬+