偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

如何使用Docker搭建Redis Cluster集群?

數(shù)據(jù)庫(kù) Redis
本文主要講了如何在一臺(tái)Linux服務(wù)器上使用Docker搭建一個(gè)Cluster模式的Redis集群,這種方式搭建的集群主要用于測(cè)試用途,不建議在生產(chǎn)環(huán)境使用。

要搭建的集群情況說(shuō)明

在一臺(tái)Linux服務(wù)器上使用docker搭建一個(gè)cluster模式的redis集群。三個(gè)master節(jié)點(diǎn),三個(gè)slave節(jié)點(diǎn),六個(gè)節(jié)點(diǎn)因?yàn)樵谕慌_(tái)服務(wù)器上,所以每個(gè)節(jié)點(diǎn)使用不同的端口,端口范圍是6380到6385。

redis cluster集群具有如下幾個(gè)特點(diǎn):

  • 去中心化,采用多主多從模式。所有節(jié)點(diǎn)彼此互聯(lián)(PING-PONG機(jī)制),內(nèi)部使用二進(jìn)制協(xié)議傳輸。
  • 客戶(hù)端不需要連接集群所有節(jié)點(diǎn),連接集群中任何一個(gè)可用節(jié)點(diǎn)即可。
  • 每一個(gè)分區(qū)都是由一個(gè)主節(jié)點(diǎn)和多個(gè)從節(jié)點(diǎn)組成,分片和分片之間平行。
  • 每一個(gè)master節(jié)點(diǎn)負(fù)責(zé)維護(hù)一部分槽,以及槽所映射的鍵值數(shù)據(jù);集群中每個(gè)節(jié)點(diǎn)都有全量的槽信息,通過(guò)槽每個(gè)node都知道具體數(shù)據(jù)存儲(chǔ)到哪個(gè)node上。

拉取redis鏡像

可以選擇指定版本的redis,本文為了方便演示,使用最新版本

docker pull redis

創(chuàng)建使用固定的network

docker network create rediscluster

創(chuàng)建redis配置文件

因?yàn)榱鶄€(gè)節(jié)點(diǎn)監(jiān)聽(tīng)端口不同,所以配置文件也有區(qū)別,可以使用如下shell腳本生成對(duì)應(yīng)配置文件(假如命名為createRedisConf.sh):

#!/bin/sh

for port in $(seq 6380 6385);
do
mkdir -p ~/redisCluster/node-${port}/conf
touch ~/redisCluster/node-${port}/conf/redis.conf
cat << EOF > ~/redisCluster/node-${port}/conf/redis.conf
#節(jié)點(diǎn)端口
port ${port}
#添加訪問(wèn)認(rèn)證
requirepass luduoxin
#如果主節(jié)點(diǎn)開(kāi)啟了訪問(wèn)認(rèn)證,從節(jié)點(diǎn)訪問(wèn)主節(jié)點(diǎn)需要認(rèn)證
masterauth luduoxin
#保護(hù)模式,默認(rèn)值 yes,即開(kāi)啟。開(kāi)啟保護(hù)模式以后,需配置 bind ip 或者設(shè)置訪問(wèn)密碼;關(guān)閉保護(hù)模式,外部網(wǎng)絡(luò)可以直接訪問(wèn)
protected-mode no
#bind 0.0.0.0

#是否以守護(hù)線程的方式啟動(dòng)(后臺(tái)啟動(dòng)),默認(rèn) no
daemonize no
#是否開(kāi)啟 AOF 持久化模式,默認(rèn) no
appendonly yes
#是否開(kāi)啟集群模式,默認(rèn) no
cluster-enabled yes
#集群節(jié)點(diǎn)信息文件
cluster-config-file nodes.conf
#群節(jié)點(diǎn)連接超時(shí)時(shí)間
cluster-node-timeout 5000
#集群節(jié)點(diǎn) IP,我使用的服務(wù)的ip為172.16.3.110,替換為自己的服務(wù)器的即可
cluster-announce-ip 172.16.3.110
#集群節(jié)點(diǎn)映射端口
cluster-announce-port ${port}
#集群節(jié)點(diǎn)總線端口
cluster-announce-bus-port 1${port}
EOF
done

創(chuàng)建此文件后,先賦予執(zhí)行權(quán)限,然后執(zhí)行生成配置文件

$ chmod 755 ./createRedisConf.sh
$ sh ./createRedisConf.sh

創(chuàng)建出六個(gè)Redis節(jié)點(diǎn)

可以使用如下shell腳本快速創(chuàng)建出來(lái)(createRedis.sh)。

#!/bin/sh

## 首次創(chuàng)建并運(yùn)行redis容器
if [ "$1" = "create" ]; then
for port in $(seq 6380 6385);
do
docker run -di --restart always --name redis-${port} --net rediscluster -p ${port}:${port} -p 1${port}:1${port} -v ~/redisCluster/node-${port}/conf/redis.conf:/usr/local/etc/redis/redis.conf -v ~/redisCluster/node-${port}/data:/data redis redis-server /usr/local/etc/redis/redis.conf
done
fi

##停止redis容器
if [ "$1" = "stop" ]; then
for port in $(seq 6380 6385);
do
docker stop redis-${port}
done
fi

##啟動(dòng)已有的redis容器
if [ "$1" = "start" ]; then
for port in $(seq 6380 6385);
do
docker start redis-${port}
done
fi

## 刪除redis容器
if [ "$1" = "rm" ]; then
for port in $(seq 6380 6385);
do
docker rm redis-${port}
done
fi

