本文将基于以下环境部署Redis Cluster集群
tips: 本文仅基于单台服务器环境部署
可参考 https://gitee.com/zhengqingya/docker-compose
# 准备 git clone https://gitee.com/zhengqingya/docker-compose.git cd docker-compose/Liunx # 当前目录下所有文件赋予权限(读、写、执行) chmod -R 777 ./redis-cluster # 运行 -- Redis Cluster 集群 docker-compose -f docker-compose-redis-cluster.yml -p redis up -d
运行成功
docker exec -it redis-6381 redis-cli -h 172.22.0.11 -p 6381 -a 123456 --cluster create 172.22.0.11:6381 redis-6382:6382 redis-6383:6383 redis-6384:6384 redis-6385:6385 redis-6386:6386 --cluster-replicas 1
# 连接集群某个节点 docker exec -it redis-6381 redis-cli -c -h redis-6381 -p 6381 -a 123456 # 查看集群信息 cluster info # 查看集群节点信息 cluster nodes # 查看slots分片 cluster slots
version: '3' # 网桥redis -> 方便相互通讯 networks: redis: ipam: driver: default config: - subnet: "172.22.0.0/24" services: redis-6381: image: registry.cn-hangzhou.aliyuncs.com/zhengqing/redis:6.0.8 # 镜像'redis:6.0.8' container_name: redis-6381 # 容器名为'redis-6381' restart: unless-stopped # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器 command: redis-server /etc/redis/redis.conf --port 6381 --requirepass 123456 --appendonly no # 启动redis服务并添加密码为:123456,默认不开启redis-aof方式持久化配置,连接并认证master节点 environment: # 设置环境变量,相当于docker run命令中的-e TZ: Asia/Shanghai LANG: en_US.UTF-8 volumes: # 数据卷挂载路径设置,将本机目录映射到容器目录 - "./redis-cluster/redis-6381/data:/data" - "./redis-cluster/redis-6381/config/redis.conf:/etc/redis/redis.conf" # `redis.conf`文件内容`http://download.redis.io/redis-stable/redis.conf` ports: # 映射端口 - "6381:6381" networks: redis: ipv4_address: 172.22.0.11 redis-6382: image: registry.cn-hangzhou.aliyuncs.com/zhengqing/redis:6.0.8 # 镜像'redis:6.0.8' container_name: redis-6382 # 容器名为'redis-6382' restart: unless-stopped # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器 command: redis-server /etc/redis/redis.conf --port 6382 --requirepass 123456 --appendonly no # 启动redis服务并添加密码为:123456,默认不开启redis-aof方式持久化配置,连接并认证master节点 environment: # 设置环境变量,相当于docker run命令中的-e TZ: Asia/Shanghai LANG: en_US.UTF-8 volumes: # 数据卷挂载路径设置,将本机目录映射到容器目录 - "./redis-cluster/redis-6382/data:/data" - "./redis-cluster/redis-6382/config/redis.conf:/etc/redis/redis.conf" # `redis.conf`文件内容`http://download.redis.io/redis-stable/redis.conf` ports: # 映射端口 - "6382:6382" networks: redis: ipv4_address: 172.22.0.2 redis-6383: image: registry.cn-hangzhou.aliyuncs.com/zhengqing/redis:6.0.8 # 镜像'redis:6.0.8' container_name: redis-6383 # 容器名为'redis-6383' restart: unless-stopped # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器 command: redis-server /etc/redis/redis.conf --port 6383 --requirepass 123456 --appendonly no # 启动redis服务并添加密码为:123456,默认不开启redis-aof方式持久化配置,连接并认证master节点 environment: # 设置环境变量,相当于docker run命令中的-e TZ: Asia/Shanghai LANG: en_US.UTF-8 volumes: # 数据卷挂载路径设置,将本机目录映射到容器目录 - "./redis-cluster/redis-6383/data:/data" - "./redis-cluster/redis-6383/config/redis.conf:/etc/redis/redis.conf" # `redis.conf`文件内容`http://download.redis.io/redis-stable/redis.conf` ports: # 映射端口 - "6383:6383" networks: redis: ipv4_address: 172.22.0.3 redis-6384: image: registry.cn-hangzhou.aliyuncs.com/zhengqing/redis:6.0.8 # 镜像'redis:6.0.8' container_name: redis-6384 # 容器名为'redis-6384' restart: unless-stopped # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器 command: redis-server /etc/redis/redis.conf --port 6384 --requirepass 123456 --appendonly no # 启动redis服务并添加密码为:123456,默认不开启redis-aof方式持久化配置,连接并认证master节点 environment: # 设置环境变量,相当于docker run命令中的-e TZ: Asia/Shanghai LANG: en_US.UTF-8 volumes: # 数据卷挂载路径设置,将本机目录映射到容器目录 - "./redis-cluster/redis-6384/data:/data" - "./redis-cluster/redis-6384/config/redis.conf:/etc/redis/redis.conf" # `redis.conf`文件内容`http://download.redis.io/redis-stable/redis.conf` ports: # 映射端口 - "6384:6384" networks: redis: ipv4_address: 172.22.0.4 redis-6385: image: registry.cn-hangzhou.aliyuncs.com/zhengqing/redis:6.0.8 # 镜像'redis:6.0.8' container_name: redis-6385 # 容器名为'redis-6385' restart: unless-stopped # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器 command: redis-server /etc/redis/redis.conf --port 6385 --requirepass 123456 --appendonly no # 启动redis服务并添加密码为:123456,默认不开启redis-aof方式持久化配置,连接并认证master节点 environment: # 设置环境变量,相当于docker run命令中的-e TZ: Asia/Shanghai LANG: en_US.UTF-8 volumes: # 数据卷挂载路径设置,将本机目录映射到容器目录 - "./redis-cluster/redis-6385/data:/data" - "./redis-cluster/redis-6385/config/redis.conf:/etc/redis/redis.conf" # `redis.conf`文件内容`http://download.redis.io/redis-stable/redis.conf` ports: # 映射端口 - "6385:6385" networks: redis: ipv4_address: 172.22.0.5 redis-6386: image: registry.cn-hangzhou.aliyuncs.com/zhengqing/redis:6.0.8 # 镜像'redis:6.0.8' container_name: redis-6386 # 容器名为'redis-6386' restart: unless-stopped # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器 command: redis-server /etc/redis/redis.conf --port 6386 --requirepass 123456 --appendonly no # 启动redis服务并添加密码为:123456,默认不开启redis-aof方式持久化配置 environment: # 设置环境变量,相当于docker run命令中的-e TZ: Asia/Shanghai LANG: en_US.UTF-8 volumes: # 数据卷挂载路径设置,将本机目录映射到容器目录 - "./redis-cluster/redis-6386/data:/data" - "./redis-cluster/redis-6386/config/redis.conf:/etc/redis/redis.conf" # `redis.conf`文件内容`http://download.redis.io/redis-stable/redis.conf` ports: # 映射端口 - "6386:6386" networks: redis: ipv4_address: 172.22.0.6
参考 http://download.redis.io/redis-stable/redis.conf
集群主要新增了如下配置
今日分享语句:
一个人必须面对自己不能承受的东西,然后起个名字叫成长。