【架构】docker实现集群主从扩容【案例3/4】

这篇具有很好参考价值的文章主要介绍了【架构】docker实现集群主从扩容【案例3/4】。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

实现集群主从扩容

当整个集群扛不住流量的情况时,需要给集群扩容增加设备,由3主3从,扩为4主4从。实现:

示意图如下:
【架构】docker实现集群主从扩容【案例3/4】,docker,架构,docker,java

第一步:新创建两个节点(redis-node-7,端口6387和 redis-node-8,端口6388),并启动。
尽可能和之前创建节点的命名规则一致

docker run -d --name redis-node-7 --net host --privileged=true -v /data/redis/share/redis-node-7:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6387

docker run -d --name redis-node-8 --net host --privileged=true -v /data/redis/share/redis-node-8:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6388

第二步:进入其中任意一个容器实例内部

docker exec -it redis-node-7 /bin/bash

第三步:将新的redis-node-7节点(空槽位),作为master加入集群 【--cluster add-node

redis-cli --cluster add-node  12.114.161.16:6387  12.114.161.16:6381
root@localhost:/data# redis-cli --cluster add-node  12.114.161.16:6387    12.114.161.16:6381
>>> Adding node 12.114.161.16:6387 to cluster 12.114.161.16:6381
>>> Performing Cluster Check (using node 12.114.161.16:6381)
M: 6e961a4765b555189708bebb69badf7dfad25cd5 12.114.161.16:6381
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 4ed46e0368698cd9d5af2ee84631c878b8ebc4d0 12.114.161.16:6386
   slots: (0 slots) slave
   replicates 6e961a4765b555189708bebb69badf7dfad25cd5
S: 9bc2417a9cd6545ef2445eb4aa0610d586acd73b 12.114.161.16:6385
   slots: (0 slots) slave
   replicates 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2
S: 0e34147ce2544cd90f5cce78d5493ae9e8625dfe 12.114.161.16:6384
   slots: (0 slots) slave
   replicates f097fec937f54d147d316c1c62e26cb67c9fd059
M: f097fec937f54d147d316c1c62e26cb67c9fd059 12.114.161.16:6382
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2 12.114.161.16:6383
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 12.114.161.16:6387 to make it join the cluster.
[OK] New node added correctly.

第四步:查看集群情况(第一次)

redis-cli --cluster check 127.0.0.1:6387
root@localhost:/data# redis-cli --cluster check 127.0.0.1:6387
127.0.0.1:6387 (bf73145e...) -> 0 keys | 0 slots | 0 slaves.      # 新增加Master主机 包含0槽位,0台从机器
12.114.161.16:6381 (6e961a47...) -> 2 keys | 5461 slots | 1 slaves.
12.114.161.16:6383 (78ac7be1...) -> 1 keys | 5461 slots | 1 slaves.
12.114.161.16:6382 (f097fec9...) -> 1 keys | 5462 slots | 1 slaves.
[OK] 4 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:6387)
M: bf73145e2eaaaa08084c9c2dad0d8c757faa48e1 127.0.0.1:6387
   slots: (0 slots) master                               # 新增加Master主机,但是哈希槽个数为 0    
S: 4ed46e0368698cd9d5af2ee84631c878b8ebc4d0 12.114.161.16:6386
   slots: (0 slots) slave
   replicates 6e961a4765b555189708bebb69badf7dfad25cd5
S: 9bc2417a9cd6545ef2445eb4aa0610d586acd73b 12.114.161.16:6385
   slots: (0 slots) slave
   replicates 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2
M: 6e961a4765b555189708bebb69badf7dfad25cd5 12.114.161.16:6381
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 0e34147ce2544cd90f5cce78d5493ae9e8625dfe 12.114.161.16:6384
   slots: (0 slots) slave
   replicates f097fec937f54d147d316c1c62e26cb67c9fd059
M: 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2 12.114.161.16:6383
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: f097fec937f54d147d316c1c62e26cb67c9fd059 12.114.161.16:6382
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

第五步:给该主机,重新分派槽号【--cluster reshard

