日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

關(guān)于docker?compose安裝redis集群的問題(集群擴(kuò)容、集群收縮)_docker

作者:Xiao--Y ? 更新時間: 2022-05-28 編程語言

一、redis 配置信息模板

文件名:redis-cluster.tmpl

# redis端口
port ${PORT}
#redis 訪問密碼
requirepass 123456
#redis 訪問Master節(jié)點密碼
masterauth 123456
# 關(guān)閉保護(hù)模式
protected-mode no
# 開啟集群
cluster-enabled yes
# 集群節(jié)點配置
cluster-config-file nodes.conf
# 超時
cluster-node-timeout 5000
# 集群節(jié)點IP host模式為宿主機(jī)IP
# cluster-announce-ip 192.168.1.10
# 集群節(jié)點端口 7001 - 7006
cluster-announce-port ${PORT}
cluster-announce-bus-port 1${PORT}
# 開啟 appendonly 備份模式
appendonly yes
# 每秒鐘備份
appendfsync everysec
# 對aof文件進(jìn)行壓縮時,是否執(zhí)行同步操作
no-appendfsync-on-rewrite no
# 當(dāng)目前aof文件大小超過上一次重寫時的aof文件大小的100%時會再次進(jìn)行重寫
auto-aof-rewrite-percentage 100
# 重寫前AOF文件的大小最小值 默認(rèn) 64mb
auto-aof-rewrite-min-size 64mb

# 日志配置
# debug:會打印生成大量信息,適用于開發(fā)/測試階段
# verbose:包含很多不太有用的信息,但是不像debug級別那么混亂
# notice:適度冗長,適用于生產(chǎn)環(huán)境
# warning:僅記錄非常重要、關(guān)鍵的警告消息
loglevel notice
# 日志文件路徑
logfile "/data/redis.log"

二、編寫批量生成配置文件腳本

文件名:redis-cluster-config.sh

for port in `seq 7001 7006`; do \
  mkdir -p ./${port}/conf \
  && PORT=${port} envsubst < ./redis-cluster.tmpl > ./${port}/conf/redis.conf \
  && mkdir -p ./${port}/data; \
done

三、批量生成配置文件

執(zhí)行 redis-cluster-config.sh 生成配置文件

在這里插入圖片描述

四、編寫 docker-compose 文件

文件名:docker-compose.yml

version: '3'
services:
  redis-7001:
    image: redis:6
    container_name: redis-7001
    command:
      ["redis-server", "/usr/local/etc/redis/redis.conf"]
    volumes:
      - ./7001/conf/redis.conf:/usr/local/etc/redis/redis.conf
      - ./7001/data:/data
    ports:
      - "7001:7001"
      - "17001:17001"
    environment:
      # 設(shè)置時區(qū)為上海,否則時間會有問題
      - TZ=Asia/Shanghai
    logging:
      options:
        max-size: '100m'
        max-file: '10'
  redis-7002:
    container_name: redis-7002
      - ./7002/conf/redis.conf:/usr/local/etc/redis/redis.conf
      - ./7002/data:/data
      - "7002:7002"
      - "17002:17002"
  redis-7003:
    container_name: redis-7003
      - ./7003/conf/redis.conf:/usr/local/etc/redis/redis.conf
      - ./7003/data:/data
      - "7003:7003"
      - "17003:17003"
  redis-7004:
    container_name: redis-7004
      - ./7004/conf/redis.conf:/usr/local/etc/redis/redis.conf
      - ./7004/data:/data
      - "7004:7004"
      - "17004:17004"
  redis-7005:
    container_name: redis-7005
      - ./7005/conf/redis.conf:/usr/local/etc/redis/redis.conf
      - ./7005/data:/data
      - "7005:7005"
      - "17005:17005"
  redis-7006:
    container_name: redis-7006
      - ./7006/conf/redis.conf:/usr/local/etc/redis/redis.conf
      - ./7006/data:/data
      - "7006:7006"
      - "17006:17006"

五、做集群、分配插槽

注:192.168.44.65 為 宿主機(jī)ip

ip port
192.168.44.65 7001
192.168.44.65 7002
192.168.44.65 7003
192.168.44.65 7004
192.168.44.65 7005
192.168.44.65 7006

執(zhí)行命令:
注: cluster-replicas 表示 一個主節(jié)點有幾個從節(jié)點

