描述
我正在尝试在docker swarm中创建一个Redis集群.我正在使用bitnami-redis-docker图像来创建我的容器.通过bitnami文档,他们总是建议使用1个主节点,而不是阅读Redis文档,该文档指出应该至少有3个主节点,这就是为什么我对哪一个是正确的感到困惑.鉴于所有bitnami slave默认为只读,如果我在其中一个swarm leader节点中只设置了一个master,如果它失败了,我相信sentinel将尝试将不同的slave redis实例作为master提升,但鉴于它只读是所有写操作都会失败.如果我改变它以使主redis实例成为全局意味着它将在swarm中可用的所有节点中创建,在这种情况下我是否需要sentinel?此外,如果以下设置是好的,是否有理由引入负载均衡器?
建立
+------------------+ +------------------+ +------------------+ +------------------+
| Node-1 | | Node-2 | | Node-3 | | Node-4 |
| Leader | | Worker | | Leader | | Worker |
+------------------+ +------------------+ +------------------+ +------------------+
| M1 | | M2 | | M3 | | M4 |
| R1 | | R2 | | R3 | | R4 |
| S1 | | S2 | | S3 | | S4 |
| | | | | | | |
+------------------+ +------------------+ +------------------+ +------------------+
传说 –
>大师称为M1,M2,M3,…,Mn
> Slaves被称为R1,R2,R3,Rn(R代表复制品).
>哨兵称为S1,S2,S3,Sn
搬运工人
version: '3'
services:
redis-master:
image: 'bitnami/redis:latest'
ports:
- '6379:6379'
environment:
- REDIS_REPLICATION_MODE=master
- REDIS_PASSWORD=lasql2019
- REDIS_EXTRA_FLAGS=--maxmemory 100mb
volumes:
- 'redis-master-volume:/bitnami'
deploy:
mode: global
redis-slave:
image: 'bitnami/redis:latest'
ports:
- '6379'
depends_on:
- redis-master
volumes:
- 'redis-slave-volume:/bitnami'
environment:
- REDIS_REPLICATION_MODE=slave
- REDIS_MASTER_HOST=redis-master
- REDIS_MASTER_PORT_NUMBER=6379
- REDIS_MASTER_PASSWORD=lasql2019
- REDIS_PASSWORD=lasql2019
- REDIS_EXTRA_FLAGS=--maxmemory 100mb
deploy:
mode: replicated
replicas: 4
redis-sentinel:
image: 'bitnami/redis:latest'
ports:
- '16379'
depends_on:
- redis-master
- redis-slave
volumes:
- 'redis-sentinel-volume:/bitnami'
entrypoint: |
bash -c 'bash -s <sql2019
sentinel announce-ip redis-sentinel
sentinel announce-port 16379
EOF"
"/bin/bash" -c "redis-sentinel /opt/bitnami/redis/etc/sentinel.conf"
EOF'
deploy:
mode: global
volumes:
redis-master-volume:
driver: local
redis-slave-volume:
driver: local
redis-sentinel-volume:
driver: local