redis-cli --cluster reshard 12.114.161.16:6381
root@localhost:/data# redis-cli --cluster reshard 12.114.161.16:6381
>>> Performing Cluster Check (using node 12.114.161.16:6381)
M: 6e961a4765b555189708bebb69badf7dfad25cd5 12.114.161.16:6381
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 4ed46e0368698cd9d5af2ee84631c878b8ebc4d0 12.114.161.16:6386
   slots: (0 slots) slave
   replicates 6e961a4765b555189708bebb69badf7dfad25cd5
M: bf73145e2eaaaa08084c9c2dad0d8c757faa48e1 12.114.161.16:6387
   slots: (0 slots) master
S: 9bc2417a9cd6545ef2445eb4aa0610d586acd73b 12.114.161.16:6385
   slots: (0 slots) slave
   replicates 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2
S: 0e34147ce2544cd90f5cce78d5493ae9e8625dfe 12.114.161.16:6384
   slots: (0 slots) slave
   replicates f097fec937f54d147d316c1c62e26cb67c9fd059
M: f097fec937f54d147d316c1c62e26cb67c9fd059 12.114.161.16:6382
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2 12.114.161.16:6383
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 4096                # 分配槽位个数为:16384 / Master主机个数 
What is the receiving node ID? bf73145e2eaaaa08084c9c2dad0d8c757faa48e1   # 选择新加的Master主机id号
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
Source node #1: all    # 选用之前的Master主机作为 哈希槽源
...
...

第六步:查看集群情况(第二次)

redis-cli --cluster check 127.0.0.1:6387
root@localhost:/data# redis-cli --cluster check 12.114.161.16:6381
12.114.161.16:6381 (6e961a47...) -> 1 keys | 4096 slots | 1 slaves.
12.114.161.16:6387 (bf73145e...) -> 1 keys | 4096 slots | 0 slaves.   # 注意: 新加Master主机分得槽位,0个从机
12.114.161.16:6382 (f097fec9...) -> 1 keys | 4096 slots | 1 slaves.
12.114.161.16:6383 (78ac7be1...) -> 1 keys | 4096 slots | 1 slaves.
[OK] 4 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 12.114.161.16:6381)
M: 6e961a4765b555189708bebb69badf7dfad25cd5 12.114.161.16:6381
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
S: 4ed46e0368698cd9d5af2ee84631c878b8ebc4d0 12.114.161.16:6386
   slots: (0 slots) slave
   replicates 6e961a4765b555189708bebb69badf7dfad25cd5
M: bf73145e2eaaaa08084c9c2dad0d8c757faa48e1 12.114.161.16:6387
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master    # 特别注意:新主机的4096槽位,分三个段,从原主机瓜分而来
S: 9bc2417a9cd6545ef2445eb4aa0610d586acd73b 12.114.161.16:6385
   slots: (0 slots) slave
   replicates 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2
S: 0e34147ce2544cd90f5cce78d5493ae9e8625dfe 12.114.161.16:6384
   slots: (0 slots) slave
   replicates f097fec937f54d147d316c1c62e26cb67c9fd059
M: f097fec937f54d147d316c1c62e26cb67c9fd059 12.114.161.16:6382
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
M: 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2 12.114.161.16:6383
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

第七步:增加第四台Slave主机(端口6388,redis-node-8)到新的Master主机

redis-cli --cluster add-node ip:新slave端口 ip:新master端口 --cluster-slave --cluster-master-id 新主机节点ID

redis-cli --cluster add-node 12.114.161.16:6388 12.114.161.16:6387 --cluster-slave --cluster-master-id   bf73145e2eaaaa08084c9c2dad0d8c757faa48e1
root@localhost:/data# redis-cli --cluster add-node 12.114.161.16:6388   12.114.161.16:6387 --cluster-slave --cluster-master-id bf73145e2eaaaa08084c9c2dad0d8c757faa48e1
>>> Adding node 12.114.161.16:6388 to cluster 12.114.161.16:6387
>>> Performing Cluster Check (using node 12.114.161.16:6387)
M: bf73145e2eaaaa08084c9c2dad0d8c757faa48e1 12.114.161.16:6387
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: 4ed46e0368698cd9d5af2ee84631c878b8ebc4d0 12.114.161.16:6386
   slots: (0 slots) slave
   replicates 6e961a4765b555189708bebb69badf7dfad25cd5
