1.下載安裝包
[root@localhost opt]# wget http://download.redis.io/rele...redis
[root@localhost opt]# tar -zxvf redis-5.0.3.tar.gz
2.切換到目錄並編譯
[root@localhost opt]# cd redis-5.0.3網絡
[root@localhost redis-5.0.3]# make
注意須要gcc環境,能夠命令gcc -v查看是否安裝gcc環境,若是沒有須要另行安裝
3.安裝redis
[root@localhost redis-5.0.3]# make install PREFIX=/opt/redis
4.配置
首先拷貝配置文件到安裝目錄
[root@localhost bin]# cp /opt/redis-5.0.3/redis.conf /opt/redis/bin/
幾個須要注意的配置項:
protected-mode 保護模式,控制外部網絡的訪問,默認爲yes,需配置bind ip或者設置訪問密碼。設置爲no時關閉保護模式工具
daemonize 守護線程,默認爲no,即啓動redis服務後若是關閉鏈接工具時redis服務同時關閉;設置爲yes時,開啓守護進程模式,在該模式下,redis會在後臺運行,並將進程pid號寫入至redis.conf選項pidfile設置的文件中,此時redis將一直運行,除非手動kill該進程。
4.啓動服務
前臺啓動:在redis的bin目錄下執行命令./redis-server線程
後臺啓動:在redis的bin目錄下執行命令./redis-server redis.conf
5.設置開機啓動
在目錄/etc/systemd/system下新建文件redis.service
輸入如下內容保存:
[Unit]
Description=redis-server
After=network.targetrest
[Service]
Type=forking
ExecStart=/opt/redis/bin/redis-server /opt/redis/bin/redis.conf
PrivateTmp=trueserver
[Install]
WantedBy=multi-user.target
輸入如下命令配置開機啓動
[root@localhost bin]# systemctl daemon-reload
[root@localhost bin]# systemctl start redis.service
[root@localhost bin]# systemctl enable redis.service
建立 redis 命令軟連接
[root@localhost ~]# ln -s /opt/redis/bin/redis-cli /usr/bin/redis進程
附服務操做命令
systemctl start redis.service #啓動redis服務
systemctl stop redis.service #中止redis服務
systemctl restart redis.service #從新啓動服務
systemctl status redis.service #查看服務當前狀態
systemctl enable redis.service #設置開機自啓動
systemctl disable redis.service #中止開機自啓動ip