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. Cos1、Cos2和cos3安装redis
3. Cos1安装twemproxy:
3.1下载twemproxy(nutcracker)的安装包
3.2解压安装
1
2
3
4
5
| [iyunv@cos1 ~]# tar xf nutcracker-0.2.4.tar.gz
[iyunv@cos1 ~]# cd nutcracker-0.2.4
[iyunv@cos1 nutcracker-0.2.4]# ./configure --prefix=/opt/phpdba/nutcracker-0.2.4
[iyunv@cos1 nutcracker-0.2.4]# make && make install
[iyunv@cos1 nutcracker-0.2.4]# cp -r conf scripts /opt/phpdba/nutcracker-0.2.4
|
3.3 配置环境变量
1
2
3
4
5
6
7
| [iyunv@cos1 ~]# cd /etc/profile.d/
[iyunv@cos1 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
|
3.4 修改配置文件
1
2
3
4
5
6
7
8
9
10
11
12
| [iyunv@cos1 ~]# 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检查语法
1
2
3
| [iyunv@cos1 ~]# nutcracker -c /opt/phpdba/nutcracker-0.2.4/conf/nutcracker.yml -t
nutcracker: configuration file '/opt/phpdba/nutcracker-0.2.4/conf/nutcracker.yml' syntax is ok
[iyunv@cos1 ~]# nutcracker -d -c /opt/phpdba/nutcracker-0.2.4/conf/nutcracker.yml
|
性能测试这里使用redis自带的redis-benchmark进行简单的性能测试,测试结果如下:
1.测试:
a.通过twemproxy测试:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| [iyunv@puppet01 ~]# 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@puppet02 ~]# redis-cli
127.0.0.1:6379> KEYS *
1) "counter:__rand_int__"
127.0.0.1:6379>
[iyunv@localhost ~]# redis-cli
127.0.0.1:6379> KEYS *
1) "mylist"
2) "key:__rand_int__"
|
发现我们的测试数据分片到了两个redis实例中。
2.查看键值分布
1
2
3
4
5
6
7
| [iyunv@puppet01 ~]# redis-cli info|grep db0
db0:keys=1,expires=0,avg_ttl=0
[iyunv@puppet02 ~]# redis-cli info|grep db0
db0:keys=1,expires=0,avg_ttl=0
[iyunv@puppet02 ~]#
[iyunv@localhost ~]# redis-cli info|grep db0
db0:keys=2,expires=0,avg_ttl=0
|
测试结果:以基本的命令通过twemproxy性能有所下降;通过twemproxy分布基本平均。测试数据以业务测试为准。
|