基於Twemproxy的Redis叢集方案

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   io   os   使用   ar   

概述

由於單台redis伺服器的記憶體管理能力有限,使用過大記憶體redis伺服器的效能急劇下降,且伺服器發生故障將直接影響大面積業務。為了擷取更好的緩衝效能及擴充型,我們將需要搭建redis叢集來滿足需求。因redis 3.0 beta支援的叢集功能不適合生產環境的使用,所以我們採用twitter正在使用的twemproxy來搭建redis快取服務器叢集,目前使用者包括Pinterest、Tumblr、Twitter、Vine、Kiip、Wuaki.tv、Wanelo、Kontera、Wikimedia、Bright、56.com、Snapchat、Digg、Gawkermedia、3scale.net等。

Twemproxy是memcached和redis協議的Proxy 伺服器,並能有效減少大量串連對redis伺服器的效能影響,它提供的主要特性如下:

 

 

叢集架構

 

安裝Redis

有三台伺服器,一台COS1安裝twemproxy,另外兩台COS2,COS3安裝redis。

 

  1. 下載最新安裝包:redis-2.8.9.tar.gz , tcl-8.5.7-6.el6.x86_64.rpm ,nutcracker-0.3.0.tar.gz
  2. 安裝必要組件rpm:
    [[email protected] redis-2.8.9]# yum install gcc[[email protected] src]# rpm -ivh tcl-8.5.7-6.el6.x86_64.rpm
  3. 安裝Redis:
    [[email protected] src]# tar xvf redis-2.8.9.tar.gz[[email protected] src]# cd redis-2.8.9[[email protected] redis-2.8.9]# make…Hint: To run ‘make test‘ is a good idea ;)make[1]: Leaving directory `/usr/local/src/redis-2.8.9/src‘[root@COS2 redis-2.8.9]# make testAll tests passed without errors!Cleanup: may take some time... OKmake[1]: Leaving directory `/usr/local/src/redis-2.8.9/src‘[root@COS2 redis-2.8.9]# make install[[email protected] redis-2.8.9]# cd /usr/local/bin/[[email protected] bin]# lltotal 13908-rwxr-xr-x. 1 root root 4170264 Apr 26 11:51 redis-benchmark-rwxr-xr-x. 1 root root   22185 Apr 26 11:51 redis-check-aof-rwxr-xr-x. 1 root root   45419 Apr 26 11:51 redis-check-dump-rwxr-xr-x. 1 root root 4263471 Apr 26 11:51 redis-cli-rwxr-xr-x. 1 root root 5726791 Apr 26 11:51 redis-server
  4. 編輯redis設定檔:
    [[email protected] redis-2.8.9]# cp redis.conf /etc/[[email protected] redis-2.8.9]# vim /etc/redredhat-release  redis.conf      [root@COS2 redis-2.8.9]# vim /etc/redis.conf把裡面的daemonize no  修改成 daemonize yes
  5. 啟動redis服務:
    [[email protected] redis-2.8.9]# redis-server /etc/redis.conf
  6. 測試redis服務:
    [[email protected] redis-2.8.9]# redis-cli 127.0.0.1:6379> set kin kinOK127.0.0.1:6379> get kin
  7. 同樣的步驟安裝其他redis伺服器。

 

 

安裝twemproxy
  1. 安裝twemproxy:
    [[email protected] src]# tar xvf nutcracker-0.3.0.tar.gz[[email protected] nutcracker-0.3.0]# cd nutcracker-0.3.0[[email protected] src]#./configure [[email protected] nutcracker-0.3.0]# make && make install
  2. 編輯設定檔:
    [[email protected] conf]# cd /usr/local/src/nutcracker-0.3.0/conf[[email protected] conf]# cp nutcracker.yml /etc/[[email protected] conf]# vim /etc/nutcracker.ymlalpha:  listen: 0.0.0.0:22121  hash: fnv1a_64  distribution: ketama  auto_eject_hosts: true  redis: true  server_retry_timeout: 2000  server_failure_limit: 1  servers: --兩台redis伺服器的地址和連接埠   - 10.23.22.240:6379:1      - 10.23.22.241:6379:1
  3. 測試組態檔案:
    [[email protected] nutcracker-0.3.0]# nutcracker -t /etc/nutcracker.yml nutcracker: configuration file ‘conf/nutcracker.yml‘ syntax is ok
  4. 啟動twemproxy:
    [[email protected] nutcracker-0.3.0]# nutcracker  --helpThis is nutcracker-0.3.0Usage: nutcracker [-?hVdDt] [-v verbosity level] [-o output file]                  [-c conf file] [-s stats port] [-a stats addr]                  [-i stats interval] [-p pid file] [-m mbuf size]Options:  -h, --help             : this help                             -V, --version          : show version and exit                   -t, --test-conf        : test configuration for syntax errors and exit   -d, --daemonize      : run as a daemon                      -D, --describe-stats   : print stats description and exit  -v, --verbosity=N      : set logging level (default: 5, min: 0, max: 11)  -o, --output=S         : set logging file (default: stderr)  -c, --conf-file=S      : set configuration file (default: conf/nutcracker.yml) #配置  -s, --stats-port=N     : set stats monitoring port (default: 22222)  -a, --stats-addr=S     : set stats monitoring ip (default: 0.0.0.0)  -i, --stats-interval=N : set stats aggregation interval in msec (default: 30000 msec)  -p, --pid-file=S       : set pid file (default: off)  -m, --mbuf-size=N      : set size of mbuf chunk in bytes (default: 16384 bytes)[root@COS1 nutcracker-0.3.0]# nutcracker -d -c /etc/nutcracker.yml[[email protected] nutcracker-0.3.0]# ps -ef|grep nutcrackerroot     15358     1  0 02:40 ?        00:00:00 nutcracker -d -c /etc/nutcracker.yml
  5. 測試twemproxy:
    [[email protected] ~]# redis-cli -p 22121127.0.0.1:22121> get kin"kin"127.0.0.1:22121> set kin kingOK127.0.0.1:22121> get kin"king"

 

 

 

 

效能測試

這裡使用redis內建的redis-benchmark進行簡單的效能測試,測試結果如下:

  1. Set測試:
    1. 通過twemproxy測試:
      [[email protected] src]# redis-benchmark -h 10.23.22.240 -p 22121 -c 100 -t set -d 100 -l –q
      SET: 38167.94 requests per second
    2. 直接對後端redis測試:
      [[email protected] ~]# redis-benchmark -h 10.23.22.241 -p 6379 -c 100 -t set -d 100 -l –q
      SET: 53191.49 requests per second
  2. Get測試:
    1. 通過twemproxy測試:
      [[email protected] src]# redis-benchmark -h 10.23.22.240 -p 22121 -c 100 -t get -d 100 -l -qGET: 37453.18 requests per second
    2. 直接對後端redis測試:
      [[email protected] ~]# redis-benchmark -h 10.23.22.241 -p 6379 -c 100 -t get -d 100 -l -qGET: 62111.80 requests per second
  3. 查看索引值分布:
    [[email protected] ~]# redis-cli info|grep db0db0:keys=51483,expires=0,avg_ttl=0[root@COS3 ~]# redis-cli info|grep db0db0:keys=48525,expires=0,avg_ttl=0

測試結果:以基本的set get命令通過twemproxy效能有所下降;通過twemproxy分布基本平均。測試資料以業務測試為準。

基於Twemproxy的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.