C:\Users\billow>docker exec -it redis-7001 redis-cli -p 7001 -a 123456 --cluster create 192.168.44.65:7001 192.168.44.65:7002 192.168.44.65:7003 192.168.44.65:7004 192.168.44.65:7005 192.168.44.65:7006 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.44.65:7005 to 192.168.44.65:7001
Adding replica 192.168.44.65:7006 to 192.168.44.65:7002
Adding replica 192.168.44.65:7004 to 192.168.44.65:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 741c7bb537888ff97866896abb22da27c22f8eaf 192.168.44.65:7001
   slots:[0-5460] (5461 slots) master
M: e5f687462a0c47f51c3abf4b8d77d646a3d63fa9 192.168.44.65:7002
   slots:[5461-10922] (5462 slots) master
M: 9936d3690d971eccfc8b8ed43c5defc66f318454 192.168.44.65:7003
   slots:[10923-16383] (5461 slots) master
S: b7b6fa6a4766c32c5d42d759548d6fcdf2b9159b 192.168.44.65:7004
   replicates e5f687462a0c47f51c3abf4b8d77d646a3d63fa9
S: 2275c996f25a8815342e2435af073eb29565778b 192.168.44.65:7005
   replicates 9936d3690d971eccfc8b8ed43c5defc66f318454
S: f69a5d0ae974816396a9d9e613c13f6ceea25de2 192.168.44.65:7006
   replicates 741c7bb537888ff97866896abb22da27c22f8eaf
Can 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 cluster
Waiting for the cluster to join
.
>>> Performing Cluster Check (using node 192.168.44.65:7001)
M: 741c7bb537888ff97866896abb22da27c22f8eaf 192.168.44.65:7001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: f69a5d0ae974816396a9d9e613c13f6ceea25de2 172.25.0.11:7006
   slots: (0 slots) slave
   replicates 741c7bb537888ff97866896abb22da27c22f8eaf
M: 9936d3690d971eccfc8b8ed43c5defc66f318454 172.25.0.7:7003
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: e5f687462a0c47f51c3abf4b8d77d646a3d63fa9 172.25.0.8:7002
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 2275c996f25a8815342e2435af073eb29565778b 172.25.0.10:7005
   slots: (0 slots) slave
   replicates 9936d3690d971eccfc8b8ed43c5defc66f318454
S: b7b6fa6a4766c32c5d42d759548d6fcdf2b9159b 172.25.0.9:7004
   slots: (0 slots) slave
   replicates e5f687462a0c47f51c3abf4b8d77d646a3d63fa9
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

六、測試:

命令:

-- 集群、分配插槽
docker exec -it redis-7001 redis-cli -p 7001 -a 123456 --cluster create 192.168.44.65:7001 192.168.44.65:7002 192.168.44.65:7003 192.168.44.65:7004 192.168.44.65:7005 192.168.44.65:7006 --cluster-replicas 1
-- 測試
docker exec -it redis-7001 redis-cli -h 192.168.44.65 -p 7003 -a 123456 -c
-- 查看集群狀態(tài)
cluster nodes
-- 查看分片信息
cluster slots
-- 查看集群信息
cluster info

執(zhí)行結(jié)果:

