百度很多,redis集群在阿里云怎么用docker一台机器弄三主三从,可惜都没有相关资料,之前是在B站看狂神视频,对docker有一些理解,恰好,自己弄了台阿里云
废话不多少,我是直接从狂神视频一步步写的,redis集群。在写xhell脚本,循环创建redis集群配置信息的时候,我从这一步用docker-compose.yml
version: "2"
services:
redis-0:
container_name: redis-0
image: redis:5.0.8
ports:
- 6400:6400
command: redis-server --port 6400 --requirepass root --appendonly yes --cluster-enabled yes --masterauth root1
expose:
- 6400
network_mode: host
volumes:
- ./reids-0/data:/data
privileged: true
redis-1:
container_name: redis-1
image: redis:5.0.8
ports:
- 6401:6401
command: redis-server --port 6401 --requirepass root --appendonly yes --cluster-enabled yes --masterauth root1
expose:
- 6401
network_mode: host
volumes:
- ./reids-1/data:/data
privileged: true
redis-2:
container_name: redis-2
image: redis:5.0.8
ports:
- 6402:6402
command: redis-server --port 6402 --requirepass root --appendonly yes --cluster-enabled yes --masterauth root1
expose:
- 6402
network_mode: host
volumes:
- ./reids-2/data:/data
privileged: true
redis-3:
container_name: redis-3
image: redis:5.0.8
ports:
- 6403:6403
command: redis-server --port 6403 --requirepass root --appendonly yes --cluster-enabled yes --masterauth root1
expose:
- 6403
network_mode: host
volumes:
- ./reids-3/data:/data
privileged: true
redis-4:
container_name: redis-4
image: redis:5.0.8
ports:
- 6404:6404
command: redis-server --port 6404 --requirepass root --appendonly yes --cluster-enabled yes --masterauth root1
expose:
- 6404
network_mode: host
volumes:
- ./reids-4/data:/data
privileged: true
redis-5:
container_name: redis-5
image: redis:5.0.8
ports:
- 6405:6405
command: redis-server --port 6405 --requirepass root --appendonly yes --cluster-enabled yes --masterauth root1
expose:
- 6405
network_mode: host
volumes:
- ./reids-5/data:/data
privileged: true
docker-compose.yml IntelliJ IDEA 2019.3.4 x64.lnk reids-0 reids-1 reids-2 reids-3 reids-4 reids-5
[root@lingweilang1 redis5]# pwd
/root/software/redis/redis5
[root@lingweilang1 redis5]#
如果不了解docker-compose的,去b站看一下。我这里不做详细介绍了
用在这个目录下,执行 docker-compose up -d 会自动帮你把docker-compose.yml配置信息读一遍,并且帮你把创建好目录结构和redis-config文件信息
docker-compose up -d 后台启动
docker-compose down 删除,连创建的docker网都会删除
docker-compose restart 重启
[root@lingweilang1 data]# ls
appendonly.aof nodes.conf
[root@lingweilang1 data]# pwd
/root/software/redis/redis5/reids-0/data
[root@lingweilang1 data]#
进入第一个容器
docker exec -it redis-0 bash