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

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

閱讀本文約花費: 17 (分鐘)

前言

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版本才支持。

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操作时,加密码参数。于是乎,我试着自己在迁移卡槽的地方传入密码参数,像下面这样:

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文件:

#设置为守护进程
daemonize no
#Redis运行的进程pid文件
pidfile redis-6397.pid
#Redis服务端口号
port 6379
#Redis服务绑定ip
#bind 192.168.100.144
bind {PODIP}
#最大内存
maxmemory 2g
#开启集群模式
cluster-enabled yes   
#节点配置文件
cluster-config-file nodes-6397.conf
#集群节点超时时间(单位:毫秒)
cluster-node-timeout 15000
#集群是否需要所有的slot都分配给在线节点,才能正常访问
cluster-require-full-coverage no
#工作目录(aof、rdb、日志文件)
dir /data
#tcp-backlog
tcp-backlog 511
#客户端闲置多少秒后关闭连接(单位:秒)
timeout 300
#检测TCP连接活性的周期(单位:秒)
tcp-keepalive 60
#redis密码
requirepass test123
masterauth test123
#日志级别
loglevel notice
#日志记录目录
logfile "redis-6397.log"
#可用的数据库数
databases 16
#RDB保存条件
save 900 1
save 300 10
save 60 10000
#bgsave执行错误,是否停止Redis接受请求
stop-writes-on-bgsave-error no
#RDB文件是否压缩
rdbcompression yes
#RDB文件是否使用校验和
rdbchecksum yes
#RDB文件名
dbfilename dump-6397.rdb
#当从节点与主节点连接中断时,如果此参数值设置为“yes”,从节点可以继续处理客户端的
#请求。否则除info和slaveof命令之外,拒绝的所有请求并统一回复"SYNC with master in #progress"
slave-serve-stale-data yes
#从节点是否开启只读模式,集群架构下从节点默认读写都不可用,需要调用readyonly命令
#开启只读模式
slave-read-only yes
#是否开启无盘复制
repl-diskless-sync no
#开启无盘复制后,需要延迟多少秒后进行创建RDB操作,一般用于同时加入多个从节点时,
#保证多个从节点可共享
RDBrepl-diskless-sync-delay 5
#是否开启主从复制socket的NO_DELAY选项:yes:Redis会合并小的TCP包来节省带宽,但
##是这样增加同步延迟,造成主
#从数据不一致;no:主节点会立即发送同步数据,没有延迟
repl-disable-tcp-nodelay no
#从节点的优先级
slave-priority 100
#是否开启AOF持久化模式
appendonly no
#Lua脚本“超时时间”(单位:毫秒)
lua-time-limit 5000
#慢查询被记录的阀值(单位微秒)
slowlog-log-slower-than 10000
#最多记录慢查询的条数
slowlog-max-len 1000
#Redis服务内存延迟监控
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
#是否激活重置哈希
activerehashing yes
#客户端输出缓冲区限制
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 512mb 128mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
#复制积压缓存区大小
repl-backlog-size 256mb
#redis server执行后台任务的频率,默认为10
hz 10
#最大客户端连接数
maxclients 15000

使用以下命令创建 configmaps

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

创建redis实例

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

apiVersion: apps/v1kind: StatefulSetmetadata:  name: redis-test  namespace: defaultspec:  podManagementPolicy: OrderedReady  replicas: 10  revisionHistoryLimit: 10  selector:    matchLabels:      name: redis-test  serviceName: redis-test  template:    metadata:      labels:        name: redis-test    spec:      containers:      - command:        - sh        - -c        - cp /config/redis.conf /data/; sed -i "s?{PODIP}?${PODIP}?g" /data/redis.conf ;redis-server /data/redis.conf        image: redis:4.0.7        env:        - name: PODIP          valueFrom:            fieldRef:              apiVersion: v1              fieldPath: status.podIP        imagePullPolicy: IfNotPresent        name: redis        ports:        - containerPort: 6379          name: redis          protocol: TCP        resources: {}        terminationMessagePath: /dev/termination-log        terminationMessagePolicy: File        volumeMounts:        - mountPath: /config          name: redis-config        - mountPath: /tmp          name: tmp-dir       dnsPolicy: ClusterFirst      restartPolicy: Always      schedulerName: default-scheduler      securityContext: {}      terminationGracePeriodSeconds: 30      volumes:      - configMap:          defaultMode: 420          name: redis-test-conf        name: redis-config      - emptyDir: {}        name: tmp-dir  updateStrategy:    rollingUpdate:      partition: 0    type: RollingUpdate

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

