centos7安裝redis設定開機啟動
阿新 • • 發佈:2019-01-25
參考:https://www.cnblogs.com/onephp/p/6245902.html
1. 首先下載redis原始碼,並使用tar進行解壓縮
wget http://download.redis.io/releases/redis-4.0.8.tar.gz
tar xvzf redis-4.0.8.tar.gz
2.使用gcc進行編譯
make
make test
編譯後的可執行檔案在redis-4.0.8/src目錄下3.使用root許可權建立redis檔案目錄,並複製redis-server redis-cli
mkdir -p /usr/local/redis cp src/redis-server /usr/local/redis/ cp src/redis-cli /usr/local/redis/ cp redis.conf /usr/local/redis/ sudo gropdadd redis sudo useradd -g redis redis --no-create-home sudo chown -R redis:redis /usr/local/redis
4.編輯配置檔案redis.conf,將daemonize 改為yes支援後臺執行
cd /usr/local/redis/
vim redis.conf
5.新增開機啟動服務
vim /etc/systemd/system/redis-server.service
新增如下內容
[Unit] Description=Redis Server Manager After=syslog.target After=network.target [Service] Type=simple User=redis Group=redis PIDFile=/var/run/redis_6379.pid ExecStart=/usr/local/redis/redis-server /usr/local/redis/redis.conf ExecStop=/usr/local/redis/redis-cli shutdown Restart=always [Install] WantedBy=multi-user.target
設定為開機啟動
systemctl daemon-reload
systemctl start redis-server.service
systemctl enable redis-server.service
建立redis-cli軟連線
ln -s /usr/local/redis/redis-cli /usr/bin/redis-cli