编排 redis 主从节点
version: '3.7'
services:master:image: 'redis:5.0.9' container_name: redis-masterrestart: alwayscommand: redis-server --appendonly yes ports:- 6379 :6379slave1:image: 'redis:5.0.9' container_name: redis-slave1restart: alwayscommand: redis-server --appendonly yes --slaveof redis-master 6379 ports:- 6380 :6379slave2:image: 'redis:5.0.9' container_name: redis-slave2restart: alwayscommand: 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
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