【redis学习笔记】主从的docker-compose脚本

编排 redis 主从节点

version: '3.7'
services:
 master:
 image: 'redis:5.0.9'
 container_name: redis-master
 restart: always
 command: redis-server --appendonly yes
 ports:
 - 6379:6379
 slave1:
 image: 'redis:5.0.9'
 container_name: redis-slave1
 restart: always
 command: redis-server --appendonly yes --slaveof redis-master 6379
 ports:
 - 6380:6379
 slave2:
 image: 'redis:5.0.9'
 container_name: redis-slave2
 restart: always
 command: redis-server --appendonly yes --slaveof redis-master 6379
 ports:
 - 6381:6379

启动所有容器

docker-compose up -d

查看运⾏⽇志

docker-compose logs

验证

连接主节点

redis-cli -p 6379
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=172.22.0.3,port=6379,state=online,offset=348,lag=1
slave1:ip=172.22.0.4,port=6379,state=online,offset=348,lag=1
master_replid:a22196b425ab42ddfd222cc5a64d53acffeb3e63
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:348
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:348

连接从节点

redis-cli -p 6380
127.0.0.1:6380> info replication

你可能感兴趣的:(redis,redis,学习,笔记)