Redis入门到高可用-8.Redis Cluster

1.概要

  • 呼唤集群
  • 数据分布
  • 搭建集群
  • 集群伸缩
  • 客户端路由
  • 集群原理
  • 开发运维常见问题

2.呼唤集群

Redis入门到高可用-8.Redis Cluster_第1张图片
呼唤集群1.png

Redis入门到高可用-8.Redis Cluster_第2张图片
呼唤集群2.png

Redis入门到高可用-8.Redis Cluster_第3张图片
呼唤集群3.png

Redis入门到高可用-8.Redis Cluster_第4张图片
呼唤集群4.png

Redis入门到高可用-8.Redis Cluster_第5张图片
呼唤集群5.png

3.数据分布

Redis入门到高可用-8.Redis Cluster_第6张图片
数据分区1.png

Redis入门到高可用-8.Redis Cluster_第7张图片
数据分区2.png

Redis入门到高可用-8.Redis Cluster_第8张图片
数据分区3.png

Redis入门到高可用-8.Redis Cluster_第9张图片
数据分区4.png

4.节点取余

Redis入门到高可用-8.Redis Cluster_第10张图片
节点取余1.png

Redis入门到高可用-8.Redis Cluster_第11张图片
节点取余2.png

Redis入门到高可用-8.Redis Cluster_第12张图片
节点取余3.png

Redis入门到高可用-8.Redis Cluster_第13张图片
节点取余4.png

Redis入门到高可用-8.Redis Cluster_第14张图片
节点取余5.png

5.一致性哈希

Redis入门到高可用-8.Redis Cluster_第15张图片
一致性哈希1.png

Redis入门到高可用-8.Redis Cluster_第16张图片
一致性哈希2.png

Redis入门到高可用-8.Redis Cluster_第17张图片
一致性哈希3.png

Redis入门到高可用-8.Redis Cluster_第18张图片
一致性哈希4.png

Redis入门到高可用-8.Redis Cluster_第19张图片
一致性哈希5.png

6.虚拟槽分区

Redis入门到高可用-8.Redis Cluster_第20张图片
虚拟槽分区1.png

Redis入门到高可用-8.Redis Cluster_第21张图片
虚拟槽分区2.png

7.基本架构

Redis入门到高可用-8.Redis Cluster_第22张图片
Redis架构1.png

Redis入门到高可用-8.Redis Cluster_第23张图片
Redis架构2.png

Redis入门到高可用-8.Redis Cluster_第24张图片
Redis架构3.png

Redis入门到高可用-8.Redis Cluster_第25张图片
Redis架构4.png

Redis入门到高可用-8.Redis Cluster_第26张图片
Redis架构5.png

Redis入门到高可用-8.Redis Cluster_第27张图片
Redis架构6.png

Redis入门到高可用-8.Redis Cluster_第28张图片
Redis架构7.png

Redis入门到高可用-8.Redis Cluster_第29张图片
Redis架构8.png

Redis入门到高可用-8.Redis Cluster_第30张图片
Redis架构9.png

8.安装

Redis入门到高可用-8.Redis Cluster_第31张图片
Redis Cluster安装1.png

Redis入门到高可用-8.Redis Cluster_第32张图片
Redis Cluster安装2.png

Redis入门到高可用-8.Redis Cluster_第33张图片
Redis Cluster安装3.png

Redis入门到高可用-8.Redis Cluster_第34张图片
Redis Cluster安装4.png

Redis入门到高可用-8.Redis Cluster_第35张图片
Redis Cluster安装5.png

Redis入门到高可用-8.Redis Cluster_第36张图片
Redis Cluster安装6.png

Redis入门到高可用-8.Redis Cluster_第37张图片
Redis Cluster安装7.png

