服务器 | 端口 | 角色 |
---|---|---|
192.168.2.2 | 6379 | master |
192.168.2.4 | 6379 | slave1 |
192.168.2.5 | 6379 | slave2 |
version: '3.7'
services:
master:
image: redis
container_name: redis-master
restart: always
command: redis-server --port 6379 --requirepass 123456 --appendonly yes
ports:
- 6379:6379
volumes:
- /home/redis:/data
version: '3.7'
services:
slave1:
image: redis
container_name: redis-slave-1
restart: always
command: redis-server --slaveof 192.168.2.2 6379 --port 6379 --requirepass 123456 --masterauth 123456 --appendonly yes
ports:
- 6379:6379
volumes:
- /home/redis/data:/data
version: '3.7'
services:
slave1:
image: redis
container_name: redis-slave-2
restart: always
command: redis-server --slaveof 192.168.2.2 6379 --port 6379 --requirepass 123456 --masterauth 123456 --appendonly yes
ports:
- 6379:6379
volumes:
- /home/redis/data:/data
在各自主从服务器中docker-compose up -d 执行
在主节点塞入一个key,两个从节点也会同时有