|
Redis集群部署文档(centos6系统)
(要让集群正常工作至少需要3个主节点,在这里我们要创建6个redis节点,其中三个为主节点,三个为从节点,对应的redis节点的ip和端口对应关系如下)
127.0.0.1:7000{192.168.0.170}
127.0.0.1:7001
127.0.0.1:7002
192.168.0.69:7000
192.168.0.69:7001
192.168.0.69:7002
1:下载redis。官网下载3.0.0版本,之前2.几的版本不支持集群模式
下载地址:https://github.com/antirez/redis/archive/3.0.0-rc2.tar.gz
2:上传服务器,解压,编译{192.168.0.170服务器}
[root@mysql ~]# wget https://github.com/antirez/redis/archive/3.0.0-rc2.tar.gz
[root@mysql ~]# tar zxvf redis-3.0.0-rc2.tar.gz
[root@mysql ~]#cd redis-3.0.0-rc2.tar.gz
[root@mysql ~]# make
[root@mysql ~]#make install
3:创建集群需要的目录
[root@mysql ~]#mkdir /data/redis-clu/{7001,7002,7000} -pv
4:修改配置文件{分别如下}
[root@mysql ~]# cp /root/redis-3.0.0-rc2/redis.conf /data/redis-clu/
[root@mysql ~]# cp /root/redis-3.0.0-rc2/src/redis-server /data/redis-clu/
[root@mysql ~]# vim /data/redis-clu/redis.conf
pid /var/run/redis7000.pid
port 7000
bind 0.0.0.0
cluster-enabled yes
cluster-config-file nodes7000.conf
cluster-node-timeout 5000
appendonly yes
cluster-require-full-coverage yes
[root@mysql ~]# cp /data/redis-clu/7000/redis.conf
[root@mysql ~]# vim /data/redis-clu/redis.conf
pid /var/run/redis7001.pid
port 7001
bind 0.0.0.0
cluster-enabled yes
cluster-config-file nodes7001.conf
cluster-node-timeout 5000
appendonly yes
cluster-require-full-coverage yes
[root@mysql ~]# cp /data/redis-clu/7001/redis.conf
[root@mysql ~]# vim /data/redis-clu/redis.conf
pid /var/run/redis7002.pid
port 7002
bind 0.0.0.0
cluster-enabled yes
cluster-config-file nodes7002.conf
cluster-node-timeout 5000
appendonly yes
cluster-require-full-coverage yes
[root@mysql ~]# cp /data/redis-clu/7002/redis.conf
5:把配置好的文件copy到192.168.0.69服务器上面一份:
[root@mysql ~]# scp -r /data/redis-clu/* 192.168.0.69:/data/redis-clu/
6:在分别在192.168.0.170和192.168.0.69服务器上启动redis-server服务
[root@mysql redis-clu]# ls
7000 7002 dump.rdb nodes-7001.conf redis.conf
7001 appendonly.aof nodes-7000.conf nodes-7002.conf redis-server
[root@mysql redis-clu]# pwd
/data/redis-clu
[root@mysql redis-clu]# #./redis-server 7000/redis.conf
[root@mysql redis-clu]# #./redis-server 7001/redis.conf
[root@mysql redis-clu]# #./redis-server 7002/redis.conf
[root@mysql redis-clu]# ss -tunl
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 *:69 *:*
tcp LISTEN 0 128 *:17000 *:*
tcp LISTEN 0 128 *:17001 *:*
tcp LISTEN 0 64 :::873 :::*
tcp LISTEN 0 128 *:17002 *:*
tcp LISTEN 0 128 :::22 :::*
tcp LISTEN 0 128 *:22 *:*
tcp LISTEN 0 128 *:7000 *:*
tcp LISTEN 0 128 *:7001 *:*
tcp LISTEN 0 10 127.0.0.1:25 *:*
tcp LISTEN 0 128 *:7002 *:*
[root@mysql redis-clu]# #表示服务启动
8:在分别在192.168.0.170和192.168.0.69服务器上安装:ruby和 rubygems和redis
[root@mysql redis-clu]#yum install -y ruby rubygems
[root@mysql redis-clu]#gem install redis
9:在192.168.0.170上启动cluster
[root@mysql redis-clu]# ./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 192.168.0.69:7000 192.168.0.69:7001 192.168.0.69:7002
发下如下错误:
就在相应的redis下执行
发现是没有meet到各个服务、;
于是就执行:
这个在查看服务端:
发现集群做好了 :
剩下的你就可以做测试了:
redis-benchmark -h hostname -p port -s socket -c clients -n requests -d> -l 永久测试 -t tests{方法}
例子:
redis-benchmark -h 127.0.0.1 -p 6379 -q -d 100
set/get 100bytes 检测host12.0.0.1:6379 的redis性能
redis-benchmark -h 127.0.0.1 -p 6379 -c 5000 -n 100000
5000个并发连接,100000个请求,检测host为127.0.0.1 端口为6379的redis服务器性能
-c:并发数量
-n:请求数量
-t:调用的参数
-d:数据大小
redis-benchmark -h localhost -p 6379 -c 100 -n 100000
100个并发连接,100000个请求,检测host为localhost 端口为6379的redis服务器性能
redis-cli -h localhost -p 6380 monitor
Dump all the received requests in real time;
监控host为localhost,端口为6380,redis的连接及读写操作
redis-cli -h localhost -p 6380 info
Provide information and statistics about the server ;
提供host为localhost,端口为6380,redis服务的统计信息
redis cluster注意的问题 :
1. 'cluster-require-full-coverage'参数的设置。该参数是redis配置文件中cluster模式的一个参数,从字面上基本就能看出它的作用:需要全部覆盖!
具体点是redis cluster需要16384个slot都正常的时候才能对外提供服务,换句话说,只要任何一个slot异常那么整个cluster不对外提供服务。
redis默认是‘yes’,即需要全覆盖!建议设置成‘no’。
2. 阻塞命令产生failover。由于一些阻塞命令(flushall, del key1 key2 ...)会造成redis在‘cluster-node-timeout’时间内无法响应其他节点的ping请求,
从而导致其他节点都把该redis标记出了pfail状态,进而产生failover。redis作者计划使用lazy redis解决。
3. 连接建立。当redis cluster的节点数多了以后,client对每个节点建立一个tcp连接需要花比较多的时间。如果是长连接,用户只需忍受一次连接建立的过程,
如果是短连接,那么频繁建立连接将会极大的降低效率。但即便是短连接,只要每次请求只涉及到一个key,有些客户端可能只需要与一个节点建立连接。
4. Jedis。Jedis是redis最流行的Java客户端,支持redis cluster。
‘MaxRedirectionsException’异常,出现该异常说明刚刚执行的那条命令经过多次重试,没有执行成功,需要用户再次执行。
在cluster扩容或者slot迁移的时候比较容易出现。建议捕获该异常并采取相应重试工作。
Pipeline,Jedis目前不支持cluster模式的pipeline,建议采用多并发代替pipeline。
5. Multi-key。Redis cluster对多key操作有限,要求命令中所有的key都属于一个slot,才可以被执行。客户端可以对multi-key命令进行拆分,再发给redis。
另外一个局限是,在slot迁移过程中,multi-key命令特别容易报错(CROSSSLOT Keys in request don't hash to the same slot)。建议不用multi-key命令。
6. 扩容速度慢。redis官方提供了redis cluster管理脚本redis-trib.rb。使用该脚本进行扩容cluster的时候,是串行的迁移slot中的每个key,这样导致了
扩容的速度非常慢,百G的数据要数小时。扩容时间越长,越容易出现异常。
|
|
|
|
|
|
|