S: 9bc2417a9cd6545ef2445eb4aa0610d586acd73b 12.114.161.16:6385
   slots: (0 slots) slave
   replicates 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2
M: 6e961a4765b555189708bebb69badf7dfad25cd5 12.114.161.16:6381
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
S: 0e34147ce2544cd90f5cce78d5493ae9e8625dfe 12.114.161.16:6384
   slots: (0 slots) slave
   replicates f097fec937f54d147d316c1c62e26cb67c9fd059
M: 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2 12.114.161.16:6383
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
M: f097fec937f54d147d316c1c62e26cb67c9fd059 12.114.161.16:6382
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 12.114.161.16:6388 to make it join the cluster.   # 端口6388,redis-node-8 新的从主机,加入集群
Waiting for the cluster to join

>>> Configure node as replica of 12.114.161.16:6387.
[OK] New node added correctly.

第八步:查看集群情况(第三次)

redis-cli --cluster check 127.0.0.1:6387
root@localhost:/data# redis-cli --cluster check 127.0.0.1:6387
127.0.0.1:6387 (bf73145e...) -> 1 keys | 4096 slots | 1 slaves.   # 新加入1个从主机
12.114.161.16:6381 (6e961a47...) -> 1 keys | 4096 slots | 1 slaves.
12.114.161.16:6383 (78ac7be1...) -> 1 keys | 4096 slots | 1 slaves.
12.114.161.16:6382 (f097fec9...) -> 1 keys | 4096 slots | 1 slaves.
[OK] 4 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:6387)
M: bf73145e2eaaaa08084c9c2dad0d8c757faa48e1 127.0.0.1:6387
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
   1 additional replica(s)
S: 4ed46e0368698cd9d5af2ee84631c878b8ebc4d0 12.114.161.16:6386
   slots: (0 slots) slave
   replicates 6e961a4765b555189708bebb69badf7dfad25cd5
S: 664e456ae7d5cf27ea6583ba2f437dac11d4e767 12.114.161.16:6388   # 从主机redis-node-8,成功加入master主机
   slots: (0 slots) slave
   replicates bf73145e2eaaaa08084c9c2dad0d8c757faa48e1
S: 9bc2417a9cd6545ef2445eb4aa0610d586acd73b 12.114.161.16:6385
   slots: (0 slots) slave
   replicates 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2
M: 6e961a4765b555189708bebb69badf7dfad25cd5 12.114.161.16:6381
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
S: 0e34147ce2544cd90f5cce78d5493ae9e8625dfe 12.114.161.16:6384
   slots: (0 slots) slave
   replicates f097fec937f54d147d316c1c62e26cb67c9fd059
M: 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2 12.114.161.16:6383
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
M: f097fec937f54d147d316c1c62e26cb67c9fd059 12.114.161.16:6382
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

- 前3个Master机器,每个机器“切”出一部分槽位,分别给第四台新加的Master的槽位,好处:
1、避免从新分配,资源分配浪费;
2、原来每个Master槽位的数据,不用重新分配;文章来源地址https://www.toymoban.com/news/detail-794892.html

