自此,RedisCluster已经手动搭建完成 。手动搭建可以理解集群建立的流程和细节,不过大家也会发现手动搭建有很多步骤,当集群的节点比较多的时候,肯定会让人头大 。所以Redis官方提供了redis-trib.rb工具,可以让我们快速地搭建集群 。
自动搭建redis-trib.rb是使用Ruby开发的Redis Cluster的管理工具,不需要额外下载,默认位于源码包的src目录下,但因为该工具是用Ruby开发的,所以需要准备相关的依赖环境 。
环境准备安装Ruby:
yum -y install zlib-develwget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.gztar xvf ruby-2.5.1.tar.gzcd ruby-2.5.1/./configure -prefix=/usr/local/rubymakemake installcd /usr/local/ruby/cp bin/ruby /usr/local/bincp bin/gem /usr/local/bin
安装rubygem redis依赖:
wget http://rubygems.org/downloads/redis-3.3.0.gemgem install -l redis-3.3.0.gem
安装redis-trib.rb:
cp src/redis-trib.rb /usr/local/bin
执行redis-trib.rb命令确认一下环境是否准备正确:
# redis-trib.rb helpUsage: redis-trib <command> <options> <arguments ...> create host1:port1 ... hostN:portN --replicas <arg> check host:port info host:port fix host:port --timeout <arg> reshard host:port --from <arg>...此处省略一万个字...
搭建集群像前面的内容讲的,准备好节点配置并启动:
src/redis-server conf/redis-7380.conf &src/redis-server conf/redis-7381.conf &src/redis-server conf/redis-7382.conf &src/redis-server conf/redis-7383.conf &src/redis-server conf/redis-7384.conf &src/redis-server conf/redis-7385.conf &
使用redis-trib.rb create命令完成节点握手和槽分配的工作,命令如下:
redis-trib.rb create --replicas 1 127.0.0.1:7380 127.0.0.1:7382 127.0.0.1:7384 127.0.0.1:7381 127.0.0.1:7383 127.0.0.1:7385
其中--replicas参数用来指定集群中每个主节点有几个从节点,这里设置的是1 。命令执行后,会首先给出主从节点的分配计划:
>>> Creating cluster>>> Performing hash slots allocation on 6 nodes...Using 3 masters:127.0.0.1:7380127.0.0.1:7382127.0.0.1:7384Adding replica 127.0.0.1:7383 to 127.0.0.1:7380Adding replica 127.0.0.1:7385 to 127.0.0.1:7382Adding replica 127.0.0.1:7381 to 127.0.0.1:7384>>> Trying to optimize slaves allocation for anti-affinity[WARNING] Some slaves are in the same host as their masterM: c25675d021c377c91f860986025e3779d89ede79 127.0.0.1:7380 slots:0-5460 (5461 slots) masterM: 58980a81b49de31383802d7d21d6782881678922 127.0.0.1:7382 slots:5461-10922 (5462 slots) masterM: 3f00a37d2c7a5ea40671c8f2934f66d059157a4a 127.0.0.1:7384 slots:10923-16383 (5461 slots) masterS: 6f7dd93973a8332305831e6b7b5e2c54c15b3b51 127.0.0.1:7381 replicates 3f00a37d2c7a5ea40671c8f2934f66d059157a4aS: 03e01f82a935ed7f977af092e6a9cb71057df68a 127.0.0.1:7383 replicates c25675d021c377c91f860986025e3779d89ede79S: 2cf3883e974a709b7070d6c4d7c528d9fa813358 127.0.0.1:7385 replicates 58980a81b49de31383802d7d21d6782881678922Can 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 clusterWaiting for the cluster to join....>>> Performing Cluster Check (using node 127.0.0.1:7380)M: c25675d021c377c91f860986025e3779d89ede79 127.0.0.1:7380 slots:0-5460 (5461 slots) master 1 additional replica(s)M: 58980a81b49de31383802d7d21d6782881678922 127.0.0.1:7382 slots:5461-10922 (5462 slots) master 1 additional replica(s)S: 2cf3883e974a709b7070d6c4d7c528d9fa813358 127.0.0.1:7385 slots: (0 slots) slave replicates 58980a81b49de31383802d7d21d6782881678922S: 03e01f82a935ed7f977af092e6a9cb71057df68a 127.0.0.1:7383 slots: (0 slots) slave replicates c25675d021c377c91f860986025e3779d89ede79S: 6f7dd93973a8332305831e6b7b5e2c54c15b3b51 127.0.0.1:7381 slots: (0 slots) slave replicates 3f00a37d2c7a5ea40671c8f2934f66d059157a4aM: 3f00a37d2c7a5ea40671c8f2934f66d059157a4a 127.0.0.1:7384 slots:10923-16383 (5461 slots) master 1 additional replica(s)[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.
推荐阅读
- 软件测试基础——Linux系统搭建MySQL数据库
- Java 分布式任务调度平台:PowerJob 快速开始+配置详解
- 淘宝活动中的商品可以改库存吗? 淘宝库存怎么快速修改
- excel中快速输入√与×并自动标注颜色,你不会,同事1分钟就搞定
- 怎么样才能快速健身?
- 教你如何快速开发一个Dubbo应用
- 网络工程师快速入门---网络架构及传输介质详解
- 运动快速减肥有哪些方法?
- 怎么快速减肥不运动呢?
- 怎么快速运动减肥呢?