Redis集群部署文档(centos6,redhat系统)
(要让集群正常工作至少需要3个主节点,在这里我们要创建6个redis节点,其中三个为主节点,三个为从节点,对应的redis节点的ip和端口对应关系如下)
127.0.0.1:7000
127.0.0.1:7001
127.0.0.1:7002
127.0.0.1:7003
127.0.0.1:7004
127.0.0.1:7005
1:下载redis。官网下载3.0.0版本,之前2.几的版本不支持集群模式(3.0版本以上也支持)
下载地址:https://github.com/antirez/redis/archive/3.0.0-rc2.tar.gz
2:上传服务器,解压,编译
tar -zxvf redis-3.0.0-rc2.tar.gz mv redis-3.0.0-rc2.tar.gz redis3.0 cd /usr/local/redis3.0 make make install |
3:创建集群需要的目录
mkdir -p /usr.local/cluster cd /usr.local/cluster mkdir 7000 mkdir 7001 mkdir 7002 mkdir 7003 mkdir 7004 mkdir 7005 |
4:修改配置文件redis.conf
cp /usr/local/redis3.0/redis.conf /usr.local/cluster vi redis.conf ##修改配置文件中的下面选项 port 7000 daemonize yes cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes ##修改完redis.conf配置文件中的这些配置项之后把这个配置文件分别拷贝到7000/7001/7002/7003/7004/7005目录下面 cp /usr/local/cluster/redis.conf /usr/local/cluster/7000 cp /usr/local/cluster/redis.conf /usr/local/cluster/7001 cp /usr/local/cluster/redis.conf /usr/local/cluster/7002 cp /usr/local/cluster/redis.conf /usr/local/cluster/7003 cp /usr/local/cluster/redis.conf /usr/local/cluster/7004 cp /usr/local/cluster/redis.conf /usr/local/cluster/7005 ##注意:拷贝完成之后要修改7001/7002/7003/7004/7005目录下面redis.conf文件中的port参数,分别改为对应的文件夹的名称 |
5:分别启动这6个redis实例
cd /usr/local/cluster/7000 redis-server redis.conf cd /usr/local/cluster/7001 redis-server redis.conf cd /usr/local/cluster/7002 redis-server redis.conf cd /usr/local/cluster/7003 redis-server redis.conf cd /usr/local/cluster/7004 redis-server redis.conf cd /usr/local/cluster/7005 redis-server redis.conf ##启动之后使用命令查看redis的启动情况ps -ef|grep redis 如下图显示则说明启动成功 |
6:执行redis的创建集群命令创建集群
cd /usr/local/redis3.0/src ./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 |
6.1执行上面的命令的时候会报错,因为是执行的ruby的脚本,需要ruby的环境
错误内容:/usr/bin/env: ruby: No such file or directory
所以需要安装ruby的环境,这里推荐使用yum install ruby安装
yum install ruby |
6.2然后再执行第6步的创建集群命令,还会报错,提示缺少rubygems组件,使用yum安装
错误内容:
./redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError)
from ./redis-trib.rb:24
yum install rubygems |
6.3再次执行第6步的命令,还会报错,提示不能加载redis,是因为缺少redis和ruby的接口,使用gem 安装
错误内容:
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- redis (LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from ./redis-trib.rb:25
gem install redis --version 3.0.0 |
注意:gem install redis --version 3.0.0 失败的话,需要修改一下gem的源
gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/
6.4 再次执行第6步的命令,正常执行
输入yes,然后配置完成。
至此redis集群即搭建成功!
7:使用redis-cli命令进入集群环境
redis-cli -c -p 7000 |
集群性能测试: Redis-benchmark是官方自带的Redis性能测试工具,可以有效的测试Redis服务的性能。 使用说明如下:
Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>]
-h <hostname> Server hostname (default 127.0.0.1) -p <port> Server port (default 6379) -s <socket> Server socket (overrides host and port) -c <clients> Number of parallel connections (default 50) -n <requests> Total number of requests (default 10000) -d <size> Data size of SET/GET value in bytes (default 2) -k <boolean> 1=keep alive 0=reconnect (default 1) -r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD Using this option the benchmark will get/set keys in the form mykey_rand:000000012456 instead of constant keys, the <keyspacelen> argument determines the max number of values for the random number. For instance if set to 10 only rand:000000000000 - rand:000000000009 range will be allowed. -P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline). -q Quiet. Just show query/sec values --csv Output in CSV format -l Loop. Run the tests forever -t <tests> Only run the comma-separated list of tests. The test names are the same as the ones produced as output. -I Idle mode. Just open N idle connections and wait.
1、redis-benchmark -h 192.168.1.201 -p 6379 -c 100 -n 100000 2、redis-benchmark -h 192.168.1.201 -p 6379 -q -d 100 测试存取大小为100字节的数据包的性能 3、redis-benchmark -t set,lpush -n 100000 -q 只测试某些操作的性能 4、redis-benchmark -n 100000 -q script load "redis.call('set','foo','bar')" 只测试某些数值存取的性能
测试结果分析:
10000 requests completed in 0.30 seconds 100 parallel clients 3 bytes payload keep alive: 1
0.11% <= 1 milliseconds 86.00% <= 2 milliseconds 90.12% <= 3 milliseconds 96.68% <= 4 milliseconds 99.27% <= 5 milliseconds 99.54% <= 6 milliseconds 99.69% <= 7 milliseconds 99.78% <= 8 milliseconds 99.89% <= 9 milliseconds 100.00% <= 9 milliseconds 33222.59 requests per second
====== PING_BULK ====== 10000 requests completed in 0.27 seconds 100 parallel clients 3 bytes payload keep alive: 1
0.93% <= 1 milliseconds 97.66% <= 2 milliseconds 100.00% <= 2 milliseconds 37174.72 requests per second
====== SET ====== 10000 requests completed in 0.32 seconds 100 parallel clients 3 bytes payload keep alive: 1
0.22% <= 1 milliseconds 91.68% <= 2 milliseconds 97.78% <= 3 milliseconds 98.80% <= 4 milliseconds 99.38% <= 5 milliseconds 99.61% <= 6 milliseconds 99.72% <= 7 milliseconds 99.83% <= 8 milliseconds 99.94% <= 9 milliseconds 100.00% <= 9 milliseconds 30959.75 requests per second
====== GET ====== 10000 requests completed in 0.28 seconds 100 parallel clients 3 bytes payload keep alive: 1
0.55% <= 1 milliseconds 98.86% <= 2 milliseconds 100.00% <= 2 milliseconds 35971.22 requests per second
====== INCR ====== 10000 requests completed in 0.14 seconds 100 parallel clients 3 bytes payload keep alive: 1
95.61% <= 1 milliseconds 100.00% <= 1 milliseconds 69444.45 requests per second
====== LPUSH ====== 10000 requests completed in 0.21 seconds 100 parallel clients 3 bytes payload keep alive: 1
18.33% <= 1 milliseconds 100.00% <= 1 milliseconds 48309.18 requests per second
====== LPOP ====== 10000 requests completed in 0.23 seconds 100 parallel clients 3 bytes payload keep alive: 1
0.29% <= 1 milliseconds 99.76% <= 2 milliseconds 100.00% <= 2 milliseconds 44052.86 requests per second
====== SADD ====== 10000 requests completed in 0.22 seconds 100 parallel clients 3 bytes payload keep alive: 1
2.37% <= 1 milliseconds 99.81% <= 2 milliseconds 100.00% <= 2 milliseconds 44444.45 requests per second
====== SPOP ====== 10000 requests completed in 0.22 seconds 100 parallel clients 3 bytes payload keep alive: 1
4.27% <= 1 milliseconds 99.84% <= 2 milliseconds 100.00% <= 2 milliseconds 44642.86 requests per second
====== LPUSH (needed to benchmark LRANGE) ====== 10000 requests completed in 0.22 seconds 100 parallel clients 3 bytes payload keep alive: 1
12.35% <= 1 milliseconds 99.62% <= 2 milliseconds 100.00% <= 2 milliseconds 46082.95 requests per second
====== LRANGE_100 (first 100 elements) ====== 10000 requests completed in 0.48 seconds 100 parallel clients 3 bytes payload keep alive: 1
0.01% <= 1 milliseconds 3.27% <= 2 milliseconds 98.71% <= 3 milliseconds 99.93% <= 4 milliseconds 100.00% <= 4 milliseconds 20964.36 requests per second
====== LRANGE_300 (first 300 elements) ====== 10000 requests completed in 1.26 seconds 100 parallel clients 3 bytes payload keep alive: 1
0.01% <= 2 milliseconds 0.14% <= 3 milliseconds 0.90% <= 4 milliseconds 7.03% <= 5 milliseconds 31.68% <= 6 milliseconds 78.93% <= 7 milliseconds 98.88% <= 8 milliseconds 99.56% <= 9 milliseconds 99.72% <= 10 milliseconds 99.95% <= 11 milliseconds 100.00% <= 11 milliseconds 7961.78 requests per second
====== LRANGE_500 (first 450 elements) ====== 10000 requests completed in 1.82 seconds 100 parallel clients 3 bytes payload keep alive: 1
0.01% <= 2 milliseconds 0.06% <= 3 milliseconds 0.14% <= 4 milliseconds 0.30% <= 5 milliseconds 0.99% <= 6 milliseconds 2.91% <= 7 milliseconds 8.11% <= 8 milliseconds 43.15% <= 9 milliseconds 88.38% <= 10 milliseconds 97.25% <= 11 milliseconds 98.61% <= 12 milliseconds 99.26% <= 13 milliseconds 99.30% <= 14 milliseconds 99.44% <= 15 milliseconds 99.48% <= 16 milliseconds 99.64% <= 17 milliseconds 99.85% <= 18 milliseconds 99.92% <= 19 milliseconds 99.95% <= 20 milliseconds 99.96% <= 21 milliseconds 99.97% <= 22 milliseconds 100.00% <= 23 milliseconds 5491.49 requests per second
====== LRANGE_600 (first 600 elements) ====== 10000 requests completed in 2.29 seconds 100 parallel clients 3 bytes payload keep alive: 1
0.01% <= 2 milliseconds 0.05% <= 3 milliseconds 0.10% <= 4 milliseconds 0.19% <= 5 milliseconds 0.34% <= 6 milliseconds 0.46% <= 7 milliseconds 0.58% <= 8 milliseconds 4.46% <= 9 milliseconds 21.80% <= 10 milliseconds 40.48% <= 11 milliseconds 60.14% <= 12 milliseconds 79.81% <= 13 milliseconds 93.77% <= 14 milliseconds 97.14% <= 15 milliseconds 98.67% <= 16 milliseconds 99.08% <= 17 milliseconds 99.30% <= 18 milliseconds 99.41% <= 19 milliseconds 99.52% <= 20 milliseconds 99.61% <= 21 milliseconds 99.79% <= 22 milliseconds 99.88% <= 23 milliseconds 99.89% <= 24 milliseconds 99.95% <= 26 milliseconds 99.96% <= 27 milliseconds 99.97% <= 28 milliseconds 99.98% <= 29 milliseconds 100.00% <= 29 milliseconds 4359.20 requests per second
====== MSET (10 keys) ====== 10000 requests completed in 0.37 seconds 100 parallel clients 3 bytes payload keep alive: 1
0.01% <= 1 milliseconds 2.00% <= 2 milliseconds 18.41% <= 3 milliseconds 88.55% <= 4 milliseconds 96.09% <= 5 milliseconds 99.50% <= 6 milliseconds 99.65% <= 7 milliseconds 99.75% <= 8 milliseconds 99.77% <= 9 milliseconds 99.78% <= 11 milliseconds 99.79% <= 12 milliseconds 99.80% <= 13 milliseconds 99.81% <= 15 milliseconds 99.82% <= 16 milliseconds 99.83% <= 17 milliseconds 99.84% <= 19 milliseconds 99.85% <= 21 milliseconds 99.86% <= 23 milliseconds 99.87% <= 24 milliseconds 99.88% <= 25 milliseconds 99.89% <= 27 milliseconds 99.90% <= 28 milliseconds 99.91% <= 30 milliseconds 99.92% <= 32 milliseconds 99.93% <= 34 milliseconds 99.95% <= 35 milliseconds 99.96% <= 36 milliseconds 99.97% <= 37 milliseconds 99.98% <= 39 milliseconds 99.99% <= 41 milliseconds 100.00% <= 41 milliseconds 27173.91 requests per second
|