天天看點

centos7安裝配置redis

準備工作

關閉防火牆

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall開機啟動

firewall-cmd --state #檢視預設防火牆狀态(關閉後顯示notrunning,開啟後顯示running)

執行後,如提示not running

centos7安裝配置redis

解決方案:

通過systemctl start firewalld開啟防火牆,沒有任何提示即開啟成功。

再次通過systemctl status firewalld檢視firewalld狀态,顯示running即已開啟了

centos7安裝配置redis

配置編譯環境:

sudo yum install gcc-c++

安裝

下載下傳源碼:

wget http://download.redis.io/releases/redis-3.2.8.tar.gz

解壓源碼:

tar -zxvf redis-3.2.8.tar.gz

進入到解壓目錄:

cd redis-3.2.8

執行make編譯Redis:

make MALLOC=libc

注意:make指令執行完成編譯後,會在src目錄下生成6個可執行檔案,分别是redis-server、redis-cli、redis-benchmark、redis-check-aof、redis-check-rdb、redis-sentinel。

centos7安裝配置redis

安裝Redis:

make install 

centos7安裝配置redis

配置Redis能随系統啟動:

./utils/install_server.sh

centos7安裝配置redis

 配置允許外部工具通路

這裡選用Redis Desktop Manager是Redis圖形化管理工具,更友善直覺地管理Redis資料。

編輯redis配置檔案

進入Redis目錄打開Redis.conf配置檔案

輸入 vim redis.conf

1、注釋掉bind(該方法無效,被坑過)

#bind 127.0.0.1

替換方案:

注釋後添加如下内容:

bind 0.0.0.0

centos7安裝配置redis

2、預設不是守護程序方式運作,這裡可以修改

daemonize no

3、禁用保護模式

protected-mode no

4、設定redis密碼

centos7安裝配置redis

此時密碼設定已經完成。

但是這樣設定不會生效,還需要在配置檔案裡加入密碼設定,找到requirepass foobared,在下面添加密碼即可

centos7安裝配置redis

 5、重新啟動Redis

redis-server

可能遇到的問題:啟動後 還是無法外部通路      
centos7安裝配置redis

很明顯,配置檔案修改未生效,ip顯示的還是本地ip

 解決方案:

啟動Redis并指明配置檔案

redis-server ../redis.conf      

 檢視redis程序

ps -ef | grep redis

centos7安裝配置redis

修改生效

centos7安裝配置redis

如遇到啟動後不生效,可能是因為程序被暫用,殺掉程序即可

centos7安裝配置redis

OK,通過外網telnet一下Redis伺服器看看是否通了,在程式設計語言中連接配接Redis也就可以了‘

centos7安裝配置redis

繼續閱讀