redis配置叢集,redis叢集

來源:互聯網
上載者:User

redis配置叢集,redis叢集
redis配置叢集配置環境

環境centos 6.6 redis 3.0.2

為了方便,直接在一個檔案夾下面複製三份redis的環境,尾碼分別表示監聽的連接埠號碼

源碼編譯,進入src檔案夾,make test,看看test能不能通過,然後make

設定檔的核心配置,連接埠分別是10000,10001,10002

    port 10000    cluster-enabled yes    cluster-config-file nodes.conf    cluster-node-timeout 15000    appendonly yes

分別運行

    ./redis-server ../redis.conf 

配置叢集

     ./redis-trib.rb create --replicas 0 127.0.0.1:10000 127.0.0.1:10001 127.0.0.1:10002


報錯!!!

必須要有ruby環境

    yum install ruby

安裝完畢,還是報錯

    ./redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError)        from ./redis-trib.rb:24

安裝rubygems

yum install rubygems

…繼續報錯

    /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- redis (LoadError)        from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'        from ./redis-trib.rb:25

安裝redis和ruby的介面

    gem install redis

安裝成功,本地測試

使用一個用戶端來連結10000連接埠的伺服器,設定一些key-value

    redis-cli -c -p 10000

可以看到自動重新導向到10002連接埠

    set weixuan fengtang    -> Redirected to slot [12705] located at 127.0.0.1:10002    OK    127.0.0.1:10002> set zhangsan Mr.Zhang    OK    127.0.0.1:10002> 

使用另一個用戶端來連結10001連接埠的伺服器,然後擷取資料

    redis-cli -c -p 10001
    127.0.0.1:10001> get weixuan    -> Redirected to slot [12705] located at 127.0.0.1:10002    "fengtang"

可以看到重新導向到10002

增加節點

建立一個節點環境,修改連接埠為10003

啟動這個node

    ./redis-server ../redis.conf

添加節點

    ./redis-trib.rb add-node 127.0.0.1:10003 127.0.0.1:10000

第一個參數是我們剛才啟動的新執行個體,第二個參數是叢集中已有的節點。

    ./redis-trib.rb add-node 127.0.0.1:10003 127.0.0.1:10000 >>> Adding node 127.0.0.1:10003          to cluster 127.0.0.1:10000    Connecting to node 127.0.0.1:10000: OK    Connecting to node 127.0.0.1:10001: OK    Connecting to node 127.0.0.1:10002: OK    >>> Performing Cluster Check (using node 127.0.0.1:10000)    M: b4a5871c0344b54e8e767af80bd6594bae8b9228 127.0.0.1:10000       slots:0-5460 (5461 slots) master       0 additional replica(s)    M: c51a32d82bf42017f2ad50907f816678293f520e 127.0.0.1:10001       slots:5461-10922 (5462 slots) master       0 additional replica(s)    M: a03226abfa843c524602afe2e22ca8c68b023e0a 127.0.0.1:10002       slots:10923-16383 (5461 slots) master       0 additional replica(s)    [OK] All nodes agree about slots configuration.    >>> Check for open slots...    >>> Check slots coverage...    [OK] All 16384 slots covered.    Connecting to node 127.0.0.1:10003: OK    >>> Send CLUSTER MEET to node 127.0.0.1:10003 to make it join the cluster.    [OK] New node added correctly.

添加成功

檢查一下新節點是否已經加入

    [root@java_yf_120 src]# redis-cli -c -p 10000    127.0.0.1:10000> cluster nodes    532634b9563dce5d5165b9c09d391da5fc73cdf9 127.0.0.1:10003 master - 0 1438165131300 0 connected    c51a32d82bf42017f2ad50907f816678293f520e 127.0.0.1:10001 master - 0 1438165130298 2 connected     5461-10922    b4a5871c0344b54e8e767af80bd6594bae8b9228 127.0.0.1:10000 myself,master - 0 0 1 connected      0-5460    a03226abfa843c524602afe2e22ca8c68b023e0a 127.0.0.1:10002 master - 0 1438165130799 3 connected 10923-16383    127.0.0.1:10000> 

可以看到添加成功

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

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.