• redis集群搭建详细与卡槽迁移遇到的坑


    前言

    https://my.oschina.net/liabio/blog/4420142

    redis5.0.0之前操作 redis集群用的是 ruby写的脚本 redis-trib.rb,这样带来的弊端就是需要安装 rubygems环境,官方拉取的 docker镜像里是没有 redis-trib.rbruby环境的,需要自己安装,在国内网络环境下还是比较费时复杂的,也不容易成功,而且最后制作的docker镜像也比较大。再者安装的 ruby、redis扩展版本不对,也会导致操作集群时,报各种各样的错误。

    最重要的硬伤是 redis-trib.rb不能操作带密码的 redis集群,虽然 github上有人在 redis-trib.rb脚本基础上已经加了密码支持。但对于 move_slots的迁移卡槽相关的操作,我试了还是没加。可以查看以下的提交记录:

    Redis-Cluster: Add support to auth in redis-trib.rb #4288

    redis5.0.0之后的 redis-cli可以直接操作 redis集群,可以支持带密码操作,可以说带来了很大的方便。但是在 redis4.0.7版本之前迁移卡槽本来就是不支持密码 auth参数的,以下命令中的 [AUTH password]redis4.0.7版本才支持。

    1. MIGRATE host port key|"" destination-db timeout [COPY] [REPLACE] [AUTH password] [KEYS key [key ...]]

    具体可以查看官方文档:MIGRATE说明文档

    Options COPY -- Do not remove the key from the local instance. REPLACE -- Replace existing key on the remote instance. KEYS -- If the key argument is an empty string, the command will instead migrate all the keys that follow the KEYS option (see the above section for more info). AUTH -- Authenticate with the given password to the remote instance. COPY and REPLACE are available only in 3.0 and above. KEYS is available starting with Redis 3.0.6. AUTH is available starting with Redis 4.0.7.

    我们最近容器化时,用到的版本为 redis3.2.6,在 redis集群有数据(有hash数据时必现),且带有密码时,从 3主3从扩规模到 5主5从时,用 5.0.7的redis-cli操作 redis:3.2.6集群,执行迁移卡槽命令时,报 ERR syntax error错误。试着用 github上加密码的 redis-trib.rb操作 3.2.6集群,进行卡槽迁移时报错 [ERR]CallingMIGRATE:ERRTargetinstance repliedwitherror:NOAUTHAuthenticationrequired这个是因为 github上的 redis-trib.rb没在 move_slots操作时,加密码参数。于是乎,我试着自己在迁移卡槽的地方传入密码参数,像下面这样:

    1. source.r.client.call(["migrate",target.info[:host],target.info[:port],"",0,@timeout,:auth,target.info[:password],:keys,*keys])

    加了之后执行卡槽迁移时,也报 ERR syntax error错误。从这可以看出, redis3.2.6集群确实在 migrate时不支持密码参数。那么下面在 redis4.0.7集群上进行验证,是否可以正常迁移卡槽。

    创建三主三从集群

    创建configmaps

    将以下内容保存到 redis-test.conf文件:

    1. #设置为守护进程

    2. daemonize no

    3. #Redis运行的进程pid文件

    4. pidfile redis-6397.pid

    5. #Redis服务端口号

    6. port 6379

    7. #Redis服务绑定ip

    8. #bind 192.168.100.144

    9. bind {PODIP}

    10. #最大内存

    11. maxmemory 2g

    12. #开启集群模式

    13. cluster-enabled yes

    14. #节点配置文件

    15. cluster-config-file nodes-6397.conf

    16. #集群节点超时时间(单位:毫秒)

    17. cluster-node-timeout 15000

    18. #集群是否需要所有的slot都分配给在线节点,才能正常访问

    19. cluster-require-full-coverage no

    20. #工作目录(aof、rdb、日志文件)

    21. dir /data

    22. #tcp-backlog

    23. tcp-backlog 511

    24. #客户端闲置多少秒后关闭连接(单位:秒)

    25. timeout 300

    26. #检测TCP连接活性的周期(单位:秒)

    27. tcp-keepalive 60

    28. #redis密码

    29. requirepass test123

    30. masterauth test123

    31. #日志级别

    32. loglevel notice

    33. #日志记录目录

    34. logfile "redis-6397.log"

    35. #可用的数据库数

    36. databases 16

    37. #RDB保存条件

    38. save 900 1

    39. save 300 10

    40. save 60 10000

    41. #bgsave执行错误,是否停止Redis接受请求

    42. stop-writes-on-bgsave-error no

    43. #RDB文件是否压缩

    44. rdbcompression yes

    45. #RDB文件是否使用校验和

    46. rdbchecksum yes

    47. #RDB文件名

    48. dbfilename dump-6397.rdb

    49. #当从节点与主节点连接中断时,如果此参数值设置为“yes”,从节点可以继续处理客户端的

    50. #请求。否则除info和slaveof命令之外,拒绝的所有请求并统一回复"SYNC with master in #progress"

    51. slave-serve-stale-data yes

    52. #从节点是否开启只读模式,集群架构下从节点默认读写都不可用,需要调用readyonly命令#开启只读模式

    53. slave-read-only yes

    54. #是否开启无盘复制

    55. repl-diskless-sync no

    56. #开启无盘复制后,需要延迟多少秒后进行创建RDB操作,一般用于同时加入多个从节点时,#保证多个从节点可共享RDB

    57. repl-diskless-sync-delay 5

    58. #是否开启主从复制socket的NO_DELAY选项:yes:Redis会合并小的TCP包来节省带宽,但##是这样增加同步延迟,造成主#从数据不一致;no:主节点会立即发送同步数据,没有延迟

    59. repl-disable-tcp-nodelay no

    60. #从节点的优先级

    61. slave-priority 100

    62. #是否开启AOF持久化模式

    63. appendonly no

    64. #Lua脚本“超时时间”(单位:毫秒)

    65. lua-time-limit 5000

    66. #慢查询被记录的阀值(单位微秒)

    67. slowlog-log-slower-than 10000

    68. #最多记录慢查询的条数

    69. slowlog-max-len 1000

    70. #Redis服务内存延迟监控

    71. latency-monitor-threshold 0

    72. notify-keyspace-events ""

    73. hash-max-ziplist-entries 512

    74. hash-max-ziplist-value 64

    75. list-max-ziplist-entries 512

    76. list-max-ziplist-value 64

    77. set-max-intset-entries 512

    78. zset-max-ziplist-entries 128

    79. zset-max-ziplist-value 64

    80. hll-sparse-max-bytes 3000

    81. #是否激活重置哈希

    82. activerehashing yes

    83. #客户端输出缓冲区限制

    84. client-output-buffer-limit normal 0 0 0

    85. client-output-buffer-limit slave 512mb 128mb 60

    86. client-output-buffer-limit pubsub 32mb 8mb 60

    87. #复制积压缓存区大小

    88. repl-backlog-size 256mb

    89. #redis server执行后台任务的频率,默认为10

    90. hz 10

    91. #最大客户端连接数

    92. maxclients 15000

    使用以下命令创建 configmaps

    1. kubectl create cm redis-test-conf --from-file=redis.conf=redis-test.conf

    创建redis实例

    将以下 yaml内容保存到redis-sts.yaml中:

    1. apiVersion: apps/v1

    2. kind: StatefulSet

    3. metadata:

    4. name: redis-test

    5. namespace: default

    6. spec:

    7. podManagementPolicy: OrderedReady

    8. replicas: 10

    9. revisionHistoryLimit: 10

    10. selector:

    11. matchLabels:

    12. name: redis-test

    13. serviceName: redis-test

    14. template:

    15. metadata:

    16. labels:

    17. name: redis-test

    18. spec:

    19. containers:

    20. - command:

    21. - sh

    22. - -c

    23. - cp /config/redis.conf /data/; sed -i "s?{PODIP}?${PODIP}?g" /data/redis.conf ;redis-server /data/redis.conf

    24. image: redis:4.0.7

    25. env:

    26. - name: PODIP

    27. valueFrom:

    28. fieldRef:

    29. apiVersion: v1

    30. fieldPath: status.podIP

    31. imagePullPolicy: IfNotPresent

    32. name: redis

    33. ports:

    34. - containerPort: 6379

    35. name: redis

    36. protocol: TCP

    37. resources: {}

    38. terminationMessagePath: /dev/termination-log

    39. terminationMessagePolicy: File

    40. volumeMounts:

    41. - mountPath: /config

    42. name: redis-config

    43. - mountPath: /tmp

    44. name: tmp-dir

    45. dnsPolicy: ClusterFirst

    46. restartPolicy: Always

    47. schedulerName: default-scheduler

    48. securityContext: {}

    49. terminationGracePeriodSeconds: 30

    50. volumes:

    51. - configMap:

    52. defaultMode: 420

    53. name: redis-test-conf

    54. name: redis-config

    55. - emptyDir: {}

    56. name: tmp-dir

    57. updateStrategy:

    58. rollingUpdate:

    59. partition: 0

    60. type: RollingUpdate

    这里使用 redis:4.0.7的docker镜像,创建如下10个pod:

    1. [root@liabio ~]# kubectl apply -f redis-sts.yaml

    2. [root@liabio ~]# kubectl get pod -owide

    3. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES

    4. redis-test-0 1/1 Running 0 60s 192.168.155.117 liabio <none> <none>

    5. redis-test-1 1/1 Running 0 59s 192.168.155.91 liabio <none> <none>

    6. redis-test-2 1/1 Running 0 58s 192.168.155.112 liabio <none> <none>

    7. redis-test-3 1/1 Running 0 55s 192.168.155.103 liabio <none> <none>

    8. redis-test-4 1/1 Running 0 54s 192.168.155.102 liabio <none> <none>

    9. redis-test-5 1/1 Running 0 52s 192.168.155.78 liabio <none> <none>

    10. redis-test-6 1/1 Running 0 51s 192.168.155.108 liabio <none> <none>

    11. redis-test-7 1/1 Running 0 49s 192.168.155.111 liabio <none> <none>

    12. redis-test-8 1/1 Running 0 47s 192.168.155.114 liabio <none> <none>

    13. redis-test-9 1/1 Running 0 45s 192.168.155.73 liabio <none> <none>

    使用redis-cli 5.0.7操作集群

    使用 redis-cli5.0.7版本操作集群:

    1. [root@liabio ~]# redis-cli -v

    2. redis-cli 5.0.7

    创建3master集群

    先选3个master出来,创建集群:

    1. [root@liabio ~]# echo yes | redis-cli --cluster create 192.168.155.117:6379 192.168.155.91:6379 192.168.155.112:6379 -a test123

    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

    3. >>> Performing hash slots allocation on 3 nodes...

    4. Master[0] -> Slots 0 - 5460

    5. Master[1] -> Slots 5461 - 10922

    6. Master[2] -> Slots 10923 - 16383

    7. M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379

    8. slots:[0-5460] (5461 slots) master

    9. M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379

    10. slots:[5461-10922] (5462 slots) master

    11. M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379

    12. slots:[10923-16383] (5461 slots) master

    13. Can I set the above configuration? (type 'yes' to accept): >>> Nodes configuration updated

    14. >>> Assign a different config epoch to each node

    15. >>> Sending CLUSTER MEET messages to join the cluster

    16. Waiting for the cluster to join

    17. .

    18. >>> Performing Cluster Check (using node 192.168.155.117:6379)

    19. M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379

    20. slots:[0-5460] (5461 slots) master

    21. M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379

    22. slots:[5461-10922] (5462 slots) master

    23. M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379

    24. slots:[10923-16383] (5461 slots) master

    25. [OK] All nodes agree about slots configuration.

    26. >>> Check for open slots...

    27. >>> Check slots coverage...

    28. [OK] All 16384 slots covered.

    添加slave1

    1. [root@liabio ~]# redis-cli --cluster add-node 192.168.155.103:6379 192.168.155.117:6379 --cluster-slave --cluster-master-id f070ddf68e39896af42dc08251199cda7c8b9b92 -a test123

    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

    3. >>> Adding node 192.168.155.103:6379 to cluster 192.168.155.117:6379

    4. >>> Performing Cluster Check (using node 192.168.155.117:6379)

    5. M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379

    6. slots:[0-5460] (5461 slots) master

    7. M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379

    8. slots:[5461-10922] (5462 slots) master

    9. M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379

    10. slots:[10923-16383] (5461 slots) master

    11. [OK] All nodes agree about slots configuration.

    12. >>> Check for open slots...

    13. >>> Check slots coverage...

    14. [OK] All 16384 slots covered.

    15. >>> Send CLUSTER MEET to node 192.168.155.103:6379 to make it join the cluster.

    16. Waiting for the cluster to join

    17. >>> Configure node as replica of 192.168.155.117:6379.

    18. [OK] New node added correctly.

    添加slave2

    1. [root@liabio ~]# redis-cli --cluster add-node 192.168.155.102:6379 192.168.155.117:6379 --cluster-slave --cluster-master-id c4ab027656d55b800cc54063493bca198a5e1385 -a test123

    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

    3. >>> Adding node 192.168.155.102:6379 to cluster 192.168.155.117:6379

    4. >>> Performing Cluster Check (using node 192.168.155.117:6379)

    5. M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379

    6. slots:[0-5460] (5461 slots) master

    7. 1 additional replica(s)

    8. S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379

    9. slots: (0 slots) slave

    10. replicates f070ddf68e39896af42dc08251199cda7c8b9b92

    11. M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379

    12. slots:[5461-10922] (5462 slots) master

    13. M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379

    14. slots:[10923-16383] (5461 slots) master

    15. [OK] All nodes agree about slots configuration.

    16. >>> Check for open slots...

    17. >>> Check slots coverage...

    18. [OK] All 16384 slots covered.

    19. >>> Send CLUSTER MEET to node 192.168.155.102:6379 to make it join the cluster.

    20. Waiting for the cluster to join

    21. >>> Configure node as replica of 192.168.155.91:6379.

    22. [OK] New node added correctly.

    添加slave3

    1. [root@liabio ~]# redis-cli --cluster add-node 192.168.155.78:6379 192.168.155.117:6379 --cluster-slave --cluster-master-id 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 -a test123

    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

    3. >>> Adding node 192.168.155.78:6379 to cluster 192.168.155.117:6379

    4. >>> Performing Cluster Check (using node 192.168.155.117:6379)

    5. M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379

    6. slots:[0-5460] (5461 slots) master

    7. 1 additional replica(s)

    8. S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379

    9. slots: (0 slots) slave

    10. replicates f070ddf68e39896af42dc08251199cda7c8b9b92

    11. M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379

    12. slots:[10923-16383] (5461 slots) master

    13. S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379

    14. slots: (0 slots) slave

    15. replicates c4ab027656d55b800cc54063493bca198a5e1385

    16. M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379

    17. slots:[5461-10922] (5462 slots) master

    18. 1 additional replica(s)

    19. [OK] All nodes agree about slots configuration.

    20. >>> Check for open slots...

    21. >>> Check slots coverage...

    22. [OK] All 16384 slots covered.

    23. >>> Send CLUSTER MEET to node 192.168.155.78:6379 to make it join the cluster.

    24. Waiting for the cluster to join

    25. >>> Configure node as replica of 192.168.155.112:6379.

    26. [OK] New node added correctly.

    27. [root@liabio ~]#

    给集群里新增各种数据类型

    分别给集群里设置hash类型的hash1;list类型的list1;有序集合(sorted set)类型的在zset1;string类型的a;set类型的set1

    1. [root@liabio ~]# redis-cli -c -h 192.168.155.112 -p 6379 -a test123

    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

    3. 192.168.155.112:6379>

    4. 192.168.155.112:6379> HMSET hash1 name1 "redis sasa"

    5. -> Redirected to slot [4414] located at 192.168.155.117:6379

    6. OK

    7. 192.168.155.117:6379> LPUSH list1 aa

    8. -> Redirected to slot [7141] located at 192.168.155.91:6379

    9. (integer) 1

    10. 192.168.155.91:6379> zadd zset1 1 aa

    11. -> Redirected to slot [4341] located at 192.168.155.117:6379

    12. (integer) 1

    13. 192.168.155.117:6379> set a b

    14. -> Redirected to slot [15495] located at 192.168.155.112:6379

    15. OK

    16. 192.168.155.112:6379> SADD set1 redis

    17. -> Redirected to slot [3037] located at 192.168.155.117:6379

    18. (integer) 1

    19. 192.168.155.117:6379>

    20. [root@liabio ~]#

    21. [root@liabio ~]# redis-cli -a test123 --cluster check 192.168.155.117:6379

    22. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

    23. 192.168.155.117:6379 (f070ddf6...) -> 3 keys | 5461 slots | 1 slaves.

    24. 192.168.155.112:6379 (8d1e7150...) -> 1 keys | 5461 slots | 1 slaves.

    25. 192.168.155.91:6379 (c4ab0276...) -> 1 keys | 5462 slots | 1 slaves.

    26. [OK] 5 keys in 3 masters.

    27. 0.00 keys per slot on average.

    28. >>> Performing Cluster Check (using node 192.168.155.117:6379)

    29. M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379

    30. slots:[0-5460] (5461 slots) master

    31. 1 additional replica(s)

    32. S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379

    33. slots: (0 slots) slave

    34. replicates f070ddf68e39896af42dc08251199cda7c8b9b92

    35. M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379

    36. slots:[10923-16383] (5461 slots) master

    37. 1 additional replica(s)

    38. S: 0a6188b6bf590c928a2f7b1b0de9aeb206977d72 192.168.155.78:6379

    39. slots: (0 slots) slave

    40. replicates 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650

    41. S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379

    42. slots: (0 slots) slave

    43. replicates c4ab027656d55b800cc54063493bca198a5e1385

    44. M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379

    45. slots:[5461-10922] (5462 slots) master

    46. 1 additional replica(s)

    47. [OK] All nodes agree about slots configuration.

    48. >>> Check for open slots...

    49. >>> Check slots coverage...

    50. [OK] All 16384 slots covered.

    扩容为五主五从集群

    添加新的master1

    1. [root@liabio ~]# redis-cli --cluster add-node 192.168.155.108:6379 192.168.155.117:6379 -a test123

    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

    3. >>> Adding node 192.168.155.108:6379 to cluster 192.168.155.117:6379

    4. >>> Performing Cluster Check (using node 192.168.155.117:6379)

    5. M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379

    6. slots:[0-5460] (5461 slots) master

    7. 1 additional replica(s)

    8. S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379

    9. slots: (0 slots) slave

    10. replicates f070ddf68e39896af42dc08251199cda7c8b9b92

    11. M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379

    12. slots:[10923-16383] (5461 slots) master

    13. 1 additional replica(s)

    14. S: 0a6188b6bf590c928a2f7b1b0de9aeb206977d72 192.168.155.78:6379

    15. slots: (0 slots) slave

    16. replicates 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650

    17. S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379

    18. slots: (0 slots) slave

    19. replicates c4ab027656d55b800cc54063493bca198a5e1385

    20. M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379

    21. slots:[5461-10922] (5462 slots) master

    22. 1 additional replica(s)

    23. [OK] All nodes agree about slots configuration.

    24. >>> Check for open slots...

    25. >>> Check slots coverage...

    26. [OK] All 16384 slots covered.

    27. >>> Send CLUSTER MEET to node 192.168.155.108:6379 to make it join the cluster.

    28. [OK] New node added correctly.

    添加新的master2

    1. [root@liabio ~]# redis-cli --cluster add-node 192.168.155.111:6379 192.168.155.117:6379 -a test123

    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

    3. >>> Adding node 192.168.155.111:6379 to cluster 192.168.155.117:6379

    4. >>> Performing Cluster Check (using node 192.168.155.117:6379)

    5. M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379

    6. slots:[0-5460] (5461 slots) master

    7. 1 additional replica(s)

    8. S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379

    9. slots: (0 slots) slave

    10. replicates f070ddf68e39896af42dc08251199cda7c8b9b92

    11. M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379

    12. slots:[10923-16383] (5461 slots) master

    13. 1 additional replica(s)

    14. S: 0a6188b6bf590c928a2f7b1b0de9aeb206977d72 192.168.155.78:6379

    15. slots: (0 slots) slave

    16. replicates 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650

    17. S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379

    18. slots: (0 slots) slave

    19. replicates c4ab027656d55b800cc54063493bca198a5e1385

    20. M: 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2 192.168.155.108:6379

    21. slots: (0 slots) master

    22. M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379

    23. slots:[5461-10922] (5462 slots) master

    24. 1 additional replica(s)

    25. [OK] All nodes agree about slots configuration.

    26. >>> Check for open slots...

    27. >>> Check slots coverage...

    28. [OK] All 16384 slots covered.

    29. >>> Send CLUSTER MEET to node 192.168.155.111:6379 to make it join the cluster.

    30. [OK] New node added correctly.

    31. [root@liabio ~]# redis-cli -a test123 --cluster check 192.168.155.117:6379

    32. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

    33. 192.168.155.117:6379 (f070ddf6...) -> 3 keys | 5461 slots | 1 slaves.

    34. 192.168.155.111:6379 (1b3b59ff...) -> 0 keys | 0 slots | 0 slaves.

    35. 192.168.155.112:6379 (8d1e7150...) -> 1 keys | 5461 slots | 1 slaves.

    36. 192.168.155.108:6379 (78ad2489...) -> 0 keys | 0 slots | 0 slaves.

    37. 192.168.155.91:6379 (c4ab0276...) -> 1 keys | 5462 slots | 1 slaves.

    38. [OK] 5 keys in 5 masters.

    39. 0.00 keys per slot on average.

    40. >>> Performing Cluster Check (using node 192.168.155.117:6379)

    41. M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379

    42. slots:[0-5460] (5461 slots) master

    43. 1 additional replica(s)

    44. M: 1b3b59ff2b7ecf0ae67568104501450b94aa9ac0 192.168.155.111:6379

    45. slots: (0 slots) master

    46. S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379

    47. slots: (0 slots) slave

    48. replicates f070ddf68e39896af42dc08251199cda7c8b9b92

    49. M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379

    50. slots:[10923-16383] (5461 slots) master

    51. 1 additional replica(s)

    52. S: 0a6188b6bf590c928a2f7b1b0de9aeb206977d72 192.168.155.78:6379

    53. slots: (0 slots) slave

    54. replicates 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650

    55. S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379

    56. slots: (0 slots) slave

    57. replicates c4ab027656d55b800cc54063493bca198a5e1385

    58. M: 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2 192.168.155.108:6379

    59. slots: (0 slots) master

    60. M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379

    61. slots:[5461-10922] (5462 slots) master

    62. 1 additional replica(s)

    63. [OK] All nodes agree about slots configuration.

    64. >>> Check for open slots...

    65. >>> Check slots coverage...

    66. [OK] All 16384 slots covered.

    添加新的slave1

    1. [root@liabio ~]# redis-cli --cluster add-node 192.168.155.114:6379 192.168.155.117:6379 --cluster-slave --cluster-master-id 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2 -a test123

    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

    3. >>> Adding node 192.168.155.114:6379 to cluster 192.168.155.117:6379

    4. >>> Performing Cluster Check (using node 192.168.155.117:6379)

    5. M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379

    6. slots:[0-5460] (5461 slots) master

    7. 1 additional replica(s)

    8. M: 1b3b59ff2b7ecf0ae67568104501450b94aa9ac0 192.168.155.111:6379

    9. slots: (0 slots) master

    10. S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379

    11. slots: (0 slots) slave

    12. replicates f070ddf68e39896af42dc08251199cda7c8b9b92

    13. M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379

    14. slots:[10923-16383] (5461 slots) master

    15. 1 additional replica(s)

    16. S: 0a6188b6bf590c928a2f7b1b0de9aeb206977d72 192.168.155.78:6379

    17. slots: (0 slots) slave

    18. replicates 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650

    19. S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379

    20. slots: (0 slots) slave

    21. replicates c4ab027656d55b800cc54063493bca198a5e1385

    22. M: 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2 192.168.155.108:6379

    23. slots: (0 slots) master

    24. M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379

    25. slots:[5461-10922] (5462 slots) master

    26. 1 additional replica(s)

    27. [OK] All nodes agree about slots configuration.

    28. >>> Check for open slots...

    29. >>> Check slots coverage...

    30. [OK] All 16384 slots covered.

    31. >>> Send CLUSTER MEET to node 192.168.155.114:6379 to make it join the cluster.

    32. Waiting for the cluster to join

    33. >>> Configure node as replica of 192.168.155.108:6379.

    34. [OK] New node added correctly.

    添加新的slave2

    1. [root@liabio ~]# redis-cli --cluster add-node 192.168.155.73:6379 192.168.155.117:6379 --cluster-slave --cluster-master-id 1b3b59ff2b7ecf0ae67568104501450b94aa9ac0 -a test123

    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

    3. >>> Adding node 192.168.155.73:6379 to cluster 192.168.155.117:6379

    4. >>> Performing Cluster Check (using node 192.168.155.117:6379)

    5. M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379

    6. slots:[0-5460] (5461 slots) master

    7. 1 additional replica(s)

    8. S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379

    9. slots: (0 slots) slave

    10. replicates c4ab027656d55b800cc54063493bca198a5e1385

    11. M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379

    12. slots:[5461-10922] (5462 slots) master

    13. 1 additional replica(s)

    14. S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379

    15. slots: (0 slots) slave

    16. replicates f070ddf68e39896af42dc08251199cda7c8b9b92

    17. M: 1b3b59ff2b7ecf0ae67568104501450b94aa9ac0 192.168.155.111:6379

    18. slots: (0 slots) master

    19. M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379

    20. slots:[10923-16383] (5461 slots) master

    21. 1 additional replica(s)

    22. S: 0a6188b6bf590c928a2f7b1b0de9aeb206977d72 192.168.155.78:6379

    23. slots: (0 slots) slave

    24. replicates 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650

    25. S: 9dc374d48b730432f726147828cde001ea5a7dc4 192.168.155.114:6379

    26. slots: (0 slots) slave

    27. replicates 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2

    28. M: 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2 192.168.155.108:6379

    29. slots: (0 slots) master

    30. 1 additional replica(s)

    31. [OK] All nodes agree about slots configuration.

    32. >>> Check for open slots...

    33. >>> Check slots coverage...

    34. [OK] All 16384 slots covered.

    35. >>> Send CLUSTER MEET to node 192.168.155.73:6379 to make it join the cluster.

    36. Waiting for the cluster to join

    37. >>> Configure node as replica of 192.168.155.111:6379.

    38. [OK] New node added correctly.

    迁移卡槽

    进行使用rebalance子命令进行卡槽分配:

      1. [root@liabio ~]# redis-cli --cluster rebalance --cluster-use-empty-masters --cluster-pipeline 100 192.168.155.117:6379 -a test123

      2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

      3. >>> Performing Cluster Check (using node 192.168.155.117:6379)

      4. [OK] All nodes agree about slots configuration.

      5. >>> Check for open slots...

      6. >>> Check slots coverage...

      7. [OK] All 16384 slots covered.

      8. >>> Rebalancing across 5 nodes. Total weight = 5.00

      9. Moving 2186 slots from 192.168.155.91:6379 to 192.168.155.111:6379

      10. ####################################################################

      11. Moving 1092 slots from 192.168.155.112:6379 to 192.168.155.111:6379

      12. ###################################################################

      13. Moving 1093 slots from 192.168.155.112:6379 to 192.168.155.108:6379

      14. #################################################################

    • Moving 2185 slots from 192.168.155.117:6379 to 192.168.155.108:6379

    • ################################################################

    • [root@liabio ~]#

    结语

    从以上可以看出, redis-cli5.0.7版本的客户端,可以操作 带密码4.0.7版本的redis集群,卡槽迁移不会报以下语法错误 ERR syntax error

  • 相关阅读:
    CentOS7下搭建hadoop2.7.3完全分布式
    在linux命令行利用SecureCRT上传下载文件
    SPDY和HTTP
    哈希表的工作原理
    LVS(Linux Virtual Server)
    Discuz x3 UCenter实现同步登陆原理
    Goroutine(协程)为何能处理大并发?
    缓存与DB数据一致性问题解决的几个思路
    固态硬盘SSD与闪存(Flash Memory)
    堆和栈的区别(转过无数次的文章)
  • 原文地址:https://www.cnblogs.com/cheyunhua/p/15879440.html
Copyright © 2020-2023  润新知