[root@liabio ~]# kubectl apply -f redis-sts.yaml[root@liabio ~]# kubectl get pod  -owideNAME                       READY   STATUS    RESTARTS   AGE     IP                NODE     NOMINATED NODE   READINESS GATESredis-test-0               1/1     Running   0          60s     192.168.155.117   liabio   <none>           <none>redis-test-1               1/1     Running   0          59s     192.168.155.91    liabio   <none>           <none>redis-test-2               1/1     Running   0          58s     192.168.155.112   liabio   <none>           <none>redis-test-3               1/1     Running   0          55s     192.168.155.103   liabio   <none>           <none>redis-test-4               1/1     Running   0          54s     192.168.155.102    liabio   <none>           <none>redis-test-5               1/1     Running   0          52s     192.168.155.78    liabio   <none>           <none>redis-test-6               1/1     Running   0          51s     192.168.155.108   liabio   <none>           <none>redis-test-7               1/1     Running   0          49s     192.168.155.111   liabio   <none>           <none>redis-test-8               1/1     Running   0          47s     192.168.155.114   liabio   <none>           <none>redis-test-9               1/1     Running   0          45s     192.168.155.73    liabio   <none>           <none>

使用redis-cli 5.0.7操作集群

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

[root@liabio ~]# redis-cli -vredis-cli 5.0.7

创建3master集群

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

[root@liabio ~]# echo yes | redis-cli --cluster create  192.168.155.117:6379 192.168.155.91:6379 192.168.155.112:6379 -a test123Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.>>> Performing hash slots allocation on 3 nodes...Master[0] -> Slots 0 - 5460Master[1] -> Slots 5461 - 10922Master[2] -> Slots 10923 - 16383M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379   slots:[0-5460] (5461 slots) masterM: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379   slots:[5461-10922] (5462 slots) masterM: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379   slots:[10923-16383] (5461 slots) masterCan I set the above configuration? (type 'yes' to accept): >>> 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 192.168.155.117:6379)M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379   slots:[0-5460] (5461 slots) masterM: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379   slots:[5461-10922] (5462 slots) masterM: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379   slots:[10923-16383] (5461 slots) master[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.

添加slave1

[root@liabio ~]# redis-cli --cluster add-node 192.168.155.103:6379 192.168.155.117:6379 --cluster-slave --cluster-master-id f070ddf68e39896af42dc08251199cda7c8b9b92 -a test123Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.>>> Adding node 192.168.155.103:6379 to cluster 192.168.155.117:6379>>> Performing Cluster Check (using node 192.168.155.117:6379)M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379   slots:[0-5460] (5461 slots) masterM: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379   slots:[5461-10922] (5462 slots) masterM: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379   slots:[10923-16383] (5461 slots) master[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.>>> Send CLUSTER MEET to node 192.168.155.103:6379 to make it join the cluster.Waiting for the cluster to join
>>> Configure node as replica of 192.168.155.117:6379.[OK] New node added correctly.

添加slave2

[root@liabio ~]# redis-cli --cluster add-node 192.168.155.102:6379 192.168.155.117:6379 --cluster-slave --cluster-master-id c4ab027656d55b800cc54063493bca198a5e1385 -a test123Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.>>> Adding node 192.168.155.102:6379 to cluster 192.168.155.117:6379>>> Performing Cluster Check (using node 192.168.155.117:6379)M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379   slots:[0-5460] (5461 slots) master   1 additional replica(s)S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379   slots: (0 slots) slave   replicates f070ddf68e39896af42dc08251199cda7c8b9b92M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379   slots:[5461-10922] (5462 slots) masterM: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379   slots:[10923-16383] (5461 slots) master[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.>>> Send CLUSTER MEET to node 192.168.155.102:6379 to make it join the cluster.Waiting for the cluster to join
>>> Configure node as replica of 192.168.155.91:6379.[OK] New node added correctly.

添加slave3

[root@liabio ~]# redis-cli --cluster add-node 192.168.155.78:6379 192.168.155.117:6379 --cluster-slave --cluster-master-id 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 -a test123Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.>>> Adding node 192.168.155.78:6379 to cluster 192.168.155.117:6379>>> Performing Cluster Check (using node 192.168.155.117:6379)M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379   slots:[0-5460] (5461 slots) master   1 additional replica(s)S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379   slots: (0 slots) slave   replicates f070ddf68e39896af42dc08251199cda7c8b9b92M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379   slots:[10923-16383] (5461 slots) masterS: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379   slots: (0 slots) slave   replicates c4ab027656d55b800cc54063493bca198a5e1385M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379   slots:[5461-10922] (5462 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.>>> Send CLUSTER MEET to node 192.168.155.78:6379 to make it join the cluster.Waiting for the cluster to join
>>> Configure node as replica of 192.168.155.112:6379.[OK] New node added correctly.[root@liabio ~]#

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

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