C:\Users\billow>docker exec -it redis-7001 redis-cli -h 192.168.44.65 -p 7003 -a 123456 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.44.65:7003>
192.168.44.65:7003>
192.168.44.65:7003>
192.168.44.65:7003>
192.168.44.65:7003> set name admin
-> Redirected to slot [5798] located at 172.25.0.8:7002
OK
172.25.0.8:7002> get name
"admin"
172.25.0.8:7002> cluster nodes
2275c996f25a8815342e2435af073eb29565778b 172.25.0.10:7005@17005 slave 9936d3690d971eccfc8b8ed43c5defc66f318454 0 1648086940436 3 connected
f69a5d0ae974816396a9d9e613c13f6ceea25de2 172.25.0.11:7006@17006 slave 741c7bb537888ff97866896abb22da27c22f8eaf 0 1648086939000 1 connected
b7b6fa6a4766c32c5d42d759548d6fcdf2b9159b 172.25.0.9:7004@17004 slave e5f687462a0c47f51c3abf4b8d77d646a3d63fa9 0 1648086939710 2 connected
741c7bb537888ff97866896abb22da27c22f8eaf 172.25.0.6:7001@17001 master - 0 1648086939392 1 connected 0-5460
e5f687462a0c47f51c3abf4b8d77d646a3d63fa9 172.25.0.8:7002@17002 myself,master - 0 1648086939000 2 connected 5461-10922
9936d3690d971eccfc8b8ed43c5defc66f318454 172.25.0.7:7003@17003 master - 0 1648086938868 3 connected 10923-16383
172.25.0.8:7002>
172.25.0.8:7002>
172.25.0.8:7002>
172.25.0.8:7002>
172.25.0.8:7002>
172.25.0.8:7002> cluster slots
1) 1) (integer) 0
? ?2) (integer) 5460
? ?3) 1) "172.25.0.6"
? ? ? 2) (integer) 7001
? ? ? 3) "741c7bb537888ff97866896abb22da27c22f8eaf"
? ?4) 1) "172.25.0.11"
? ? ? 2) (integer) 7006
? ? ? 3) "f69a5d0ae974816396a9d9e613c13f6ceea25de2"
2) 1) (integer) 5461
? ?2) (integer) 10922
? ?3) 1) "172.25.0.8"
? ? ? 2) (integer) 7002
? ? ? 3) "e5f687462a0c47f51c3abf4b8d77d646a3d63fa9"
? ?4) 1) "172.25.0.9"
? ? ? 2) (integer) 7004
? ? ? 3) "b7b6fa6a4766c32c5d42d759548d6fcdf2b9159b"
3) 1) (integer) 10923
? ?2) (integer) 16383
? ?3) 1) "172.25.0.7"
? ? ? 2) (integer) 7003
? ? ? 3) "9936d3690d971eccfc8b8ed43c5defc66f318454"
? ?4) 1) "172.25.0.10"
? ? ? 2) (integer) 7005
? ? ? 3) "2275c996f25a8815342e2435af073eb29565778b"
172.25.0.8:7002> 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:6
cluster_my_epoch:2
cluster_stats_messages_ping_sent:906
cluster_stats_messages_pong_sent:911
cluster_stats_messages_meet_sent:1
cluster_stats_messages_sent:1818
cluster_stats_messages_ping_received:911
cluster_stats_messages_pong_received:906
cluster_stats_messages_received:1817

七、手動擴(kuò)容

添加兩個新的節(jié)點用于手動擴(kuò)容
文件名:add-redis-docker.yml

version: '3'

services:
  redis-7007:
    image: redis:6
    container_name: redis-7007
    command:
      ["redis-server", "/usr/local/etc/redis/redis.conf"]
    volumes:
      - ./7007/conf/redis.conf:/usr/local/etc/redis/redis.conf
      - ./7007/data:/data
    ports:
      - "7007:7007"
      - "17007:17007"
    environment:
      # 設(shè)置時區(qū)為上海,否則時間會有問題
      - TZ=Asia/Shanghai
    logging:
      options:
        max-size: '100m'
        max-file: '10'
  redis-7008:
    container_name: redis-7008
      - ./7008/conf/redis.conf:/usr/local/etc/redis/redis.conf
      - ./7008/data:/data
      - "7008:7008"
      - "17008:17008"
networks:
    default:
        external:
            name: learn_shop

執(zhí)行命令:
docker-compose -f add-redis-docker.yml up

八、添加主從節(jié)點

1、添加主節(jié)點

-- 進(jìn)入任意節(jié)點
docker exet -it redis-7001 bash

-- 添加主節(jié)點(192.168.44.65:7001 -a 123456  這個可以是任何已存在的節(jié)點,主要用于獲取集群信息)
redis-cli --cluster add-node 192.168.44.65:7007 192.168.44.65:7001 -a 123456

結(jié)果:

root@aa1e004c00ff:/data# redis-cli --cluster add-node 192.168.44.65:7007 192.168.44.65:7001 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 192.168.44.65:7007 to cluster 192.168.44.65:7001
>>> Performing Cluster Check (using node 192.168.44.65:7001)
M: 741c7bb537888ff97866896abb22da27c22f8eaf 192.168.44.65:7001
? ?slots:[0-5460] (5461 slots) master
? ?1 additional replica(s)
S: 2275c996f25a8815342e2435af073eb29565778b 172.25.0.6:7005
? ?slots: (0 slots) slave
? ?replicates 9936d3690d971eccfc8b8ed43c5defc66f318454
M: 9936d3690d971eccfc8b8ed43c5defc66f318454 172.25.0.8:7003
? ?slots:[10923-16383] (5461 slots) master
? ?1 additional replica(s)
S: f69a5d0ae974816396a9d9e613c13f6ceea25de2 172.25.0.11:7006
? ?slots: (0 slots) slave
? ?replicates 741c7bb537888ff97866896abb22da27c22f8eaf
S: b7b6fa6a4766c32c5d42d759548d6fcdf2b9159b 172.25.0.9:7004
? ?slots: (0 slots) slave
? ?replicates e5f687462a0c47f51c3abf4b8d77d646a3d63fa9
M: e5f687462a0c47f51c3abf4b8d77d646a3d63fa9 172.25.0.7:7002
? ?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.44.65:7007 to make it join the cluster.
[OK] New node added correctly.

查看剛加的主節(jié)點:

127.0.0.1:7001> cluster nodes
741c7bb537888ff97866896abb22da27c22f8eaf 172.25.0.10:7001@17001 myself,master - 0 1648104789000 1 connected 0-5460
2275c996f25a8815342e2435af073eb29565778b 172.25.0.6:7005@17005 slave 9936d3690d971eccfc8b8ed43c5defc66f318454 0 1648104789523 3 connected
6f0c7d0ae166717d645e84b48b72b9706c7c758a 172.25.0.13:7007@17007 master - 0 1648104790133 0 connected
9936d3690d971eccfc8b8ed43c5defc66f318454 172.25.0.8:7003@17003 master - 0 1648104790546 3 connected 10923-16383
f69a5d0ae974816396a9d9e613c13f6ceea25de2 172.25.0.11:7006@17006 slave 741c7bb537888ff97866896abb22da27c22f8eaf 0 1648104790000 1 connected
b7b6fa6a4766c32c5d42d759548d6fcdf2b9159b 172.25.0.9:7004@17004 slave e5f687462a0c47f51c3abf4b8d77d646a3d63fa9 0 1648104790000 2 connected
e5f687462a0c47f51c3abf4b8d77d646a3d63fa9 172.25.0.7:7002@17002 master - 0 1648104791062 2 connected 5461-10922

2、添加從節(jié)點

-- 進(jìn)入任意節(jié)點
docker exet -it redis-7001 bash

-- 添加從節(jié)點(192.168.44.65:7001 -a 123456  這個可以是任何已存在的節(jié)點,主要用于獲取集群信息)(6f0c7d0ae166717d645e84b48b72b9706c7c758a  為剛加的主節(jié)點 id)
redis-cli --cluster add-node --cluster-slave --cluster-master-id 6f0c7d0ae166717d645e84b48b72b9706c7c758a 192.168.44.65:7008 192.168.44.65:7001 -a 123456

結(jié)果:

127.0.0.1:7001> cluster nodes
741c7bb537888ff97866896abb22da27c22f8eaf 172.25.0.10:7001@17001 myself,master - 0 1648105151000 1 connected 0-5460
2275c996f25a8815342e2435af073eb29565778b 172.25.0.6:7005@17005 slave 9936d3690d971eccfc8b8ed43c5defc66f318454 0 1648105154016 3 connected
6f0c7d0ae166717d645e84b48b72b9706c7c758a 172.25.0.13:7007@17007 master - 0 1648105152000 0 connected
9936d3690d971eccfc8b8ed43c5defc66f318454 172.25.0.8:7003@17003 master - 0 1648105153000 3 connected 10923-16383
f69a5d0ae974816396a9d9e613c13f6ceea25de2 172.25.0.11:7006@17006 slave 741c7bb537888ff97866896abb22da27c22f8eaf 0 1648105152000 1 connected
6478c692a149130d56538aea69b54d2abc1c98b4 172.25.0.12:7008@17008 slave 6f0c7d0ae166717d645e84b48b72b9706c7c758a 0 1648105152000 0 connected
b7b6fa6a4766c32c5d42d759548d6fcdf2b9159b 172.25.0.9:7004@17004 slave e5f687462a0c47f51c3abf4b8d77d646a3d63fa9 0 1648105153599 2 connected
e5f687462a0c47f51c3abf4b8d77d646a3d63fa9 172.25.0.7:7002@17002 master - 0 1648105153000 2 connected 5461-10922

