容器:redis_6380 – IP:172.17.0.3 – 啟動成功
容器:redis_6381 – IP:172.17.0.4 – 啟動成功
容器:redis_6382 – IP:172.17.0.5 – 啟動成功
容器:redis_6383 – IP:172.17.0.6 – 啟動成功
容器:redis_6384 – IP:172.17.0.7 – 啟動成功

執行 docker ps 確實是否啟動成功

root@DESKTOP-Q13EI52:~/docker-config/redis# docker ps
CONTAINER ID    IMAGE        COMMAND         CREATED       STATUS       PORTS          NAMES
c0601df1a456    redis        "docker-entrypoint.s…"  27 seconds ago   Up 26 seconds    0.0.0.0:6384->6379/tcp  redis_6384
6fecf70465b8    redis        "docker-entrypoint.s…"  27 seconds ago   Up 26 seconds    0.0.0.0:6383->6379/tcp  redis_6383
1af15e90b7a0    redis        "docker-entrypoint.s…"  28 seconds ago   Up 27 seconds    0.0.0.0:6382->6379/tcp  redis_6382
6c495f31a5df    redis        "docker-entrypoint.s…"  28 seconds ago   Up 28 seconds    0.0.0.0:6381->6379/tcp  redis_6381
e54fd9fd0550    redis        "docker-entrypoint.s…"  29 seconds ago   Up 28 seconds    0.0.0.0:6380->6379/tcp  redis_6380
be92ad2f7046    redis        "docker-entrypoint.s…"  29 seconds ago   Up 29 seconds    0.0.0.0:6379->6379/tcp  redis_6379

到此為止,6個獨立集群節點創建完畢,目前還無法正常工作。

創建集群

此處可以跳過,本人是為了省事

獲取容器為redis_開始所有的容器IP地址

docker inspect -f "{{.NetworkSettings.IPAddress}}:6379" `docker ps | grep redis_ | awk -F' ' '{print $1}'` | sort |xargs | sed 's/ /, /g'

# 返回結果
# 172.17.0.2:6379, 172.17.0.3:6379, 172.17.0.4:6379, 172.17.0.5:6379, 172.17.0.6:6379, 172.17.0.7:6379

初次創建集群執行

./redis-cli --cluster create 172.17.0.2:6379, 172.17.0.3:6379, 172.17.0.4:6379, 172.17.0.5:6379, 172.17.0.6:6379, 172.17.0.7:6379 --cluster-replicas 1

輸出結果

licas 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 172.17.0.6:6379 to 172.17.0.2:6379
Adding replica 172.17.0.7:6379 to 172.17.0.3:6379
Adding replica 172.17.0.5:6379 to 172.17.0.4:6379
M: e8da1fef656984de3ec2a677edc8d9c48d01cd95 172.17.0.2:6379
  slots:[0-5460] (5461 slots) master
M: 68b925ab0fbbc1a632c1754587fb6dad3fa14c91 172.17.0.3:6379
  slots:[5461-10922] (5462 slots) master
M: 0a46ab2f6d176738b55fe699c2df1c34f8200d06 172.17.0.4:6379
  slots:[10923-16383] (5461 slots) master
S: bd3064ad5297dfc258e9236943455c589be8b2a3 172.17.0.5:6379
  replicates 0a46ab2f6d176738b55fe699c2df1c34f8200d06
S: f1d8c897882d29e6538b1158525493b3b782289a 172.17.0.6:6379
  replicates e8da1fef656984de3ec2a677edc8d9c48d01cd95
S: 619e1cb52f39e07b321719b77fc3631fa6293cef 172.17.0.7:6379
  replicates 68b925ab0fbbc1a632c1754587fb6dad3fa14c91
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 172.17.0.2:6379)
M: e8da1fef656984de3ec2a677edc8d9c48d01cd95 172.17.0.2:6379
  slots:[0-5460] (5461 slots) master
  1 additional replica(s)
S: f1d8c897882d29e6538b1158525493b3b782289a 172.17.0.6:6379
  slots: (0 slots) slave
  replicates e8da1fef656984de3ec2a677edc8d9c48d01cd95
S: bd3064ad5297dfc258e9236943455c589be8b2a3 172.17.0.5:6379
  slots: (0 slots) slave
  replicates 0a46ab2f6d176738b55fe699c2df1c34f8200d06
M: 0a46ab2f6d176738b55fe699c2df1c34f8200d06 172.17.0.4:6379
  slots:[10923-16383] (5461 slots) master
  1 additional replica(s)
S: 619e1cb52f39e07b321719b77fc3631fa6293cef 172.17.0.7:6379
  slots: (0 slots) slave
  replicates 68b925ab0fbbc1a632c1754587fb6dad3fa14c91
M: 68b925ab0fbbc1a632c1754587fb6dad3fa14c91 172.17.0.3: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.

連接集群

通過客戶端連接

redis-cli -c <端口>

執行命令:cluster info

127.0.0.1:6379> 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:1
cluster_stats_messages_ping_sent:104
cluster_stats_messages_pong_sent:120
cluster_stats_messages_sent:224
cluster_stats_messages_ping_received:115
cluster_stats_messages_pong_received:104
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:224

看到:cluster_state:ok 說明集群已可以正常工作

