欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Docker快速搭建Redis集群的方法示例

 更新時(shí)間:2020年05月14日 09:19:42   作者:有我在心  
這篇文章主要介紹了Docker快速搭建Redis集群的方法示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

什么是Redis集群

Redis集群是Redis提供的分布式數(shù)據(jù)庫(kù)方案,集群通過(guò)分片(sharding)來(lái)進(jìn)行數(shù)據(jù)共享,并提供復(fù)制和故障轉(zhuǎn)移功能。

節(jié)點(diǎn)

一個(gè)Redis集群通常由多個(gè)節(jié)點(diǎn)(node)組成,在剛開(kāi)始的時(shí)候,每個(gè)節(jié)點(diǎn)都是相互獨(dú)立的,它們都處于一個(gè)只包含自己的集群當(dāng)中,要組建一個(gè)真正可工作的集群,我們必須將各個(gè)獨(dú)立的節(jié)點(diǎn)連接起來(lái),構(gòu)成一個(gè)包含多個(gè)節(jié)點(diǎn)的集群。

集群配置

配置文件

下載配置文件:https://raw.githubusercontent.com/antirez/redis/5.0/redis.conf

調(diào)整 CLUSTER 節(jié)點(diǎn)配置

# 開(kāi)啟cluster集群
cluster-enabled yes

# 集群配置文件
cluster-config-file nodes-6379.conf

# 集群節(jié)點(diǎn)超時(shí)
cluster-node-timeout 15000

Docker快速搭建Redis集群

安裝Redis

參考文章:http://www.dbjr.com.cn/article/150054.htm

準(zhǔn)備工作

├── conf
│  ├── redis.conf
│  └── sentinel.conf
├── redis
│  ├── data_6379
│  ├── data_6380
│  ├── data_6381
│  ├── data_6382
│  ├── data_6383
│  └── data_6384
└── scripts
  ├── cluster.sh
  ├── run.sh
  └── sentinel.sh

run.sh 腳本文件

#!/usr/bin/env bash
set -e

# 腳本當(dāng)前目錄
cPath=$(cd $(dirname "$0") || exit; pwd)

# 根目錄
dirPath=$(dirname "$cPath")

# 獲取端口
port="$1"
if [[ ! "$port" ]]; then
 port=6379
fi

# 創(chuàng)建數(shù)據(jù)目錄
mkdir -p "$dirPath"/redis/data_"$port"

# 刪除已啟動(dòng)服務(wù)
containerId=$(docker ps -a | grep "redis_$port" | awk -F' ' '{print $1}')
if [[ "$containerId" ]]; then
  docker rm -f ${containerId} > /dev/null
fi

# 啟動(dòng)服務(wù)
containerName=redis_"$port"
docker run -itd --privileged=true -p "$port":6379 --name ${containerName} \
-v="$dirPath"/conf/redis.conf:/etc/redis/redis.conf \
-v="$dirPath"/redis/data_"$port":/data \
redis \
redis-server /etc/redis/redis.conf > /dev/null

# 獲取容器IP地址
dockerIp=$(docker inspect -f "{{.NetworkSettings.IPAddress}}" "$containerName")

# 獲取容器啟動(dòng)狀態(tài)
isRunning=$(docker inspect -f "{{.State.Running}}" "$containerName")
if [[ "$isRunning" == "true" ]]; then
  echo "容器:$containerName - IP:$dockerIp - 啟動(dòng)成功"
fi

cluster.sh 腳本文件

#!/usr/bin/env bash
set -e

# 腳本當(dāng)前目錄
cPath=$(cd $(dirname "$0") || exit; pwd)

# 啟動(dòng)集群數(shù)量
num="$1"
if [[ ! "$num" ]]; then
 num=6
fi

sPort=6378
for((i=1;i<=$num;i++)); do
  sh ${cPath}/run.sh $(($sPort+$i))
done

啟動(dòng)服務(wù)

執(zhí)行腳本文件,默認(rèn)創(chuàng)建6個(gè)節(jié)點(diǎn)

sh scripts/cluster.sh

腳本返回結(jié)果

容器:redis_6379 - IP:172.17.0.2 - 啟動(dòng)成功
容器:redis_6380 - IP:172.17.0.3 - 啟動(dòng)成功
容器:redis_6381 - IP:172.17.0.4 - 啟動(dòng)成功
容器:redis_6382 - IP:172.17.0.5 - 啟動(dòng)成功
容器:redis_6383 - IP:172.17.0.6 - 啟動(dòng)成功
容器:redis_6384 - IP:172.17.0.7 - 啟動(dòng)成功

