首页 > 数据库 >docker-compose之redis cluster模式

docker-compose之redis cluster模式

时间:2022-11-25 11:14:44浏览次数:67  
标签:compose -- redis cluster announce xbd docker yes

  一、docker容器化的redis cluster最难搞的就是网络问题,这边记录一下集群搭建过程。

  二、dockerfile

FROM redis:5.0.14
MAINTAINER xbd
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

  三、docker-compose.yml

version: "2"
services:
  xbd-redis-1:
    build:
      context: ./
      dockerfile: ./config/Dockerfile/Dockerfile-redis
    image: xbd-redis-1
    restart: always
    container_name: xbd-redis-1
    ports:
      - 6379:6379
      - 16379:16379
    environment:
      - TZ=Asia/Shanghai
    privileged: true
    command: ['redis-server',
              '--bind 0.0.0.0',
              '--protected-mode yes',
              '--daemonize no',
              '--requirepass xbd',
              '--maxmemory 1GB',
              '--maxmemory-policy allkeys-lru',
              '--cluster-enabled yes',
              '--cluster-config-file nodes-6379.conf',
              '--cluster-node-timeout 15000',
              '--cluster-replica-validity-factor 10',
              '--cluster-migration-barrier 1',
              '--cluster-require-full-coverage yes',
              '--cluster-replica-no-failover no',
              '--cluster-announce-ip 192.168.5.14',
              '--cluster-announce-port 6379',
              '--cluster-announce-bus-port 16379']

  xbd-redis-2:
    build:
      context: ./
      dockerfile: ./config/Dockerfile/Dockerfile-redis
    image: xbd-redis-2
    restart: always
    container_name: xbd-redis-2
    ports:
      - 6380:6379
      - 16380:16379
    environment:
      - TZ=Asia/Shanghai
    privileged: true
    command: ['redis-server',
              '--bind 0.0.0.0',
              '--protected-mode yes',
              '--daemonize no',
              '--requirepass xbd',
              '--maxmemory 1GB',
              '--maxmemory-policy allkeys-lru',
              '--cluster-enabled yes',
              '--cluster-config-file nodes-6379.conf',
              '--cluster-node-timeout 15000',
              '--cluster-replica-validity-factor 10',
              '--cluster-migration-barrier 1',
              '--cluster-require-full-coverage yes',
              '--cluster-replica-no-failover no',
              '--cluster-announce-ip 192.168.5.14',
              '--cluster-announce-port 6380',
              '--cluster-announce-bus-port 16380']
  xbd-redis-3:
    build:
      context: ./
      dockerfile: ./config/Dockerfile/Dockerfile-redis
    image: xbd-redis-3
    restart: always
    container_name: xbd-redis-3
    ports:
      - 6381:6379
      - 16381:16379
    environment:
      - TZ=Asia/Shanghai
    privileged: true
    command: ['redis-server',
              '--bind 0.0.0.0',
              '--protected-mode yes',
              '--daemonize no',
              '--requirepass xbd',
              '--maxmemory 1GB',
              '--maxmemory-policy allkeys-lru',
              '--cluster-enabled yes',
              '--cluster-config-file nodes-6379.conf',
              '--cluster-node-timeout 15000',
              '--cluster-replica-validity-factor 10',
              '--cluster-migration-barrier 1',
              '--cluster-require-full-coverage yes',
              '--cluster-replica-no-failover no',
              '--cluster-announce-ip 192.168.5.14',
              '--cluster-announce-port 6381',
              '--cluster-announce-bus-port 16381']

  xbd-redis-4:
    build:
      context: ./
      dockerfile: ./config/Dockerfile/Dockerfile-redis
    image: xbd-redis-4
    restart: always
    container_name: xbd-redis-4
    ports:
      - 6382:6379
      - 16382:16379
    environment:
      - TZ=Asia/Shanghai
    privileged: true
    command: ['redis-server',
              '--bind 0.0.0.0',
              '--protected-mode yes',
              '--daemonize no',
              '--requirepass xbd',
              '--maxmemory 1GB',
              '--maxmemory-policy allkeys-lru',
              '--cluster-enabled yes',
              '--cluster-config-file nodes-6379.conf',
              '--cluster-node-timeout 15000',
              '--cluster-replica-validity-factor 10',
              '--cluster-migration-barrier 1',
              '--cluster-require-full-coverage yes',
              '--cluster-replica-no-failover no',
              '--cluster-announce-ip 192.168.5.14',
              '--cluster-announce-port 6382',
              '--cluster-announce-bus-port 16382']

  参数说明