九、分配插槽

剛加入的主從節(jié)點還不能使用,因為還沒有分配插槽
rebalance平衡集群節(jié)點slot數(shù)量
語法:

rebalance host:port
--weight <arg>
--auto-weights
--threshold <arg>
--use-empty-masters
--timeout <arg>
--simulate
--pipeline <arg>

host:port:這個是必傳參數(shù),用來從一個節(jié)點獲取整個集群信息,相當(dāng)于獲取集群信息的入口。
--weight <arg>:節(jié)點的權(quán)重,格式為node_id=weight,如果需要為多個節(jié)點分配權(quán)重的話,需要添加多個--weight <arg>參數(shù),即--weight b31e3a2e=5 --weight 60b8e3a1=5,node_id可為節(jié)點名稱的前綴,只要保證前綴位數(shù)能唯一區(qū)分該節(jié)點即可。沒有傳遞–weight的節(jié)點的權(quán)重默認(rèn)為1。
--auto-weights:這個參數(shù)在rebalance流程中并未用到。
--threshold <arg>:只有節(jié)點需要遷移的slot閾值超過threshold,才會執(zhí)行rebalance操作。具體計算方法可以參考下面的rebalance命令流程的第四步。
--use-empty-masters:rebalance是否考慮沒有節(jié)點的master,默認(rèn)沒有分配slot節(jié)點的master是不參與rebalance的,設(shè)置--use-empty-masters可以讓沒有分配slot的節(jié)點參與rebalance。
--timeout <arg>:設(shè)置migrate命令的超時時間。
--simulate:設(shè)置該參數(shù),可以模擬rebalance操作,提示用戶會遷移哪些slots,而不會真正執(zhí)行遷移操作。
--pipeline <arg>:與reshar的pipeline參數(shù)一樣,定義cluster getkeysinslot命令一次取出的key數(shù)量,不傳的話使用默認(rèn)值為10。
-- 分配插槽(192.168.44.65:7001 -a 123456  這個可以是任何已存在的節(jié)點,主要用于獲取集群信息)
redis-cli --cluster rebalance --cluster-threshold 1 --cluster-use-empty-masters 192.168.44.65:7001 -a 123456

如果需要模擬執(zhí)行添加 : --cluster-simulate

結(jié)果:

root@aa1e004c00ff:/data# redis-cli --cluster rebalance --cluster-threshold 1 --cluster-use-empty-masters 192.168.44.65:7001 -a 123456
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.44.65:7001)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Rebalancing across 4 nodes. Total weight = 4.00
Moving 1366 slots from 172.25.0.7:7002 to 172.25.0.13:7007
#########################################################################################
Moving 1365 slots from 172.25.0.8:7003 to 172.25.0.13:7007
#########################################################################################
Moving 1365 slots from 192.168.44.65:7001 to 172.25.0.13:7007
#########################################################################################

查看節(jié)點信息:

127.0.0.1:7001> cluster nodes
741c7bb537888ff97866896abb22da27c22f8eaf 172.25.0.10:7001@17001 myself,master - 0 1648105892000 1 connected 1365-5460
2275c996f25a8815342e2435af073eb29565778b 172.25.0.6:7005@17005 slave 9936d3690d971eccfc8b8ed43c5defc66f318454 0 1648105893536 3 connected
6f0c7d0ae166717d645e84b48b72b9706c7c758a 172.25.0.13:7007@17007 master - 0 1648105894566 8 connected 0-1364 5461-6826 10923-12287
9936d3690d971eccfc8b8ed43c5defc66f318454 172.25.0.8:7003@17003 master - 0 1648105893000 3 connected 12288-16383
f69a5d0ae974816396a9d9e613c13f6ceea25de2 172.25.0.11:7006@17006 slave 741c7bb537888ff97866896abb22da27c22f8eaf 0 1648105893000 1 connected
6478c692a149130d56538aea69b54d2abc1c98b4 172.25.0.12:7008@17008 slave 6f0c7d0ae166717d645e84b48b72b9706c7c758a 0 1648105894576 8 connected
b7b6fa6a4766c32c5d42d759548d6fcdf2b9159b 172.25.0.9:7004@17004 slave e5f687462a0c47f51c3abf4b8d77d646a3d63fa9 0 1648105893000 2 connected
e5f687462a0c47f51c3abf4b8d77d646a3d63fa9 172.25.0.7:7002@17002 master - 0 1648105894566 2 connected 6827-10922