執(zhí)行 docker ps 確實(shí)是否啟動(dòng)成功

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個(gè)獨(dú)立集群節(jié)點(diǎn)創(chuàng)建完畢,目前還無(wú)法正常工作。

創(chuàng)建集群

此處可以跳過(guò),本人是為了省事

獲取容器為redis_開(kāi)始所有的容器IP地址

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

# 返回結(jié)果
# 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

初次創(chuàng)建集群執(zhí)行

./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

輸出結(jié)果

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.

連接集群

通過(guò)客戶(hù)端連接

redis-cli -c <端口>

執(zhí)行命令: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 說(shuō)明集群已可以正常工作

客戶(hù)端控制臺(tái):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

查看客戶(hù)端提供的集群相關(guān)命令: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

到此這篇關(guān)于Docker快速搭建Redis集群的方法示例的文章就介紹到這了,更多相關(guān)Docker搭建Redis集群內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

  • Docker上部署Nginx的方法步驟

    Docker上部署Nginx的方法步驟

    本文主要介紹了Docker上部署Nginx的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • 如何解決Docker鏡像缺少字體的問(wèn)題

    如何解決Docker鏡像缺少字體的問(wèn)題

    在使用Spire.Office.Free將Excel轉(zhuǎn)換為HTML時(shí),遇到字體缺失錯(cuò)誤,通過(guò)在Dockerfile中添加字體文件,成功解決了問(wèn)題,建議在遇到類(lèi)似問(wèn)題時(shí),可以嘗試在Dockerfile中添加缺失的字體文件
    2025-02-02
  • 如何使用Docker快速搭建服務(wù)器環(huán)境

    如何使用Docker快速搭建服務(wù)器環(huán)境

    這篇文章主要介紹了使用Docker快速搭建服務(wù)器環(huán)境的詳細(xì)步驟,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-10-10
  • 解決docker掛載的目錄無(wú)法讀寫(xiě)問(wèn)題

    解決docker掛載的目錄無(wú)法讀寫(xiě)問(wèn)題

    這篇文章主要介紹了解決docker掛載的目錄無(wú)法讀寫(xiě)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-03-03
  • CentOS 7安裝Docker服務(wù)詳細(xì)過(guò)程

    CentOS 7安裝Docker服務(wù)詳細(xì)過(guò)程

    這篇文章主要為大家介紹了CentOS 7安裝Docker服務(wù)詳細(xì)過(guò)程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • 解決'nacos默認(rèn)secret.key配置不當(dāng)權(quán)限繞過(guò)漏洞'的問(wèn)題

    解決'nacos默認(rèn)secret.key配置不當(dāng)權(quán)限繞過(guò)漏洞'的問(wèn)題

    這篇文章主要介紹了解決“nacos默認(rèn)secret.key配置不當(dāng)權(quán)限繞過(guò)漏洞“的問(wèn)題,解決這個(gè)問(wèn)題需要對(duì)這個(gè)key的默認(rèn)值進(jìn)行修改,建議不要使用明文,可以用base64,key的長(zhǎng)度要32位以上,下面介紹一下在兩種環(huán)境下的修改方法,感興趣的朋友一起看看吧
    2024-01-01
  • docker部署fastapi的實(shí)現(xiàn)步驟

    docker部署fastapi的實(shí)現(xiàn)步驟

    本文主要介紹了docker部署fastapi的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • Docker網(wǎng)絡(luò)配置(橋接網(wǎng)絡(luò)和自定義網(wǎng)絡(luò))自定義網(wǎng)絡(luò)設(shè)置ip方式

    Docker網(wǎng)絡(luò)配置(橋接網(wǎng)絡(luò)和自定義網(wǎng)絡(luò))自定義網(wǎng)絡(luò)設(shè)置ip方式

    這篇文章主要介紹了Docker網(wǎng)絡(luò)配置(橋接網(wǎng)絡(luò)和自定義網(wǎng)絡(luò))自定義網(wǎng)絡(luò)設(shè)置ip方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • Docker搭建私有鏡像倉(cāng)庫(kù)的方法

    Docker搭建私有鏡像倉(cāng)庫(kù)的方法

    這篇文章主要介紹了Docker搭建私有鏡像倉(cāng)庫(kù)的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-11-11
  • 借助Docker搭建JMeter+Grafana+Influxdb監(jiān)控平臺(tái)的詳細(xì)教程

    借助Docker搭建JMeter+Grafana+Influxdb監(jiān)控平臺(tái)的詳細(xì)教程

    這篇文章主要介紹了借助Docker搭建JMeter+Grafana+Influxdb監(jiān)控平臺(tái),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-01-01

最新評(píng)論