# 绑定IP
bind 0.0.0.0
# 保护模式
protected-mode yes
# docker原因不用守护进程
daemonize no
# 认证密码
requirepass xbd
# 最大内存,按实际要求设定
maxmemory 1GB
# 内存回收策略
maxmemory-policy allkeys-lru
# 集群开启
cluster-enabled yes
# 节点记录文件,自动写入
cluster-config-file nodes-6379.conf
# 节点超时时间
cluster-node-timeout 15000
# 故障转移的超时时间
cluster-replica-validity-factor 10
# 最少副本数量
cluster-migration-barrier 1
# 控制集群高可用,设置为yes,则允许在分片不可用或者集群路由未完全分配的情况下,其他的分片仍然提供服务
cluster-require-full-coverage yes
# # 选项设置为yes时,会阻止replicas尝试对其master在主故障期间进行故障转移
# 然而,master仍然可以执行手动故障转移,如果强制这样做的话。
cluster-replica-no-failover no
# 真实IP,docker时使用
cluster-announce-ip 192.168.5.14
# 端口
cluster-announce-port 6379
# 内部端口
cluster-announce-bus-port 16379'

  详细参数说明:https://www.cnblogs.com/ll409546297/p/16922764.html

  四、部署

  1)运行docker容器

docker-compose up &

  2)手动建立集群

redis-cli -a xbd --cluster create 192.168.5.14:6379 192.168.5.14:6380 192.168.5.14:6381 192.168.5.14:6382

  集群会出现:

  

  3)集群查看和确认hash槽

  

 

   

 

   可以确认,集群已经成功,并且自动分配了hash槽。

  3)测试(一定要带-c,主要声明集群模式):

redis-cli -h 192.168.5.14 -p 6379 -a xbd -c

  

 

   确认自己做了节点迁移,数据存储和查询。

标签:compose,--,redis,cluster,announce,xbd,docker,yes
From: https://www.cnblogs.com/ll409546297/p/16924478.html

相关文章

  • 3.3 Docker最新入门教程-Docker入门-更新应用程序
    3.3更新应用程序在第2部分中,您容器化了一个待办事项应用程序。在这一部分中,您将更新应用程序和容器镜像。您还将学习如何停止和删除容器。更新源代码在下面的步骤中,......
  • 在centos 7上部署安装docker
    一、docker概述docker资源地址官网:https://www.docker.com/文档地址:https://docs.docker.com/仓库地址:https://hub.docker.com/镜像(images):docker镜像就好比是一个模......
  • Docker Java+Tomcat 环境搭建
    Docker更多资料请到​​https://dashboard.daocloud.io​​学习 软件环境:jdk、tomcat、docker、centos、虚拟机  首先,您要准备一个CentOS的操作系统,虚拟机也行。总之,......
  • 一文说清楚Dockerfile 中VOLUME到底有什么用?
    一文说清楚Dockerfile中VOLUME到底有什么用?原创2021-10-2500:25:2125点赞https://blog.csdn.net/qq32933432/article/details/120944205诺浅码龄11年关注写在开头相......
  • linux docker 远程连接配置
    新买的服务器安装docker,记录下配置过程默认配置下,dockerdaemon只响应来自本地host的客户端请求。如果需要远程客户端请求,需要修改配置文件vim/etc/systemd/system/mu......
  • pve开启lxc容器ipv6并为docker-qBittorrent容器配置ipv6
    pve开启lxc容器ipv6并为docker容器配置ipv6写这篇文档是记录一下为了记录用pveLXC容器安装的docker版qBittorrent开启ipv6,这样下载的速度会快一点,这其中有很多坑,随笔记录......
  • Docker总结整合(一)
    1、简介Docker是一个开源的应用容器引擎;是一个轻量级容器技术;Docker支持将软件编译成一个镜像;然后在镜像中各种软件做好配置,将镜像发布出去,其他使用者可以直接使用这个镜像......
  • [Docker]How to run CentOS in Docker container
    dockerpullcentosdockerimagesdockerrun-d-i-p10000:80centosdockerps 为什么需要加-i的参数:Nothingisactivelyrunning.Thatmakessense,because......
  • DockerFile解析-笔记-全
    是什么DockerFile是用来构建Docker镜像的构建文件,是由一系列命令和参数构成的脚本。构建三步骤:   编写dockerfile文件   dockerbuild   dockerrun文件什么......
  • Docker常用命令整理实例-全
    笔记来自:​​https://pan.baidu.com/s/1FLcOpjpJTJlP36lzD-kfWA#list/path=%2F​​帮助命令dockerversiondockerinfodocker--help镜像命令dockerimages列出本地主机......