創(chuàng)建此文件后,先賦予執(zhí)行權(quán)限,然后執(zhí)行創(chuàng)建出redis服務(wù)

$ chmod 755 ./createRedis.sh
$ sh ./createRedis.sh create

創(chuàng)建完成后,可以使用命令 docker ps -a 查看容器。

創(chuàng)建cluster集群

選擇一個(gè)redis容器,例如選擇redis-6380容器,進(jìn)入容器。

docker exec -it redis-6380 /bin/bash

在容器里面執(zhí)行如下命令。

redis-cli -a luduoxin --cluster create 172.16.3.110:6380 172.16.3.110:6381 172.16.3.110:6382 172.16.3.110:6383 172.16.3.110:6384 172.16.3.110:6385 --cluster-replicas 1

然后出現(xiàn)如下提示,輸入 yes 繼續(xù)。

Can I set the above configuration ? (type 'yes' to accept)

創(chuàng)建過(guò)程如下:

# redis-cli -a luduoxin --cluster create 172.16.3.110:6380 172.16.3.110:6381 172.16.3.110:6382 172.16.3.110:6383 172.16.3.110:6384 172.16.3.110:6385 --cluster-replicas 1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> 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.16.3.110:6384 to 172.16.3.110:6380
Adding replica 172.16.3.110:6385 to 172.16.3.110:6381
Adding replica 172.16.3.110:6383 to 172.16.3.110:6382
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 78891932599b7497c8dd921295ba19eb0f549285 172.16.3.110:6380
slots:[0-5460] (5461 slots) master
M: 43c735f5e5bd1dfd7e4fa80aed467dc6e10a9081 172.16.3.110:6381
slots:[5461-10922] (5462 slots) master
M: 254d130ac0f88ec36be9cda27e59500e04c283cc 172.16.3.110:6382
slots:[10923-16383] (5461 slots) master
S: e2875613c12f0754e485e5eb56d968dd78493bae 172.16.3.110:6383
replicates 78891932599b7497c8dd921295ba19eb0f549285
S: a87af69f190a86455864c5ca73fabb60290abd1e 172.16.3.110:6384
replicates 43c735f5e5bd1dfd7e4fa80aed467dc6e10a9081
S: 846fa01cecc7fa75fc558eb8fcfb2788abb2a83d 172.16.3.110:6385
replicates 254d130ac0f88ec36be9cda27e59500e04c283cc
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.16.3.110:6380)
M: 78891932599b7497c8dd921295ba19eb0f549285 172.16.3.110:6380
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: 254d130ac0f88ec36be9cda27e59500e04c283cc 172.16.3.110:6382
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
M: 43c735f5e5bd1dfd7e4fa80aed467dc6e10a9081 172.16.3.110:6381
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: a87af69f190a86455864c5ca73fabb60290abd1e 172.16.3.110:6384
slots: (0 slots) slave
replicates 43c735f5e5bd1dfd7e4fa80aed467dc6e10a9081
S: 846fa01cecc7fa75fc558eb8fcfb2788abb2a83d 172.16.3.110:6385
slots: (0 slots) slave
replicates 254d130ac0f88ec36be9cda27e59500e04c283cc
S: e2875613c12f0754e485e5eb56d968dd78493bae 172.16.3.110:6383
slots: (0 slots) slave
replicates 78891932599b7497c8dd921295ba19eb0f549285
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

到這里集群就創(chuàng)建成功了。

檢查集群狀態(tài)。

redis-cli -a luduoxin --cluster check 172.16.3.110:6382

連接集群某個(gè)節(jié)點(diǎn)。

$ redis-cli -c -a luduoxin -h 172.16.3.110 -p 6382
//查看集群信息
172.16.3.110:6381> cluster info
//查看集群結(jié)點(diǎn)信息
172.16.3.110:6381> cluster nodes
//查看集群的slot分配區(qū)間及對(duì)應(yīng)的主從節(jié)點(diǎn)映射關(guān)系
172.16.3.110:6381> cluster slots

小結(jié)

本文主要講了如何在一臺(tái)Linux服務(wù)器上使用docker搭建一個(gè)cluster模式的redis集群,這種方式搭建的集群主要用于測(cè)試用途,不建議在生產(chǎn)環(huán)境使用。

責(zé)任編輯:姜華 來(lái)源: 今日頭條
相關(guān)推薦

2024-03-07 16:03:56

RedisDocker

2021-04-06 06:04:36

Redis 6.X C集群搭建操作系統(tǒng)

2023-11-13 09:03:10

2017-07-11 13:30:12

RedisDockerLinux

2024-04-03 00:00:00

Redis集群代碼

2023-06-10 23:09:40

Redis場(chǎng)景內(nèi)存

2022-09-15 08:31:11

主從復(fù)制模式Docker

2016-01-07 09:36:20

Docker容器

2017-02-27 21:55:04

LinuxCentOS 7.0Redis

2021-05-12 09:13:48

MySQL數(shù)據(jù)庫(kù)Docker搭建

2021-01-07 10:18:03

Redis數(shù)據(jù)庫(kù)環(huán)境搭建

2021-06-03 18:42:26

Redis集群故障

2015-05-27 10:29:41

DockerHadoopHadoop集群

2019-12-13 10:50:49

集群Redis存儲(chǔ)

2015-08-03 16:15:53

Docker部署集群

2015-06-16 16:20:40

2022-01-26 00:06:08

Redis分布式客戶(hù)端

2022-01-27 20:15:31

集群存儲(chǔ)元數(shù)據(jù)

2025-01-06 13:00:00

RedisSentinel高可用模式

2020-04-21 22:59:50

Redis搭建選舉
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)