redis集羣的創建,redis集羣卡槽遷移報錯ERR syntax error詳細說明與驗證

前言

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] Calling MIGRATE: ERR Target instance replied with error: NOAUTH Authentication required
在這裏插入圖片描述
這個是因爲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操作,一般用於同時加入多個從節點時,#保證多個從節點可共享RDB
repl-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/v1
kind: StatefulSet
metadata:
  name: redis-test
  namespace: default
spec:
  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  -owide
NAME                       READY   STATUS    RESTARTS   AGE     IP                NODE     NOMINATED NODE   READINESS GATES
redis-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 -v
redis-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 test123
Warning: 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 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
M: f070ddf68e39896af42dc08251199cda7c8b9b92 192.168.155.117:6379
   slots:[0-5460] (5461 slots) master
M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379
   slots:[5461-10922] (5462 slots) master
M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379
   slots:[10923-16383] (5461 slots) master
Can 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 cluster
Waiting 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) master
M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379
   slots:[5461-10922] (5462 slots) master
M: 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 test123
Warning: 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) master
M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379
   slots:[5461-10922] (5462 slots) master
M: 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 test123
Warning: 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 f070ddf68e39896af42dc08251199cda7c8b9b92
M: c4ab027656d55b800cc54063493bca198a5e1385 192.168.155.91:6379
   slots:[5461-10922] (5462 slots) master
M: 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 test123
Warning: 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 f070ddf68e39896af42dc08251199cda7c8b9b92
M: 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650 192.168.155.112:6379
   slots:[10923-16383] (5461 slots) master
S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379
   slots: (0 slots) slave
   replicates c4ab027656d55b800cc54063493bca198a5e1385
M: 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 test123
Warning: 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:6379
OK
192.168.155.117:6379> LPUSH list1 aa
-> Redirected to slot [7141] located at 192.168.155.91:6379
(integer) 1
192.168.155.91:6379> zadd zset1 1 aa
-> Redirected to slot [4341] located at 192.168.155.117:6379
(integer) 1
192.168.155.117:6379> set a b
-> Redirected to slot [15495] located at 192.168.155.112:6379
OK
192.168.155.112:6379> SADD set1 redis
-> Redirected to slot [3037] located at 192.168.155.117:6379
(integer) 1
192.168.155.117:6379> 
[root@liabio ~]# 
[root@liabio ~]# redis-cli -a test123 --cluster  check 192.168.155.117:6379
Warning: 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 f070ddf68e39896af42dc08251199cda7c8b9b92
M: 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 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650
S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379
   slots: (0 slots) slave
   replicates c4ab027656d55b800cc54063493bca198a5e1385
M: 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 test123
Warning: 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 f070ddf68e39896af42dc08251199cda7c8b9b92
M: 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 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650
S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379
   slots: (0 slots) slave
   replicates c4ab027656d55b800cc54063493bca198a5e1385
M: 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 test123
Warning: 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 f070ddf68e39896af42dc08251199cda7c8b9b92
M: 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 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650
S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379
   slots: (0 slots) slave
   replicates c4ab027656d55b800cc54063493bca198a5e1385
M: 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2 192.168.155.108:6379
   slots: (0 slots) master
M: 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:6379
Warning: 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) master
S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379
   slots: (0 slots) slave
   replicates f070ddf68e39896af42dc08251199cda7c8b9b92
M: 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 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650
S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379
   slots: (0 slots) slave
   replicates c4ab027656d55b800cc54063493bca198a5e1385
M: 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2 192.168.155.108:6379
   slots: (0 slots) master
M: 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 test123
Warning: 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) master
S: 1121a45980f1d5964f0010b331aeb514ff9dedb8 192.168.155.103:6379
   slots: (0 slots) slave
   replicates f070ddf68e39896af42dc08251199cda7c8b9b92
M: 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 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650
S: 941108cab0121fc840f909da080d92770dbbdee1 192.168.155.102:6379
   slots: (0 slots) slave
   replicates c4ab027656d55b800cc54063493bca198a5e1385
M: 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2 192.168.155.108:6379
   slots: (0 slots) master
M: 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 test123
Warning: 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 c4ab027656d55b800cc54063493bca198a5e1385
M: 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 f070ddf68e39896af42dc08251199cda7c8b9b92
M: 1b3b59ff2b7ecf0ae67568104501450b94aa9ac0 192.168.155.111:6379
   slots: (0 slots) master
M: 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 8d1e71502b9f1c29b3170eb9bf1391ae5aa50650
S: 9dc374d48b730432f726147828cde001ea5a7dc4 192.168.155.114:6379
   slots: (0 slots) slave
   replicates 78ad24899c7a7b1c0cad99e2c1afab82e8c98ec2
M: 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
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章