Redis入门到高可用-8.Redis Cluster_第38张图片
Redis Cluster安装8.png
  • 配置Redis.conf
    port 7000
    daemonize yes
    pidfile /var/run/redis-7000.pid
    dbfilename "dump-7000.rdb"
    logfile "7000.log"
    dir "/opt/soft/redis/redis/data/"
    cluster-enabled yes
    cluster-config-file nodes-7000.conf
    cluster-require-full-coverage no
    
  • 搭建集群-meet
    [root@master redis-cluster-config]# redis-cli -p 7000 cluster meet 127.0.0.1 7001
    OK
    [root@master redis-cluster-config]# redis-cli -p 7000 cluster meet 127.0.0.1 7002
    OK
    [root@master redis-cluster-config]# redis-cli -p 7000 cluster meet 127.0.0.1 7003
    OK
    [root@master redis-cluster-config]# redis-cli -p 7000 cluster meet 127.0.0.1 7004
    OK
    [root@master redis-cluster-config]# redis-cli -p 7000 cluster meet 127.0.0.1 7005
    OK
    [root@master redis-cluster-config]# redis-cli -p 7000 cluster nodes
    c09e9379e37ee282219a07399bfb0dcbb933159a 127.0.0.1:7001@17001 master - 0 1567952635000 1 connected
    df740a3f64985bb4645c1f9fff276d29ad1bcb25 127.0.0.1:7000@17000 myself,master - 0 1567952636000 0 connected
    2e6827954a8dd1b7a1455e9aec057cb89fd56fa4 127.0.0.1:7003@17003 master - 0 1567952636853 3 connected
    0fee682eb0247d98bcffe694fe745af194f708dd 127.0.0.1:7005@17005 master - 0 1567952636000 5 connected
    97969f534d03b6c7c346df035e35b676c79e2d51 127.0.0.1:7004@17004 master - 0 1567952637000 4 connected
    80602baaf52498f27be91a8b9169dc78de6e6e07 127.0.0.1:7002@17002 master - 0 1567952637855 2 connected
    [root@master redis-cluster-config]# redis-cli -p 7000 cluster info
    cluster_state:fail
    cluster_slots_assigned:0
    cluster_slots_ok:0
    cluster_slots_pfail:0
    cluster_slots_fail:0
    cluster_known_nodes:6
    cluster_size:0
    cluster_current_epoch:5
    cluster_my_epoch:0
    cluster_stats_messages_ping_sent:208
    cluster_stats_messages_pong_sent:68
    cluster_stats_messages_meet_sent:6
    cluster_stats_messages_sent:282
    cluster_stats_messages_ping_received:68
    cluster_stats_messages_pong_received:64
    cluster_stats_messages_received:132
    
  • 分配槽

    vim addslots.sh

    start=$1
    end=$2
    port=$3
    for slot in `seq ${start} ${end}`
    do
        echo "port:${port},slot:${slot}"
        redis-cli -p ${port} cluster addslots ${slot}
    done
    
    [root@master redis-cluster-config]# sh addslots.sh 0 5461 7000
    [root@master redis-cluster-config]# sh addslots.sh 5462 10922 7001
    [root@master redis-cluster-config]# sh addslots.sh 10923 16383 7002
    [root@master redis-cluster-config]# redis-cli -p 7000 cluster info
    cluster_state:ok
    cluster_slots_assigned:16384
    cluster_slots_ok:16384
    cluster_slots_pfail:0
    cluster_slots_fail:0
    cluster_known_nodes:6
    cluster_size:3
    cluster_current_epoch:5
    cluster_my_epoch:0
    cluster_stats_messages_ping_sent:948
    cluster_stats_messages_pong_sent:830
    cluster_stats_messages_meet_sent:6
    cluster_stats_messages_sent:1784
    cluster_stats_messages_ping_received:830
    cluster_stats_messages_pong_received:804
    cluster_stats_messages_received:1634
    
  • 搭建集群-主从分配
    [root@master redis-cluster-config]# redis-cli -p 7004 cluster replicate c09e9379e37ee282219a07399bfb0dcbb933159a
    OK
    [root@master redis-cluster-config]# redis-cli -p 7005 cluster replicate 80602baaf52498f27be91a8b9169dc78de6e6e07
    OK
    [root@master redis-cluster-config]# redis-cli -p 7000 cluster nodes
    c09e9379e37ee282219a07399bfb0dcbb933159a 127.0.0.1:7001@17001 master - 0 1567953967031 1 connected 5462-10922
    df740a3f64985bb4645c1f9fff276d29ad1bcb25 127.0.0.1:7000@17000 myself,master - 0 1567953964000 0 connected 0-5461
    2e6827954a8dd1b7a1455e9aec057cb89fd56fa4 127.0.0.1:7003@17003 slave df740a3f64985bb4645c1f9fff276d29ad1bcb25 0 1567953966027 3 connected
    0fee682eb0247d98bcffe694fe745af194f708dd 127.0.0.1:7005@17005 slave 80602baaf52498f27be91a8b9169dc78de6e6e07 0 1567953965024 5 connected
    97969f534d03b6c7c346df035e35b676c79e2d51 127.0.0.1:7004@17004 slave c09e9379e37ee282219a07399bfb0dcbb933159a 0 1567953968035 4 connected
    80602baaf52498f27be91a8b9169dc78de6e6e07 127.0.0.1:7002@17002 master - 0 1567953966000 2 connected 10923-16383
    [root@master redis-cluster-config]# redis-cli -p 7000 cluster slots
    1) 1) (integer) 5462
       2) (integer) 10922
       3) 1) "127.0.0.1"
          2) (integer) 7001
          3) "c09e9379e37ee282219a07399bfb0dcbb933159a"
       4) 1) "127.0.0.1"
          2) (integer) 7004
          3) "97969f534d03b6c7c346df035e35b676c79e2d51"
    2) 1) (integer) 0
       2) (integer) 5461
       3) 1) "127.0.0.1"
          2) (integer) 7000
          3) "df740a3f64985bb4645c1f9fff276d29ad1bcb25"
       4) 1) "127.0.0.1"
          2) (integer) 7003
          3) "2e6827954a8dd1b7a1455e9aec057cb89fd56fa4"
    3) 1) (integer) 10923
       2) (integer) 16383
       3) 1) "127.0.0.1"
          2) (integer) 7002
          3) "80602baaf52498f27be91a8b9169dc78de6e6e07"
       4) 1) "127.0.0.1"
          2) (integer) 7005
          3) "0fee682eb0247d98bcffe694fe745af194f708dd"
    [root@master redis-cluster-config]# redis-cli -c -p 7000
    127.0.0.1:7000> set hello world
    OK
    127.0.0.1:7000> exit
    

