redis+主從複製+叢集配置

來源:互聯網
上載者:User

標籤:redis   叢集   主從複製   

      redis+主從複製+叢集配置

       redis是一個key-value儲存系統。和memcached類似,不過redis支援的value類型更多,主要有:string(字串)、list(鏈表)、set(集合)、zset(有序集合)和hash(雜湊類型)。redis和memcached一樣,為了保證效率,都是把資料緩衝在記憶體中。區別是redis會周期性的把更新的資料寫入磁碟或者把修改的操作寫入追加的記錄檔案,並且在此基礎上實現master-slave主從同步。

下面就來實現主從複製和叢集,叢集是建立在主從複製的基礎之上的。首先準備三台虛擬機器,分別為:

#VM1: ip=172.25.10.8

#VM2: ip=172.25.10.9

#VM3: ip=172.25.10.10

一:redis在三台虛擬機器主機上的安裝:

#yum install -y gcc gcc-c++         ;安裝編譯軟體

#cd redis/

#tar -zxf redis-3.0.2.tar.gz             ;解壓軟體包

#cd redis-3.0.2                               ;進入解壓的目錄

#make ---> #make install               ;直接編譯並且安裝

#cd utils/                                         ;進入此util目錄,執行下面的指令碼。配置並啟動程式

#./install_server.sh

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/83/88/wKioL1d1Srvy5TrDAAGDs4XdmKU164.png-wh_500x0-wm_3-wmp_4-s_1037220804.png" title="Screenshot from 2016-06-30 09_53_23.png" alt="wKioL1d1Srvy5TrDAAGDs4XdmKU164.png-wh_50" />

#netstat -antlpe | grep redis             ;可以查看redis使用的連接埠號碼為6379

#redis-cli                                         ;redis用戶端的使用命令


    >set no1 1234                                 ;將鍵no1添加索引值1234; 


    >get no1                                           ;獲得no1的索引值;


啟動三台虛擬機器上的redis服務;配置兩台SLAVE主機上的設定檔,作主從複製;

SLAVE:VM2  VM3

VM2 #vim /etc/redis/redis-6379  

    slaveof   172.25.10.8 6379   ;添加MASTER的ip和port號。


VM3 #vim /etc/redis/redis-6379  /

    slaveof   172.25.10.8 6379

VM2、VM3分別重啟redis服務;

# /etc/init.d/redis-6379  restart


然後進行驗證:在MASTER上使用命令列redis-cli輸入索引值對(redis-cli  --> set no1 1234),然後在兩台SLAVE主機上進行驗證,直接擷取索引值(redis-cli  --> get no1).如果都能得到統一數值,這表明主從複製同步成功。或者在MASTER上這樣驗證:redis-cli -->info

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/83/88/wKioL1d1TYbydHU8AAB8N8Zvgz0428.png-wh_500x0-wm_3-wmp_4-s_2217544702.png" title="Screenshot from 2016-06-30 09_56_00.png" alt="wKioL1d1TYbydHU8AAB8N8Zvgz0428.png-wh_50" />

出現則表明主從複製成功。


叢集服務配置,有效解決單點故障;

#cd /root/ redis-3.0.2

#vim  sentinel.conf

#grep -v ^# sentinel.conf      ;修改配置如

    650) this.width=650;" src="http://s1.51cto.com/wyfs02/M00/83/89/wKiom1d1Tk7yHN34AABknKbZeig506.png-wh_500x0-wm_3-wmp_4-s_2247403209.png" title="Screenshot from 2016-06-30 09_54_04.png" alt="wKiom1d1Tk7yHN34AABknKbZeig506.png-wh_50" />

#grep -v ^# sentinel.conf > /etc/sentinel.conf

#scp /etc/sentinel.conf [email protected]:/etc/   將配置好的檔案直接傳送到兩個SLAVE機上面,

#scp /etc/sentinel.conf [email protected]:/etc/ 


啟動三台虛擬機器主機的哨兵進程;

VM1、VM2、VM3:

# redis-sentinel  /etc/sentinel.conf

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/83/89/wKiom1d1TwqgwPyaAADiu9Ax_jE961.png-wh_500x0-wm_3-wmp_4-s_2534129691.png" title="Screenshot from 2016-06-30 09_54_40.png" alt="wKiom1d1TwqgwPyaAADiu9Ax_jE961.png-wh_50" />

出現上面的圖形代表哨兵已經啟動,如果無法啟動可能是因為哨兵的設定檔沒有給寫入權限(W)。

650) this.width=650;" src="http://s2.51cto.com/wyfs02/M02/83/89/wKiom1d1T4aiUr98AADQfNmSSrM503.png-wh_500x0-wm_3-wmp_4-s_1116342768.png" title="Screenshot from 2016-06-30 09_55_05.png" alt="wKiom1d1T4aiUr98AADQfNmSSrM503.png-wh_50" />

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/83/89/wKiom1d1T5XxQlHVAADkgFVw9dI776.png-wh_500x0-wm_3-wmp_4-s_2116206796.png" title="Screenshot from 2016-06-30 09_55_41.png" alt="wKiom1d1T5XxQlHVAADkgFVw9dI776.png-wh_50" />


最後驗證MASTER停止掉,然後就是SLAVE進行接管。

本文出自 “Foreverlinux” 部落格,請務必保留此出處http://linuxmin0712.blog.51cto.com/11702588/1794757

redis+主從複製+叢集配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.