客戶端控制臺:cluster help

127.0.0.1:6379> cluster help
 1) CLUSTER <subcommand> arg arg ... arg. Subcommands are:
 2) ADDSLOTS <slot> [slot ...] -- Assign slots to current node.
 3) BUMPEPOCH -- Advance the cluster config epoch.
 4) COUNT-failure-reports <node-id> -- Return number of failure reports for <node-id>.
 5) COUNTKEYSINSLOT <slot> - Return the number of keys in <slot>.
 6) DELSLOTS <slot> [slot ...] -- Delete slots information from current node.
 7) FAILOVER [force|takeover] -- Promote current replica node to being a master.
 8) FORGET <node-id> -- Remove a node from the cluster.
 9) GETKEYSINSLOT <slot> <count> -- Return key names stored by current node in a slot.
10) FLUSHSLOTS -- Delete current node own slots information.
11) INFO - Return information about the cluster.
12) KEYSLOT <key> -- Return the hash slot for <key>.
13) MEET <ip> <port> [bus-port] -- Connect nodes into a working cluster.
14) MYID -- Return the node id.
15) NODES -- Return cluster configuration seen by node. Output format:
16)   <id> <ip:port> <flags> <master> <pings> <pongs> <epoch> <link> <slot> ... <slot>
17) REPLICATE <node-id> -- Configure current node as replica to <node-id>.
18) RESET [hard|soft] -- Reset current node (default: soft).
19) SET-config-epoch <epoch> - Set config epoch of current node.
20) SETSLOT <slot> (importing|migrating|stable|node <node-id>) -- Set slot state.
21) REPLICAS <node-id> -- Return <node-id> replicas.
22) SAVECONFIG - Force saving cluster configuration on disk.
23) SLOTS -- Return information about slots range mappings. Each range is made of:
24)   start, end, master and replicas IP addresses, ports and ids

查看客戶端提供的集群相關命令:redis-cli --cluster help

Cluster Manager Commands:
 create     host1:port1 ... hostN:portN
         --cluster-replicas <arg>
 check     host:port
         --cluster-search-multiple-owners
 info      host:port
 fix      host:port
         --cluster-search-multiple-owners
 reshard    host:port
         --cluster-from <arg>
         --cluster-to <arg>
         --cluster-slots <arg>
         --cluster-yes
         --cluster-timeout <arg>
         --cluster-pipeline <arg>
         --cluster-replace
 rebalance   host:port
         --cluster-weight <node1=w1...nodeN=wN>
         --cluster-use-empty-masters
         --cluster-timeout <arg>
         --cluster-simulate
         --cluster-pipeline <arg>
         --cluster-threshold <arg>
         --cluster-replace
 add-node    new_host:new_port existing_host:existing_port
         --cluster-slave
         --cluster-master-id <arg>
 del-node    host:port node_id
 call      host:port command arg arg .. arg
 set-timeout  host:port milliseconds
 import     host:port
         --cluster-from <arg>
         --cluster-copy
         --cluster-replace

看完這篇關于Docker怎么快速搭建Redis集群的文章,如果覺得文章內容寫得不錯的話,可以把它分享出去給更多人看到。

更多關于云服務器域名注冊,虛擬主機的問題,請訪問三五互聯官網:m.shinetop.cn

贊(0)
聲明:本網站發布的內容(圖片、視頻和文字)以原創、轉載和分享網絡內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。郵箱:3140448839@qq.com。本站原創內容未經允許不得轉載,或轉載時需注明出處:三五互聯知識庫 » Docker怎么快速搭建Redis集群

登錄

找回密碼

注冊

主站蜘蛛池模板: 国产一区二区精品久久凹凸| 国产成人 综合 亚洲欧洲| 丰满少妇高潮在线播放不卡| 无码视频伊人| 精品亚洲国产成人性色av| 国产成人精品无码一区二区| 日本一区二区精品色超碰| 99久久国产宗和精品1上映| 色综合久久一区二区三区| 日韩精品亚洲专在线电影| 国产精品日韩深夜福利久久| 久久综合亚洲色一区二区三区| 国产综合视频精品一区二区| 久久精品国产亚洲av麻豆软件| 国产精品有码在线观看| 日韩国产欧美精品在线| 8av国产精品爽爽ⅴa在线观看| 国产成人剧情AV麻豆果冻| 成人免费毛片aaaaaa片| 少妇激情一区二区三区视频| 国偷自产一区二区三区在线视频 | 麻豆精品一区二区视频在线| 中文字幕国产精品二区| 熟女人妻aⅴ一区二区三区电影| 久久精品国产热久久精品国产亚洲| 亚洲人午夜精品射精日韩| 亚洲色大成网站www久久九九 | 国产对白老熟女正在播放 | 伊人成伊人成综合网222| 国产午夜福利不卡在线观看| 精品无人乱码一区二区三区的优势 | 草草浮力地址线路①屁屁影院| 一区二区三区日本久久九| 中文字幕亚洲精品人妻| 欧美大胆老熟妇乱子伦视频| 欧美激情一区二区久久久| 99久热在线精品视频| 天堂网亚洲综合在线| 昌都县| 精品国产大片中文字幕| 2021亚洲国产精品无码|