docker搭建redis一主二从哨兵模式集群

4 篇文章 0 订阅
3 篇文章 0 订阅

1、IP规划

master 192.168.0.11:6379

slave1 192.168.0.12:6379

slave2 192.168.0.13:6379

sentinel1 192.168.0.14:26379

sentinel2 192.168.0.15:26379

sentinel3 192.168.0.16:26379

2、目录规划

KumasMBA:~ kumas$ ls -l /Users/kumas/Applications/Docker/redis/cluster4sentinels/

total 0

drwxr-xr-x 2 kumas staff 68 8 9 15:28 redis01

drwxr-xr-x 2 kumas staff 68 8 9 15:29 redis02

drwxr-xr-x 2 kumas staff 68 8 9 15:29 redis03

drwxr-xr-x 2 kumas staff 68 8 9 15:28 sentinel01

drwxr-xr-x 2 kumas staff 68 8 9 15:28 sentinel02

drwxr-xr-x 2 kumas staff 68 8 9 15:28 sentinel03

3、启动master

3.1 启动一个master(注意:测试使用,没有expose对外的端口,需要则另加-p 指定)

docker run -d  --name redis01 --network devnet --ip 192.168.0.11  -v /Users/kumas/Applications/Docker/redis/cluster4sentinels/redis01:/data redis:3.2-alpine  --appendonly yes --port 6379

3.2 启动两个slave

docker run -d  --name redis02 --network devnet --ip 192.168.0.12   -v /Users/kumas/Applications/Docker/redis/cluster4sentinels/redis02:/data redis:3.2-alpine  --appendonly yes --port 6379  --slave-read-only yes --slaveof 192.168.0.11 6379

docker run -d --name redis03 --network devnet --ip 192.168.0.13  -v /Users/kumas/Applications/Docker/redis/cluster4sentinels/redis03:/data redis:3.2-alpine  --appendonly yes --port 6379  --slave-read-only yes --slaveof 192.168.0.11 6379

4、启动sentinel

docker run -d --network devnet --ip 192.168.0.14 --name sentinel01 -v /Users/kumas/Applications/Docker/redis/cluster4sentinels/sentinel01:/data redis:3.2-alpine /data/sentinel.conf --sentinel

docker run -d --network devnet --ip 192.168.0.15 --name sentinel02 -v /Users/kumas/Applications/Docker/redis/cluster4sentinels/sentinel02:/data redis:3.2-alpine /data/sentinel.conf --sentinel

docker run -d --network devnet --ip 192.168.0.16 --name sentinel03 -v /Users/kumas/Applications/Docker/redis/cluster4sentinels/sentinel03:/data redis:3.2-alpine /data/sentinel.conf --sentinel
KumasMBA:~ kumas$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
f0af17a64201        redis:3.2-alpine    "docker-entrypoint..."   3 seconds ago       Up 2 seconds        6379/tcp                 sentinel03
41fa659c1e48        redis:3.2-alpine    "docker-entrypoint..."   11 seconds ago      Up 10 seconds       6379/tcp                 sentinel02
7ce382ea3912        redis:3.2-alpine    "docker-entrypoint..."   3 minutes ago       Up 2 minutes        6379/tcp                 sentinel01
f20793fa6676        redis:3.2-alpine    "docker-entrypoint..."   8 minutes ago       Up 8 minutes        6379/tcp                 redis03
550954a24cbb        redis:3.2-alpine    "docker-entrypoint..."   9 minutes ago       Up 9 minutes        6379/tcp                 redis02
01d1493ef2bf        redis:3.2-alpine    "docker-entrypoint..."   11 minutes ago      Up 11 minutes       0.0.0.0:6379->6379/tcp   redis01

ok,可以测试了。

 

5、附:sentinel.conf样例

port 26379
dir "/data"
logfile "/data/sentinel-01.log"
#bind 192.168.0.14
sentinel myid 203fb658bc42b4d3f5b77968b4f048e4d1df9889
sentinel monitor mymaster 192.168.0.11 6379 2
sentinel failover-timeout mymaster 60000
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
# Generated by CONFIG REWRITE
sentinel known-slave mymaster 192.168.0.12 6379
sentinel known-slave mymaster 192.168.0.13 6379
sentinel known-sentinel mymaster 192.168.0.16 26379 677facf0a38105a12cfeb8118a32195c92629a88
sentinel known-sentinel mymaster 192.168.0.15 26379 862a852ba0052b74297cc09f9c73b9b6bab129cc
sentinel current-epoch 0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值