Redis叢集部署

來源:互聯網
上載者:User

標籤:redis3.0叢集

親測jedis(jedis2.7.2)用戶端 JedisCluster 可用
1:安裝redis cluster 以及依賴

        1.安裝zlib

       wget:htpp://zlib.net/zlib-1.2.8.tar.gz            tar -zxvf zlib-1.2.8.tar.gz            cd zlib-1.2.8            ./configure            make            make install

         2.安裝redis

     wget:http://download.redis.io/redis-stable.tar.gz            tar -zxvf redis-stable.tar.gz           cd redis-stable          make          make install

         3.安裝ruby

            gem sources -a  http://ruby.taobao.org/                        yum install rubygems            gem install redis
2:配置redis

       1. 建立節點目錄 

           為了區分master 和slave ,slave比master 多1000

    mkdir /server/cluster/6380 6381 6382 7380 7381 7382

         通用配置

  

    mkdir -p /server/server/cluster/redis-common.conf
    daemonize yes     #守護進程運行(後台運行)    tcp-backlog 511      timeout 0      tcp-keepalive 0      loglevel notice      databases 16      dir /opt/redis/data      slave-serve-stale-data yes      #slave唯讀      slave-read-only yes      #not use default      repl-disable-tcp-nodelay yes      slave-priority 100      #開啟aof持久化      appendonly yes      #每秒一次aof寫      appendfsync everysec      #關閉在aof rewrite的時候對新的寫操作進行fsync      no-appendfsync-on-rewrite yes      auto-aof-rewrite-min-size 64mb      lua-time-limit 5000      #開啟redis叢集      cluster-enabled yes      #節點互連逾時的閥值      cluster-node-timeout 15000      cluster-migration-barrier 1      slowlog-log-slower-than 10000      slowlog-max-len 128      notify-keyspace-events ""      hash-max-ziplist-entries 512      hash-max-ziplist-value 64      list-max-ziplist-entries 512      list-max-ziplist-value 64      set-max-intset-entries 512      zset-max-ziplist-entries 128      zset-max-ziplist-value 64      activerehashing yes      client-output-buffer-limit normal 0 0 0      client-output-buffer-limit slave 256mb 64mb 60      client-output-buffer-limit pubsub 32mb 8mb 60      hz 10      aof-rewrite-incremental-fsync yes

        特殊配置

           記得更改port

       vim /server/cluster/6380/redis.conf       vim /server/cluster/6381/redis.conf       vim /server/cluster/6382/redis.conf       vim /serve/cluster/7380/redis.conf       vim /server/cluster/7381/redis.conf       vim /server/cluster/6382/redis.conf

  1. #包含通用配置  include /server/cluster/redis-common.conf  #監聽tcp連接埠  port 6379  #最大可用記憶體  maxmemory 100m  #記憶體耗盡時採用的淘汰策略:  # volatile-lru -> remove the key with an expire set using an LRU algorithm  # allkeys-lru -> remove any key accordingly to the LRU algorithm  # volatile-random -> remove a random key with an expire set  # allkeys-random -> remove a random key, any key  # volatile-ttl -> remove the key with the nearest expire time (minor TTL)  # noeviction -> don‘t expire at all, just return an error on write operations  maxmemory-policy allkeys-lru  #aof隱藏檔  appendfilename "appendonly-6379.aof"  #不開啟rdb儲存,只用於添加slave過程  dbfilename dump-6379.rdb  #cluster設定檔(啟動自動產生)  cluster-config-file nodes-6379.conf  #部署在同一機器的redis執行個體,把auto-aof-rewrite搓開,因為cluster環境下記憶體佔用基本一致.  #防止同意機器下瞬間fork所有redis進程做aof rewrite,佔用大量記憶體(ps:cluster必須開啟aof)  auto-aof-rewrite-percentage 80-100

     

2:建立叢集

         1.啟動redis服務

    redis-server /server/cluster/6380/redis.conf        redis-server /server/cluster/6381/redis.conf    redis-server /server/cluster/6382/redis.conf    redis-server /server/cluster/7380/redis.conf    redis-server /server/cluster/7381/redis.conf    redis-server /server/cluster/7382/redis.conf

        2.建立叢集

     cd /server/server/redis-stable/src     ./redis-trib.rb create --replicas 1 host:6380 host:6381 host:6382 host:7380.....     #這裡注意redis官方翻譯過來的叢集教程,使用的是127.0.0.1:prot 實際很坑爹,     #如果你使用的是java並且使用JedisCluster API來訪問      #會報錯:too many redis cluster redirection。     #比如我的本機ip為123.133.122.141,那麼就應該使用123.133.122.141:prot      #而非127.0.0.1 :port

  命令的意義如下:

  • 給定 redis-trib.rb 程式的命令是 create ,這表示我們希望建立一個新的叢集。

  • 選項 --replicas 1 表示我們希望為叢集中的每個主節點建立一個從節點。

  • 之後跟著的其他參數則是執行個體的地址清單,我們希望程式使用這些地址所指示的執行個體來建立新叢集。

     以上命令的意思就是讓 redis-trib 程式建立一個包含三個主節點和三個從節點的叢集。

    redis-trib 會列印出一份預想中的配置給你看,如果你覺得沒問題的話,就可以輸入 yesredis-trib 就會將這份配置應用到叢集當中。

      查看叢集資訊

redis-cli -p 6380 -c127.0.0.1:6380>cluster infocluster_state:okcluster_slots_assigned:16384cluster_slots_ok:16384cluster_slots_pfail:0cluster_slots_fail:0cluster_known_nodes:6cluster_size:3cluster_current_epoch:6cluster_my_epoch:1cluster_stats_messages_sent:19161cluster_stats_messages_received:19161

可以看到當前cluster_state 是ok的



     使用./redis-trib.rb check host port  檢查狀態

    ./redis-trib.rb check 115.28.138.150:6380    Connecting to node 115.28.138.150:6380: OK    Connecting to node 115.28.138.150:7380: OK    Connecting to node 115.28.138.150:7382: OK    Connecting to node 115.28.138.150:7381: OK    Connecting to node 115.28.138.150:6382: OK    Connecting to node 115.28.138.150:6381: OK    >>> Performing Cluster Check (using node 115.28.138.150:6380)    M: 3046c8e6efbcea5c77e90483d97b928c5e4fbe05 115.28.138.150:6380       slots:0-5460 (5461 slots) master       1 additional replica(s)    S: 2f045aaecb9addea7ae8ef636e3a5415686889e4 115.28.138.150:7380       slots: (0 slots) slave       replicates 3046c8e6efbcea5c77e90483d97b928c5e4fbe05    S: c09ffe456b44abedd7ba811aaad470b3f7a36ea5 115.28.138.150:7382       slots: (0 slots) slave       replicates ed7200bf1cdacc18661d70c39270995582559037    S: 1866624d3330f6491d5c57e269811694bb061759 115.28.138.150:7381       slots: (0 slots) slave       replicates fb5c50e062d0e770aa534315fec1aa11488c228a    M: ed7200bf1cdacc18661d70c39270995582559037 115.28.138.150:6382       slots:10923-16383 (5461 slots) master       1 additional replica(s)    M: fb5c50e062d0e770aa534315fec1aa11488c228a 115.28.138.150:6381       slots:5461-10922 (5462 slots) master       1 additional replica(s)    [OK] All nodes agree about slots configuration.    >>> Check for open slots...    >>> Check slots coverage...    [OK] All 16384 slots covered.

 

  

    


 

本文出自 “瞄膩的專欄” 部落格,請務必保留此出處http://miaoni.blog.51cto.com/10720758/1696050

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.