[root@liabio ~]# redis-cli -c -h 192.168.155.112 -p 6379 -a test123Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.192.168.155.112:6379> 192.168.155.112:6379> HMSET hash1 name1 "redis sasa"-> Redirected to slot [4414] located at 192.168.155.117:6379OK192.168.155.117:6379> LPUSH list1 aa-> Redirected to slot [7141] located at 192.168.155.91:6379(integer) 1192.168.155.91:6379> zadd zset1 1 aa-> Redirected to slot [4341] located at 192.168.155.117:6379(integer) 1192.168.155.117:6379> set a b-> Redirected to slot [15495] located at 192.168.155.112:6379OK192.168.155.112:6379> SADD set1 redis-> Redirected to slot [3037] located at 192.168.155.117:6379(integer) 1192.168.155.117:6379> [root@liabio ~]# [root@liabio ~]# redis-cli -a test123 --cluster  check 192.168.155.117:6379Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.192.168.155.117:6379 (f070ddf6...) -> 3 keys | 5461 slots | 1 slaves.192.168.155.112:6379 (8d1e7150...) -> 1 keys | 5461 slots | 1 slaves.192.168.155.91:6379 (c4ab0276...) -> 1 keys | 5462 slots | 1 slaves.[OK] 5 keys in 3 masters.0.00 keys per slot on average.>>> Performing Cluster Check (using node 192.168.155.117:6379)M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379   slots:[0-5460] (5461 slots) master   1 additional replica(s)S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379   slots: (0 slots) slave   replicates f070ddf68e39896af42dc08251199cda7c8b9b92M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379   slots:[10923-16383] (5461 slots) master   1 additional replica(s)S: 0a6188b6bf590c928a2f7b1b0de9aeb206977d72 192.168.155.78:6379   slots: (0 slots) slave   replicates 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379   slots: (0 slots) slave   replicates c4ab027656d55b800cc54063493bca198a5e1385M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379   slots:[5461-10922] (5462 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.

扩容为五主五从集群

添加新的master1

[root@liabio ~]# redis-cli --cluster add-node 192.168.155.108:6379 192.168.155.117:6379 -a test123Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.>>> Adding node 192.168.155.108:6379 to cluster 192.168.155.117:6379>>> Performing Cluster Check (using node 192.168.155.117:6379)M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379   slots:[0-5460] (5461 slots) master   1 additional replica(s)S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379   slots: (0 slots) slave   replicates f070ddf68e39896af42dc08251199cda7c8b9b92M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379   slots:[10923-16383] (5461 slots) master   1 additional replica(s)S: 0a6188b6bf590c928a2f7b1b0de9aeb206977d72 192.168.155.78:6379   slots: (0 slots) slave   replicates 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379   slots: (0 slots) slave   replicates c4ab027656d55b800cc54063493bca198a5e1385M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379   slots:[5461-10922] (5462 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.>>> Send CLUSTER MEET to node 192.168.155.108:6379 to make it join the cluster.[OK] New node added correctly.

添加新的master2

[root@liabio ~]# redis-cli --cluster add-node 192.168.155.111:6379 192.168.155.117:6379 -a test123Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.>>> Adding node 192.168.155.111:6379 to cluster 192.168.155.117:6379>>> Performing Cluster Check (using node 192.168.155.117:6379)M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379   slots:[0-5460] (5461 slots) master   1 additional replica(s)S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379   slots: (0 slots) slave   replicates f070ddf68e39896af42dc08251199cda7c8b9b92M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379   slots:[10923-16383] (5461 slots) master   1 additional replica(s)S: 0a6188b6bf590c928a2f7b1b0de9aeb206977d72 192.168.155.78:6379   slots: (0 slots) slave   replicates 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379   slots: (0 slots) slave   replicates c4ab027656d55b800cc54063493bca198a5e1385M: 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2 192.168.155.108:6379   slots: (0 slots) masterM: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379   slots:[5461-10922] (5462 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.>>> Send CLUSTER MEET to node 192.168.155.111:6379 to make it join the cluster.[OK] New node added correctly.[root@liabio ~]# redis-cli -a test123 --cluster  check 192.168.155.117:6379Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.192.168.155.117:6379 (f070ddf6...) -> 3 keys | 5461 slots | 1 slaves.192.168.155.111:6379 (1b3b59ff...) -> 0 keys | 0 slots | 0 slaves.192.168.155.112:6379 (8d1e7150...) -> 1 keys | 5461 slots | 1 slaves.192.168.155.108:6379 (78ad2489...) -> 0 keys | 0 slots | 0 slaves.192.168.155.91:6379 (c4ab0276...) -> 1 keys | 5462 slots | 1 slaves.[OK] 5 keys in 5 masters.0.00 keys per slot on average.>>> Performing Cluster Check (using node 192.168.155.117:6379)M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379   slots:[0-5460] (5461 slots) master   1 additional replica(s)M: 1b3b59ff2b7ecf0ae67568104501450b94aa9ac0 192.168.155.111:6379   slots: (0 slots) masterS: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379   slots: (0 slots) slave   replicates f070ddf68e39896af42dc08251199cda7c8b9b92M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379   slots:[10923-16383] (5461 slots) master   1 additional replica(s)S: 0a6188b6bf590c928a2f7b1b0de9aeb206977d72 192.168.155.78:6379   slots: (0 slots) slave   replicates 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379   slots: (0 slots) slave   replicates c4ab027656d55b800cc54063493bca198a5e1385M: 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2 192.168.155.108:6379   slots: (0 slots) masterM: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379   slots:[5461-10922] (5462 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.

