首页 > 其他分享 >Canal:ZooKeeper进行集群管理

Canal:ZooKeeper进行集群管理

时间:2022-11-09 19:03:04浏览次数:44  
标签:Canal canal zookeeper ZooKeeper server instance 集群 root


集成ZooKeeper

前期回顾:

  • ​​Canal:部署Canal与Canal Admin​​

搭建​​ZooKeeper​​可以参考下面这几篇博客:

  • ​​ZooKeeper :Shell脚本搭建单机版ZooKeeper​​
  • ​​ZooKeeper :搭建ZooKeeper集群​​
  • ​​ZooKeeper :Nginx基于TCP协议代理ZooKeeper集群​​

启动​​ZooKeeper​​并且关闭防火墙。

[root@localhost ~]# cd /usr/local/apache-zookeeper-3.6.3-bin/
[root@localhost apache-zookeeper-3.6.3-bin]# sh bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost apache-zookeeper-3.6.3-bin]# sh bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
Client port found: 9000. Client address: localhost. Client SSL: false.
Mode: standalone
[root@localhost apache-zookeeper-3.6.3-bin]# systemctl stop firewalld

在​​Canal Admin​​​上添加集群,集群名称为​​zookeeper​​。

Canal:ZooKeeper进行集群管理_linux


修改​​zookeeper​​集群的主配置。

Canal:ZooKeeper进行集群管理_linux_02


主要是添加​​ZooKeeper​​服务地址。

Canal:ZooKeeper进行集群管理_apache_03


在​​zookeeper​​​集群下创建​​server​​​(博主把之前创建的​​instance​​​和​​server​​​都删除了,因为​​server​​不能修改所属集群配置,只能删除再重新创建)。

Canal:ZooKeeper进行集群管理_linux_04


创建​​kaven server​​成功,状态为启动。

Canal:ZooKeeper进行集群管理_linux_05


在​​zookeeper​​​集群下创建​​instance​​。

Canal:ZooKeeper进行集群管理_云原生_06


由下图所示,​​itkaven instance​​​由​​zookeeper​​​集群下的​​kaven server​​运行,状态也是启动。

Canal:ZooKeeper进行集群管理_单机版_07


查看​​itkaven instance​​的日志,很显然启动成功了。

Canal:ZooKeeper进行集群管理_linux_08


因为​​zookeeper​​​集群下只有一个​​server​​​,即​​kaven server​​​,因此​​itkaven instance​​​肯定是在​​kaven server​​​上运行的。查看​​Canal​​​项目(​​zookeeper​​​集群下唯一的​​server​​​)的日志文件和配置文件即可发现​​itkaven instance​​的相关文件:

[root@localhost canal-server]# ll logs
总用量 0
drwxr-xr-x. 2 root root 47 12月 14 15:27 canal
drwxr-xr-x. 2 root root 25 12月 14 15:20 example
drwxr-xr-x. 2 root root 25 12月 14 16:26 itkaven
drwxr-xr-x. 2 root root 23 12月 14 15:34 other
[root@localhost canal-server]# ll conf
总用量 16
-rwxrwxrwx. 1 root root 319 4月 19 2021 canal_local.properties
-rwxrwxrwx. 1 root root 6277 4月 19 2021 canal.properties
drwxrwxrwx. 2 root root 65 12月 14 16:05 example
drwxr-xr-x. 2 root root 38 12月 14 16:27 itkaven
-rwxrwxrwx. 1 root root 3437 4月 19 2021 logback.xml
drwxrwxrwx. 2 root root 39 12月 13 23:02 metrics
drwxr-xr-x. 2 root root 38 12月 14 15:36 other
drwxrwxrwx. 3 root root 149 12月 13 23:02 spring

​ZooKeeper​​​中也会保存一些数据(比如集群下的所有​​server​​​和​​instance​​​信息,以及​​instance​​​在哪个​​server​​上运行)。

[root@localhost apache-zookeeper-3.6.3-bin]# sh bin/zkCli.sh -timeout 5000 -server 127.0.0.1:9000
[zk: 127.0.0.1:9000(CONNECTED) 0] ls -R /otter
/otter
/otter/canal
/otter/canal/cluster
/otter/canal/destinations
/otter/canal/cluster/192.168.1.199:11111
/otter/canal/destinations/itkaven
/otter/canal/destinations/itkaven/cluster
/otter/canal/destinations/itkaven/running
/otter/canal/destinations/itkaven/cluster/192.168.1.199:11111
[zk: 127.0.0.1:9000(CONNECTED) 1] get /otter/canal/destinations/itkaven/running
{"active":true,"address":"192.168.1.199:11111"}

HA机制设计

