环境说明:
twemproxy | 192.168.0.112:22122 | centos6.5 | redis | 192.168.0.113:6379 | centos6.5 | redis | 192.168.0.113:6380 | centos6.5 |
twemproxy安装:
1
2
3
4
5
| [iyunv@localhost src]# tar -zxf nutcracker-0.4.0.tar.gz
[iyunv@localhost src]# cd nutcracker-0.4.0
[iyunv@localhost nutcracker-0.4.0]# ./configure --prefix=/usr/local/nutcracker/
[iyunv@localhost nutcracker-0.4.0]# make && make install
[iyunv@localhost nutcracker-0.4.0]# cp -r conf scripts /usr/local/nutcracker/
|
配置环境变量:
1
2
3
4
5
6
7
| [iyunv@localhost nutcracker-0.4.0]# cd /etc/profile.d/
[iyunv@localhost profile.d]# vim twemproxy.sh
#!/bin/sh
#set Rutcracker environment
export RUTCRACKER_HOME=/opt/phpdba/nutcracker-0.2.4
export PATH=$RUTCRACKER_HOME/bin:$PATH
source twemporxy.sh
|
修改nutcracker配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| [iyunv@localhost nutcracker-0.4.0]# cd /usr/local/nutcracker/
[iyunv@localhost nutcracker]# vim conf/nutcracker.yml
alpha:
listen: 0.0.0.0:22121
hash: fnv1a_64
distribution: ketama
auto_eject_hosts: true #将出现故障的redis从集群中移除
redis: true
server_retry_timeout: 2000
server_failure_limit: 1
servers:
- 192.168.0.112:6379:1 server1
- 192.168.0.113:6379:1 server2
- 192.168.0.113:6380:1 server3
|
配置文件说明
检查配置文件语法
1
2
| [iyunv@localhost nutcracker]# nutcracker -c conf/nutcracker.yml -t
nutcracker: configuration file '/opt/phpdba/nutcracker-0.2.4/conf/nutcracker.yml' syntax is ok
|
启动:
1
| [iyunv@localhost nutcracker]# nutcracker -d -c /opt/phpdba/nutcracker-0.2.4/conf/nutcracker.yml
|
redis安装请看主从配置中的安装部分
性能测试这里使用redis自带的redis-benchmark进行简单的性能测试,测试结果如下: 1.测试: a.通过twemproxy测试: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
| [iyunv@localhost nutcracker]# redis-benchmark -h 127.0.0.1 -q -t set,get,incr,lpush,lpop,sadd,spop,lpush,lrange -c 100 -p 22121
SET: 62972.29 requests per second
GET: 87336.24 requests per second
INCR: 85034.02 requests per second
LPUSH: 81699.35 requests per second
LPOP: 82987.55 requests per second
SADD: 85034.02 requests per second
SPOP: 87412.59 requests per second
LPUSH (needed to benchmark LRANGE): 80840.74 requests per second
LRANGE_100 (first 100 elements): 28384.90 requests per second
LRANGE_300 (first 300 elements): 9022.01 requests per second
LRANGE_500 (first 450 elements): 4810.00 requests per second
LRANGE_600 (first 600 elements): 3363.04 requests per second
|
b.通过对后端redis查看:
1
2
3
4
5
6
7
8
| [iyunv@localhost nutcracker]# redis-cli
127.0.0.1:6379> KEYS *
1) "counter:__rand_int__"
127.0.0.1:6379>
[iyunv@localhost nutcracker]# redis-cli
127.0.0.1:6379> KEYS *
1) "mylist"
2) "key:__rand_int__"
|
发现我们的测试数据分片到了两个redis实例中。
2.查看键值分布(分别在集群后端的redis实例查看)
1
2
3
4
5
6
| [iyunv@localhost nutcracker]# redis-cli info|grep db0
db0:keys=1,expires=0,avg_ttl=0
[iyunv@localhost nutcracker]# redis-cli info|grep db0
db0:keys=1,expires=0,avg_ttl=0
[iyunv@localhost nutcracker]# redis-cli info|grep db0
db0:keys=2,expires=0,avg_ttl=0
|
测试结果:以基本的命令通过twemproxy性能有所下降;通过twemproxy分布基本平均。测试数据以业务测试为准。
|