9.Ruby

Redis入门到高可用-8.Redis Cluster_第39张图片
Ruby1.png

Redis入门到高可用-8.Redis Cluster_第40张图片
Ruby2.png

Redis入门到高可用-8.Redis Cluster_第41张图片
Ruby3.png

Redis入门到高可用-8.Redis Cluster_第42张图片
Ruby4.png
[root@master ~]# gem install redis-4.1.2.gem 
ERROR:  Loading command: install (LoadError)
  cannot load such file -- zlib
ERROR:  While executing gem ... (NoMethodError)
  undefined method `invoke_with_build_args' for nil:NilClass

解决问题

[root@master ~]# yum install zlib-devel
[root@master ~]# cd /root/ruby-2.6.4/ext/zlib
[root@master zlib]# ruby extconf.rb
[root@master zlib]# vim Makefile 
# 将 $(top_srcdir)/include/ruby.h 改为 ../../include/ruby.h
[root@master zlib]# make && make install
[root@master zlib]# yum install openssl-devel
[root@master zlib]# cd ../openssl/
[root@master openssl]# ruby extconf.rb 
[root@master openssl]# vim Makefile 
# 将 $(top_srcdir)/include/ruby.h 改为 ../../include/ruby.h
[root@master openssl]# make && make install
[root@master ~]# gem install redis-4.1.2.gem 
Successfully installed redis-4.1.2
Parsing documentation for redis-4.1.2
Installing ri documentation for redis-4.1.2
Done installing documentation for redis after 1 seconds
1 gem installed
[root@master src]# ./redis-trib.rb
WARNING: redis-trib.rb is not longer available!
You should use redis-cli instead.

All commands and features belonging to redis-trib.rb have been moved
to redis-cli.
In order to use them you should call redis-cli with the --cluster
option followed by the subcommand name, arguments and options.

Use the following syntax:
redis-cli --cluster SUBCOMMAND [ARGUMENTS] [OPTIONS]

Example:
redis-cli --cluster info 127.0.0.1:7000

To get help about all subcommands, type:
redis-cli --cluster help

[root@master ~]# redis-cli –cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002

10.原生命令与redis-trib.rb对比

Redis入门到高可用-8.Redis Cluster_第43张图片
Redis Cluster总结.png

emmm,Redis5.0 把redis-trib.rb集成到了redis-cli中

你可能感兴趣的:(Redis入门到高可用-8.Redis Cluster)