![]() |
架构细节:
redis-cluster把所有的物理节点映射到[0-16383]slot上,cluster 负责维护
node<->slot<->value
![]() |
![]() |
第一步:安装ruby
[root@itheima bin2]# yum install ruby
[root@itheima bin2]# yum install rubygems
第二步:将以下文件上传到linux系统
第三步:安装ruby和redis接口
[root@itheima ~]# gem install redis-3.0.0.gem
第四步:将redis-3.0.0包下src目录中的以下文件拷贝到redis19/redis-cluster/
[root@itheima src]# cd /usr/local/redis19/
[root@itheima redis19]# mkdir redis-cluster
[root@itheima redis19]# cd /root/redis-3.0.0/src/
[root@itheima src]# cp redis-trib.rb /usr/local/redis19/redis-cluster
第五步:查看是否拷贝成功
端口设计如下:7001-7006
第一步:复制出一个7001机器
[root@itheima redis19]# cp bin ./redis-cluster/7001 –r
第二步:如果存在持久化文件,则删除
[root@itheima 7001]# rm -rf appendonly.aof dump.rdb
第三步:设置集群参数
第四步:修改端口
第五步:复制出7002-7006机器
[root@itheima redis-cluster]# cp 7001/ 7002 -r
[root@itheima redis-cluster]# cp 7001/ 7003 -r
[root@itheima redis-cluster]# cp 7001/ 7004 -r
[root@itheima redis-cluster]# cp 7001/ 7005 -r
[root@itheima redis-cluster]# cp 7001/ 7006 –r
第六步:修改7002-7006机器的端口
第七步:启动7001-7006这六台机器
第八步:修改start-all.sh文件的权限
[root@itheima redis-cluster]# chmod u+x start-all.sh
[root@itheima redis-cluster]# ./start-all.sh
第九步:创建集群
[root@itheima redis-cluster]# ./redis-trib.rb create --replicas 1 192.168.242.137:7001 192.168.242.137:7002 192.168.242.137:7003 192.168.242.137:7004 192.168.242.137:7005 192.168.242.137:7006 >>> Creating cluster Connecting to node 192.168.242.137:7001: OK Connecting to node 192.168.242.137:7002: OK Connecting to node 192.168.242.137:7003: OK Connecting to node 192.168.242.137:7004: OK Connecting to node 192.168.242.137:7005: OK Connecting to node 192.168.242.137:7006: OK >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 192.168.242.137:7001 192.168.242.137:7002 192.168.242.137:7003 Adding replica 192.168.242.137:7004 to 192.168.242.137:7001 Adding replica 192.168.242.137:7005 to 192.168.242.137:7002 Adding replica 192.168.242.137:7006 to 192.168.242.137:7003 M: 8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24 192.168.242.137:7001 slots:0-5460 (5461 slots) master M: 4f52a974f64343fd9f1ee0388490b3c0647a4db7 192.168.242.137:7002 slots:5461-10922 (5462 slots) master M: cb7c5def8f61df2016b38972396a8d1f349208c2 192.168.242.137:7003 slots:10923-16383 (5461 slots) master S: 66adf006fed43b3b5e499ce2ff1949a756504a16 192.168.242.137:7004 replicates 8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24 S: cbb0c9bc4b27dd85511a7ef2d01bec90e692793b 192.168.242.137:7005 replicates 4f52a974f64343fd9f1ee0388490b3c0647a4db7 S: a908736eadd1cd06e86fdff8b2749a6f46b38c00 192.168.242.137:7006 replicates cb7c5def8f61df2016b38972396a8d1f349208c2 Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join.. >>> Performing Cluster Check (using node 192.168.242.137:7001) M: 8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24 192.168.242.137:7001 slots:0-5460 (5461 slots) master M: 4f52a974f64343fd9f1ee0388490b3c0647a4db7 192.168.242.137:7002 slots:5461-10922 (5462 slots) master M: cb7c5def8f61df2016b38972396a8d1f349208c2 192.168.242.137:7003 slots:10923-16383 (5461 slots) master M: 66adf006fed43b3b5e499ce2ff1949a756504a16 192.168.242.137:7004 slots: (0 slots) master replicates 8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24 M: cbb0c9bc4b27dd85511a7ef2d01bec90e692793b 192.168.242.137:7005 slots: (0 slots) master replicates 4f52a974f64343fd9f1ee0388490b3c0647a4db7 M: a908736eadd1cd06e86fdff8b2749a6f46b38c00 192.168.242.137:7006 slots: (0 slots) master replicates cb7c5def8f61df2016b38972396a8d1f349208c2 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. [root@itheima redis-cluster]# |
[root@itheima 7001]# ./redis-cli -h 192.168.242.137 -p 7001 –c
-c:指定是集群连接
|
3.查看集群节点
|