docker安装Redis集群
1.创建安装目录
cd /mnt
mkdir redis-cluster
cd redis-cluster
mkdir -p 6380/conf 6381/conf 6382/conf
2.分别编写conf文件,在6380/conf 6381/conf 6382/conf下
1) 6380 redis.conf
port 6380
requirepass 123456
masterauth 123456
protected-mode no
daemonize no
appendonly yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 15000
cluster-announce-ip 192.168.0.87
cluster-announce-port 6380
cluster-announce-bus-port 16380
2) 6381 redis.conf
port 6381
requirepass 123456
masterauth 123456
protected-mode no
daemonize no
appendonly yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 15000
cluster-announce-ip 192.168.0.87
cluster-announce-port 6381
cluster-announce-bus-port 16381
3) 6382 redis.conf
port 6382
requirepass 123456
masterauth 123456
protected-mode no
daemonize no
appendonly yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 15000
cluster-announce-ip 192.168.0.87
cluster-announce-port 6382
cluster-announce-bus-port 16382
3.编写docker-compose.yml文件
version: "3.2"
# 定义服务,可以多个
services:
redis-cluster:
image: redis:6.0.8
command: redis-cli -a 123456 --cluster create 192.168.0.87:6380 192.168.0.87:6381 192.168.0.87:6382 --cluster-replicas 0 --cluster-yes
depends_on:
- redis-6380
- redis-6381
- redis-6382
redis-6380: # 服务名称
image: redis:6.0.8 # 创建容器时所需的镜像
container_name: redis-6380 # 容器名称
restart: always # 容器总是重新启动
ports:
- 6380:6380
- 16380:16380
volumes: # 数据卷,目录挂载
- ./etc_rc.local:/etc/rc.local
- ./6380/conf/redis.conf:/etc/redis/redis.conf
- ./6380/data:/data
command: redis-server /etc/redis/redis.conf # 覆盖容器启动后默认执行的命令
redis-6381:
image: redis:6.0.8
container_name: redis-6381
restart: always
ports:
- 6381:6381
- 16381:16381
volumes:
- ./etc_rc.local:/etc/rc.local
- ./6381/conf/redis.conf:/etc/redis/redis.conf
- ./6381/data:/data
command: redis-server /etc/redis/redis.conf
redis-6382:
image: redis:6.0.8
container_name: redis-6382
restart: always
ports:
- 6382:6382
- 16382:16382
volumes:
- ./etc_rc.local:/etc/rc.local
- ./6382/conf/redis.conf:/etc/redis/redis.conf
- ./6382/data:/data
command: redis-server /etc/redis/redis.conf
4.完整目录结构
│ docker-compose.yml
│
├─6380
│ └─conf
│ redis.conf
│
├─6381
│ └─conf
│ redis.conf
│
└─6382
└─conf
redis.conf
5.构建redis集群
docker-compose up -d
6.验证集群是否部署成功
docker exec -it redis-6381 bash
redis-cli -p 6381
auth 123456
cluster info还没有评论,来说两句吧