添加新的slave1

[root@liabio ~]# redis-cli --cluster add-node 192.168.155.114:6379 192.168.155.117:6379 --cluster-slave --cluster-master-id 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2 -a test123Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.>>> Adding node 192.168.155.114:6379 to cluster 192.168.155.117:6379>>> Performing Cluster Check (using node 192.168.155.117:6379)M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379   slots:[0-5460] (5461 slots) master   1 additional replica(s)M: 1b3b59ff2b7ecf0ae67568104501450b94aa9ac0 192.168.155.111:6379   slots: (0 slots) masterS: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379   slots: (0 slots) slave   replicates f070ddf68e39896af42dc08251199cda7c8b9b92M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379   slots:[10923-16383] (5461 slots) master   1 additional replica(s)S: 0a6188b6bf590c928a2f7b1b0de9aeb206977d72 192.168.155.78:6379   slots: (0 slots) slave   replicates 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379   slots: (0 slots) slave   replicates c4ab027656d55b800cc54063493bca198a5e1385M: 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2 192.168.155.108:6379   slots: (0 slots) masterM: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379   slots:[5461-10922] (5462 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.>>> Send CLUSTER MEET to node 192.168.155.114:6379 to make it join the cluster.Waiting for the cluster to join
>>> Configure node as replica of 192.168.155.108:6379.[OK] New node added correctly.

添加新的slave2

[root@liabio ~]# redis-cli --cluster add-node 192.168.155.73:6379 192.168.155.117:6379 --cluster-slave --cluster-master-id 1b3b59ff2b7ecf0ae67568104501450b94aa9ac0 -a test123Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.>>> Adding node 192.168.155.73:6379 to cluster 192.168.155.117:6379>>> Performing Cluster Check (using node 192.168.155.117:6379)M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379   slots:[0-5460] (5461 slots) master   1 additional replica(s)S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379   slots: (0 slots) slave   replicates c4ab027656d55b800cc54063493bca198a5e1385M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379   slots:[5461-10922] (5462 slots) master   1 additional replica(s)S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379   slots: (0 slots) slave   replicates f070ddf68e39896af42dc08251199cda7c8b9b92M: 1b3b59ff2b7ecf0ae67568104501450b94aa9ac0 192.168.155.111:6379   slots: (0 slots) masterM: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379   slots:[10923-16383] (5461 slots) master   1 additional replica(s)S: 0a6188b6bf590c928a2f7b1b0de9aeb206977d72 192.168.155.78:6379   slots: (0 slots) slave   replicates 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650S: 9dc374d48b730432f726147828cde001ea5a7dc4 192.168.155.114:6379   slots: (0 slots) slave   replicates 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2M: 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2 192.168.155.108:6379   slots: (0 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.>>> Send CLUSTER MEET to node 192.168.155.73:6379 to make it join the cluster.Waiting for the cluster to join
>>> Configure node as replica of 192.168.155.111:6379.[OK] New node added correctly.

迁移卡槽

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

[root@liabio ~]# redis-cli --cluster rebalance --cluster-use-empty-masters --cluster-pipeline 100 192.168.155.117:6379 -a test123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 192.168.155.117:6379)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Rebalancing across 5 nodes. Total weight = 5.00
Moving 2186 slots from 192.168.155.91:6379 to 192.168.155.111:6379
####################################################################
Moving 1092 slots from 192.168.155.112:6379 to 192.168.155.111:6379
###################################################################
Moving 1093 slots from 192.168.155.112:6379 to 192.168.155.108:6379
#################################################################
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

via : https://mp.weixin.qq.com/s/YKe323wv_eXw_wwgYx0-GA

– END –

Rate this post

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注