Redis 集群 docker swarm 使用 docker compose
Redis cluster with docker swarm using docker compose
我只是在学习 docker 以及它的所有优势,例如 swarm 和 compose。我的意图是在 docker 群中创建一个 Redis 集群。
这是我的撰写文件 -
version: '3'
services:
redis:
image: redis:alpine
command: ["redis-server","--appendonly yes","--cluster-enabled yes","--cluster-node-timeout 60000","--cluster-require-full-coverage no"]
deploy:
replicas: 5
restart_policy:
condition: on-failure
ports:
- 6379:6379
- 16379:16379
networks:
host:
external: true
如果我添加 network: - host
然后 none 容器启动,如果我删除它然后容器启动但是当我尝试连接时它会抛出类似 CLUSTERDOWN Hash slot not served
的错误。
规格 -
Windows 10
Docker Swarm Nodes -
2 Virtual Box VMs running Alpine Linux 3.7.0 with two networks
VirtualBox VM Network -
eth0 - NAT
eth1 - VirtualBox Host-only network
Docker running inside the above VMs -
17.12.1-ce
不幸的是,对于任何为此苦苦挣扎的人,这还不能通过 docker-compose.yml
完成。参考这个问题Start Redis cluster #79。唯一的方法是获取所有 运行 Redis 节点的 IP 地址和端口,然后 运行 在任何 swarm 节点中执行此命令。
# Gives you all the command help
docker run --rm -it thesobercoder/redis-trib
# This creates all master nodes
docker run --rm -it thesobercoder/redis-trib create 172.17.8.101:7000 172.17.8.102:7000 172.17.8.103:7000
# This creates slaves nodes. Note that this requires at least six nodes running master
docker run --rm -it thesobercoder/redis-trib create --replicas 1 172.17.8.101:7000 172.17.8.102:7000 172.17.8.103:7000 172.17.8.104:7000 172.17.8.105:7000 172.17.8.106:7000
这似乎对我有用,来自 here 的网络配置:
version: '3.6'
services:
redis:
image: redis:5.0.3
command:
- "redis-server"
- "--cluster-enabled yes"
- "--cluster-config-file nodes.conf"
- "--cluster-node-timeout 5000"
- "--appendonly yes"
deploy:
mode: global
restart_policy:
condition: on-failure
networks:
hostnet: {}
networks:
hostnet:
external: true
name: host
然后运行例如:echo yes | docker run -i --rm --entrypoint redis-cli redis:5.0.3 --cluster create 1.2.3.4{1,2,3}:6379 --cluster-replicas 0
显然更换你的 IP。
这里是 redis 集群的 repo
https://github.com/jay-johnson/docker-redis-cluster/blob/master/docker-compose.yml
我只是在学习 docker 以及它的所有优势,例如 swarm 和 compose。我的意图是在 docker 群中创建一个 Redis 集群。
这是我的撰写文件 -
version: '3'
services:
redis:
image: redis:alpine
command: ["redis-server","--appendonly yes","--cluster-enabled yes","--cluster-node-timeout 60000","--cluster-require-full-coverage no"]
deploy:
replicas: 5
restart_policy:
condition: on-failure
ports:
- 6379:6379
- 16379:16379
networks:
host:
external: true
如果我添加 network: - host
然后 none 容器启动,如果我删除它然后容器启动但是当我尝试连接时它会抛出类似 CLUSTERDOWN Hash slot not served
的错误。
规格 -
Windows 10
Docker Swarm Nodes -
2 Virtual Box VMs running Alpine Linux 3.7.0 with two networks
VirtualBox VM Network -
eth0 - NAT
eth1 - VirtualBox Host-only network
Docker running inside the above VMs -
17.12.1-ce
不幸的是,对于任何为此苦苦挣扎的人,这还不能通过 docker-compose.yml
完成。参考这个问题Start Redis cluster #79。唯一的方法是获取所有 运行 Redis 节点的 IP 地址和端口,然后 运行 在任何 swarm 节点中执行此命令。
# Gives you all the command help
docker run --rm -it thesobercoder/redis-trib
# This creates all master nodes
docker run --rm -it thesobercoder/redis-trib create 172.17.8.101:7000 172.17.8.102:7000 172.17.8.103:7000
# This creates slaves nodes. Note that this requires at least six nodes running master
docker run --rm -it thesobercoder/redis-trib create --replicas 1 172.17.8.101:7000 172.17.8.102:7000 172.17.8.103:7000 172.17.8.104:7000 172.17.8.105:7000 172.17.8.106:7000
这似乎对我有用,来自 here 的网络配置:
version: '3.6'
services:
redis:
image: redis:5.0.3
command:
- "redis-server"
- "--cluster-enabled yes"
- "--cluster-config-file nodes.conf"
- "--cluster-node-timeout 5000"
- "--appendonly yes"
deploy:
mode: global
restart_policy:
condition: on-failure
networks:
hostnet: {}
networks:
hostnet:
external: true
name: host
然后运行例如:echo yes | docker run -i --rm --entrypoint redis-cli redis:5.0.3 --cluster create 1.2.3.4{1,2,3}:6379 --cluster-replicas 0
显然更换你的 IP。
这里是 redis 集群的 repo
https://github.com/jay-johnson/docker-redis-cluster/blob/master/docker-compose.yml