標籤:nosql
Redis叢集
Twemproxy
1
、環境
部署:
作業系統 |
CentOS 6.4 |
redis版本 |
redis-3.0.7 |
redis主伺服器 |
192.168.1.111 |
redis從伺服器1 |
192.168.1.112 |
redis從伺服器2 |
192.168.1.113 |
有三台伺服器,一台COS1安裝twemproxy,另外兩台COS2,COS3安裝redis。
2.
Cos
1、
Cos2和cos3安裝redi
s
見 http://youngcheung.blog.51cto.com/10809015/1773154
3. Cos1安裝twemproxy:
3.1下載twemproxy(nutcracker)的安裝包
[[email protected] ~]# cd /usr/src/ [[email protected]]# wget http://twemproxy.googlecode.com/files/nutcracker-0.2.4.tar.gz
3.2解壓安裝
[[email protected] ~]# tar xf nutcracker-0.2.4.tar.gz[[email protected] ~]# cd nutcracker-0.2.4[[email protected] nutcracker-0.2.4]# ./configure --prefix=/opt/phpdba/nutcracker-0.2.4[[email protected] nutcracker-0.2.4]# make && make install[[email protected] nutcracker-0.2.4]# cp -r conf scripts /opt/phpdba/nutcracker-0.2.4
3.3 配置環境變數
[[email protected] ~]# cd /etc/profile.d/[[email protected] profile.d]# vim twemproxy.sh #!/bin/sh#set Rutcracker environmentexport RUTCRACKER_HOME=/opt/phpdba/nutcracker-0.2.4export PATH=$RUTCRACKER_HOME/bin:$PATHsource twemporxy.sh
3.4 修改設定檔
[[email protected] ~]# vim /opt/phpdba/nutcracker-0.2.4/conf/nutcracker.yml alpha: listen: 127.0.0.1:22121 hash: fnv1a_64 distribution: ketama auto_eject_hosts: true redis: true server_retry_timeout: 2000 server_failure_limit: 1 servers: - 192.168.1.112:6379:1 server1 - 192.168.1.113:6379:1 server2
3.5檢查文法
[[email protected] ~]# nutcracker -c /opt/phpdba/nutcracker-0.2.4/conf/nutcracker.yml -tnutcracker: configuration file ‘/opt/phpdba/nutcracker-0.2.4/conf/nutcracker.yml‘ syntax is ok[[email protected] ~]# nutcracker -d -c /opt/phpdba/nutcracker-0.2.4/conf/nutcracker.yml
效能測試
這裡使用redis內建的redis-benchmark進行簡單的效能測試,測試結果如下:
1.測試:
a.通過twemproxy測試:
[[email protected] ~]# redis-benchmark -h 127.0.0.1 -q -t set,get,incr,lpush,lpop,sadd,spop,lpush,lrange -c 100 -p 22121SET: 62972.29 requests per secondGET: 87336.24 requests per secondINCR: 85034.02 requests per secondLPUSH: 81699.35 requests per secondLPOP: 82987.55 requests per secondSADD: 85034.02 requests per secondSPOP: 87412.59 requests per secondLPUSH (needed to benchmark LRANGE): 80840.74 requests per secondLRANGE_100 (first 100 elements): 28384.90 requests per secondLRANGE_300 (first 300 elements): 9022.01 requests per secondLRANGE_500 (first 450 elements): 4810.00 requests per secondLRANGE_600 (first 600 elements): 3363.04 requests per second
b.通過對後端redis查看:
[[email protected] ~]# redis-cli 127.0.0.1:6379> KEYS *1) "counter:__rand_int__"127.0.0.1:6379> [[email protected] ~]# redis-cli 127.0.0.1:6379> KEYS *1) "mylist"2) "key:__rand_int__"
發現我們的測試資料分區到了兩個redis執行個體中。
2.查看索引值分布
[[email protected] ~]# redis-cli info|grep db0db0:keys=1,expires=0,avg_ttl=0[[email protected] ~]# redis-cli info|grep db0db0:keys=1,expires=0,avg_ttl=0[[email protected] ~]# [[email protected] ~]# redis-cli info|grep db0db0:keys=2,expires=0,avg_ttl=0
測試結果:以基本的命令通過twemproxy效能有所下降;通過twemproxy分布基本平均。測試資料以業務測試為準。
Redis叢集Twemproxy