​canal​​​的​​HA​​​分为两部分,​​canal server​​​和​​canal client​​​分别有对应的​​HA​​实现:

  • ​canal server​​​: 为了减少对​​mysql dump​​​的请求,不同​​server​​​上的​​instance​​​要求同一时间只能有一个处于​​running​​​,其他的处于​​standby​​状态。
  • ​canal client​​​: 为了保证有序性,一个​​instance​​​同一时间只能由一个​​canal client​​​进行​​get/ack/rollback​​操作,否则客户端接收无法保证有序。

整个​​HA​​​机制的控制主要是依赖了​​ZooKeeper​​​的几个特性,​​watcher​​​和​​EPHEMERAL​​​节点(和​​session​​生命周期绑定)。

  • ​​ZooKeeper :重要概念​​

大致步骤:

  1. ​canal server​​​要启动某个​​canal instance​​​时,都先向​​ZooKeeper​​​进行一次尝试启动判断 (创建​​EPHEMERAL​​节点,谁创建成功就允许谁启动)。
  2. 创建​​ZooKeeper​​​节点成功后,该​​canal server​​​就启动对应的​​canal instance​​​,没有创建成功的​​canal instance​​​就会处于​​standby​​状态。
  3. 一旦​​ZooKeeper​​​发现​​canal server​​​ 创建的节点消失后,立即通知其他的​​canal server​​​再次进行步骤​​1​​​的操作,重新选出一个​​canal server​​​启动​​canal instance​​。
  4. ​canal client​​​每次进行​​connect​​​时,会首先向​​ZooKeeper​​​询问当前是谁启动了​​canal instance​​​,然后和其建立连接,一旦连接不可用,会重新尝试​​connect​​。

​canal client​​​的方式和​​canal server​​​的方式类似,也是利用​​ZooKeeper​​​抢占​​EPHEMERAL​​节点的方式进行控制。

使用​​ZooKeeper​​进行集群管理就介绍到这里,如果博主有说错的地方或者大家有不同的见解,欢迎大家评论补充。


标签:Canal,canal,zookeeper,ZooKeeper,server,instance,集群,root
From: https://blog.51cto.com/u_15870611/5838296

相关文章

  • 1 zookeeper介绍
     https://mirror.bit.edu.cn/apache/zookeeper/https://www.cnblogs.com/sakura-yxf/p/12020348.html 1Zookeeper集群的角色:Leader和follower(Observer) 只要集群......
  • 2 zookeeper安装
    zookeeper包下载:https://mirror.bit.edu.cn/apache/zookeeper/1下载解压,修改配置zookeeper下载:http://archive.apache.org/dist/zookeeper/https://www.aboutyun.co......
  • Kubernetes集群YAML文件简介
    概述k8s集群中对资源管理和资源对象编排部署都可以通过声明样式(YAML)文件来解决,也就是可以把需要对资源对象操作编辑到YAML格式文件中,我们把这种文件叫做资源清单文件,通......
  • Kubernetes集群管理工具kubectl简介
     概述kubectl是Kubernetes集群的命令行工具,通过kubectl能够对集群本身进行管理,并能够在集群上进行容器化应用的安装和部署 命令格式kubectl[command][type][na......
  • zookeeper启动闪退问题
    在配置zookeeper集群时,遇到启动zookeeper后几秒就闪退经过一系列疯狂查找后解决问题方法一:在zookeeper的配置文件zoo.cfg中在/zkData/installed里面查找zookeeper_serv......
  • ZooKeeper系列:实现分布式锁
    锁是为了在多线程的场景中保证数据安全而增加的一种手段,Java中常用的有CountdownLatch,ReentrantLock等单应用中的锁,在现在处处都是分布式的场景需求下就不能满足了,所以就出......
  • 使用kubeadm方式搭建K8S集群
     kubeadm是官方社区推出的一个用于快速部署kubernetes集群的工具。这个工具能通过两条指令完成一个kubernetes集群的部署:#创建一个Master节点kubeadminit#将一......
  • 快速搭建Jenkins集群
    欢迎访问我的GitHub这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos关于Jenkins集群在Jenkins上同时执行多个任务时,单机性能可能达......
  • mycat负载均衡集群
    1.haproxy负载均衡搭建与介绍在网站创立初期,我们一般都使用单台机器对台提供集中式服务,但随着业务量越来越大,无论性能还是稳定性上都有了更大的挑战。这时候我们就会想到......
  • mycat2 安装、分库分表、以及集群的搭建
    搭建双主双从 一个主机m1用于处理所有写请求,它的从机s1和另一台主机m2还有它的从机s2负责所有读请求。当m1主机宕机后,m2主机负责写请求,m1、m2互为备机。......