到了这里,关于【架构】docker实现集群主从扩容【案例3/4】的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【Redis】Redis三种集群模式-主从、哨兵、集群各自架构的优点和缺点对比

    如果Redis的读写请求量很大,那么单个实例很有可能承担不了这么大的请求量,如何提高Redis的性能呢?你也许已经想到了,可以部署多个副本节点,业务采用读写分离的方式,把读请求分担到多个副本节点上,提高访问性能。要实现读写分离,就必须部署多个副本,每个副本

    2024年02月12日
    浏览(40)
  • docker 配置 Mysql主从集群

    Docker version 20.10.17, build 100c701 MySQL Image version: 8.0.32 Docker container mysql-master is source. mysql-replica is replication. master == source. replica == slave.名称叫法不一样而已。 Choose one of the way,与replica同步数据两种情况: source有存在的数据并且你想同步到replica,这种需要mysqldump备份source数据,

    2023年04月14日
    浏览(46)
  • docker Mysql部署主从集群

    目录 1 docker安装 2 docker mysql 安装配置 远程连接 2.0 配置 2.0.1 文件夹 配置 2.0.2 主库文件配置 my.cnf - 主库 id 和 开启二进制日志  2.0.3 从库文件配置 - 从库 id 2.1 mysql 主 - 第一个端口号和从库不一样 2.1.1 docker run 主库 2.1.2  查看主库二进制日志 2.2 mysql 从库 2.2.1 docker run 从库

    2024年02月02日
    浏览(44)
  • Docker集群部署-MySQL主从复制

    利用Docker实现MySQL主从复制架构的部署,实现1主1从集群配置。 要求实验主机能够连接外网,已经正确安装Docker,并关闭防火墙和selinux。 新建主服务器容器实例3307 # docker run -p 3307:3306 --name mysql-master -v /mydata/mysql-master/log:/var/log/mysql -v /mydata/mysql-master/data:/var/lib/mysql -v /m

    2024年02月12日
    浏览(37)
  • 使用Docker搭建Redis主从集群

    欢迎来到 请回答1024 的博客 🍓🍓🍓欢迎来到 请回答1024的博客 关于博主 : 我是 请回答1024 ,一个追求数学与计算的边界、时间与空间的平衡,0与1的延伸的后端开发者。 博客特色 : 在我的博客中,开设了如下专栏( 点击可以进入专栏奥~ ): Java、MySQL、Redis、Spring、SpringB

    2024年04月24日
    浏览(43)
  • 【MySQL5.7麒麟系统,ARM架构下离线安装,搭建主从集群】

    注意:MsSQL8.0开始才支持arm架构,我们可以去第三方下载编译好的安装包,或者可以采取docker安装 注意:信息中心的服务器需要自己挂盘,建议统一挂载到/data目录 1、修改配置文件 2、设置开机自动启动 3、添加环境变量 4、初始化启动MySQL 5、修改MySQL密码,并允许远程连接

    2024年02月03日
    浏览(37)
  • Docker 容器搭建mysql 集群(主从数据库)

    目录 1.背景         2.设备及软件版本 3.开始搭建(这里不介绍安装docker及mysql) 3.1创建主数据库容器(master) 3.2查看容器是否创建成功 3.3进入修改容器下的/etc/my.cnf文件 3.3.1先拷贝my.cnf到容器外修改完再覆盖容器原来的my.cnf文件 3.4重启mysql容器使配置文件生效 3.5查看是否

    2024年02月08日
    浏览(99)
  • 15年大牛用140多个实战案例深入讲解Java微服务架构实战:SpringBoot +SpringCloud +Docker +RabbitMQ

    第一部分,springboot篇; 第1章SpringBoot编程起步; 1.SpringBoot提倡的是一种简洁的开发模式,可保证用户不被大量的配置文件和依赖关系所困扰。 2.SpringBoot开发需要Maven或 Gradle构建工具支持。 3.SpringBoot使用一系列的注解来简化开发过程。 第2章SpringBoot程序开发; 1. SpringBoot的依赖

    2024年04月09日
    浏览(50)
  • MySQL主从复制案例实现

    使用Sharding-JDBC实现读写分离: 1、导入maven坐标 2、 在配置文件中配置读写分离规则 3、在配置文件中配置允许bean定义覆盖配置项 可以看到已经实现了读写分离了。

    2024年02月03日
    浏览(59)
  • 使用Docker构建的MySQL主从架构:高可用性数据库解决方案

    MySQL主从架构,我们已经在vmware虚拟机上实践过了,接下来我们一起探讨在docker中如何使用MySQL主从架构。 🏠个人主页:我是沐风晓月 🧑个人简介:大家好,我是沐风晓月,阿里云社区博客专家😉😉 💕 座右铭: 先努力成长自己,再帮助更多的人 ,一起加油进步🍺🍺🍺

    2024年02月08日
    浏览(87)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包