十、集群測試

root@aa1e004c00ff:/data# redis-cli -p 7001 -a 123456 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:7001> set 1 1
-> Redirected to slot [9842] located at 172.25.0.7:7002
OK
172.25.0.7:7002> set 2 2
-> Redirected to slot [5649] located at 172.25.0.13:7007
OK
172.25.0.13:7007> set 3 3
-> Redirected to slot [1584] located at 172.25.0.10:7001
OK
172.25.0.10:7001> set 4 4
-> Redirected to slot [14039] located at 172.25.0.8:7003
OK
172.25.0.8:7003> set 5 5
-> Redirected to slot [9974] located at 172.25.0.7:7002
OK
172.25.0.7:7002> set 6 6
-> Redirected to slot [5781] located at 172.25.0.13:7007
OK
172.25.0.13:7007> set 7 7
-> Redirected to slot [1716] located at 172.25.0.10:7001
OK
172.25.0.10:7001>
172.25.0.10:7001>
172.25.0.10:7001>
172.25.0.10:7001>
172.25.0.10:7001> get 1
-> Redirected to slot [9842] located at 172.25.0.7:7002
"1"
172.25.0.7:7002> get 2
-> Redirected to slot [5649] located at 172.25.0.13:7007
"2"
172.25.0.13:7007> get 3
-> Redirected to slot [1584] located at 172.25.0.10:7001
"3"
172.25.0.10:7001> get 4
-> Redirected to slot [14039] located at 172.25.0.8:7003
"4"
172.25.0.8:7003> get 5
-> Redirected to slot [9974] located at 172.25.0.7:7002
"5"
172.25.0.7:7002> get 6
-> Redirected to slot [5781] located at 172.25.0.13:7007
"6"
172.25.0.13:7007> get 7
-> Redirected to slot [1716] located at 172.25.0.10:7001
"7"

十一、常用命令

集群
cluster info :打印集群的信息

cluster nodes :列出集群當(dāng)前已知的所有節(jié)點( node),以及這些節(jié)點的相關(guān)信息。
節(jié)點
cluster meet <ip> <port> :將 ip 和 port 所指定的節(jié)點添加到集群當(dāng)中,讓它成為集群的一份子。
cluster forget <node_id> :從集群中移除 node_id 指定的節(jié)點。
cluster replicate <node_id> :將當(dāng)前節(jié)點設(shè)置為 node_id 指定的節(jié)點的從節(jié)點。
cluster saveconfig :將節(jié)點的配置文件保存到硬盤里面。
槽(slot)
cluster addslots <slot> [slot ...] :將一個或多個槽( slot)指派( assign)給當(dāng)前節(jié)點。
cluster delslots <slot> [slot ...] :移除一個或多個槽對當(dāng)前節(jié)點的指派。
cluster flushslots :移除指派給當(dāng)前節(jié)點的所有槽,讓當(dāng)前節(jié)點變成一個沒有指派任何槽的節(jié)點。
cluster setslot <slot> node <node_id> :將槽 slot 指派給 node_id 指定的節(jié)點,如果槽已經(jīng)指派給另一個節(jié)點,那么先讓另一個節(jié)點刪除該槽>,然后再進(jìn)行指派。
cluster setslot <slot> migrating <node_id> :將本節(jié)點的槽 slot 遷移到 node_id 指定的節(jié)點中。
cluster setslot <slot> importing <node_id> :從 node_id 指定的節(jié)點中導(dǎo)入槽 slot 到本節(jié)點。
cluster setslot <slot> stable :取消對槽 slot 的導(dǎo)入( import)或者遷移( migrate)。
鍵
cluster keyslot <key> :計算鍵 key 應(yīng)該被放置在哪個槽上。
cluster countkeysinslot <slot> :返回槽 slot 目前包含的鍵值對數(shù)量。
cluster getkeysinslot <slot> <count> :返回 count 個 slot 槽中的鍵

原文鏈接:https://blog.csdn.net/lyong1223/article/details/123703651

欄目分類
最近更新