redis集群部署三主三从 docker-compose编排
时间: 2023-07-05 09:27:01 浏览: 259
好的,以下是一个简单的redis集群部署三主三从的docker-compose编排示例:
```yaml
version: '3'
services:
redis-master-1:
image: redis
command: redis-server --port 6379 --cluster-enabled yes --cluster-config-file /data/nodes.conf --cluster-node-timeout 5000 --appendonly yes
ports:
- "6379:6379"
volumes:
- redis-master-data-1:/data
networks:
- redis-net
redis-master-2:
image: redis
command: redis-server --port 6380 --cluster-enabled yes --cluster-config-file /data/nodes.conf --cluster-node-timeout 5000 --appendonly yes
ports:
- "6380:6380"
volumes:
- redis-master-data-2:/data
networks:
- redis-net
redis-master-3:
image: redis
command: redis-server --port 6381 --cluster-enabled yes --cluster-config-file /data/nodes.conf --cluster-node-timeout 5000 --appendonly yes
ports:
- "6381:6381"
volumes:
- redis-master-data-3:/data
networks:
- redis-net
redis-slave-1:
image: redis
command: redis-server --port 6382 --cluster-enabled yes --cluster-config-file /data/nodes.conf --cluster-node-timeout 5000 --slaveof redis-master-1 6379 --appendonly yes
volumes:
- redis-slave-data-1:/data
networks:
- redis-net
redis-slave-2:
image: redis
command: redis-server --port 6383 --cluster-enabled yes --cluster-config-file /data/nodes.conf --cluster-node-timeout 5000 --slaveof redis-master-2 6380 --appendonly yes
volumes:
- redis-slave-data-2:/data
networks:
- redis-net
redis-slave-3:
image: redis
command: redis-server --port 6384 --cluster-enabled yes --cluster-config-file /data/nodes.conf --cluster-node-timeout 5000 --slaveof redis-master-3 6381 --appendonly yes
volumes:
- redis-slave-data-3:/data
networks:
- redis-net
volumes:
redis-master-data-1:
redis-master-data-2:
redis-master-data-3:
redis-slave-data-1:
redis-slave-data-2:
redis-slave-data-3:
networks:
redis-net:
```
在这个docker-compose文件中,我们定义了6个redis实例,其中3个是主节点,3个是从节点,并且每个节点都会在本地暴露对应的端口。我们还定义了一个名为redis-net的网络,以便在容器之间进行通信。通过这个docker-compose文件,我们可以使用`docker-compose up`命令启动这个redis集群。
阅读全文