创建docker-compose.yml文件
version: '3'
services:
redis-1:
image: redis
container_name: redis-1
ports:
- "7001:7001"
- "17001:17001"
command: redis-server --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes --port 7001 --cluster-announce-ip 11.13.153.169
redis-2:
image: redis
container_name: redis-2
ports:
- "7002:7002"
- "17002:17002"
command: redis-server --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes --port 7002 --cluster-announce-ip 11.13.153.169
redis-3:
image: redis
container_name: redis-3
ports:
- "7003:7003"
- "17003:17003"
command: redis-server --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes --port 7003 --cluster-announce-ip 11.13.153.169
redis-4:
image: redis
container_name: redis-4
ports:
- "7004:7004"
- "17004:17004"
command: redis-server --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes --port 7004 --cluster-announce-ip 11.13.153.169
redis-5:
image: redis
container_name: redis-5
ports:
- "7005:7005"
- "17005:17005"
command: redis-server --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes --port 7005 --cluster-announce-ip 11.13.153.169
redis-6:
image: redis
container_name: redis-6
ports:
- "7006:7006"
- "17006:17006"
command: redis-server --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-
timeout 5000 --appendonly yes --port 7006 --cluster-announce-ip 11.13.153.169
其中11.13.153.169为本地局域网ip
创建好文件后在文件目录调用控制台,直接执行docker-compose up -d
启动成功后随便选个redis容器进入执行
命令redis-cli --cluster create 11.13.153.169:7003 11.13.153.169:7001 11.13.153.169:7002 11.13.153.169:7004 11.13.153.169:7005 11.13.153.169:7006 --cluster-replicas 1
执行后直接输入yes
看到这个就成功了