zoukankan      html  css  js  c++  java
  • canal HA配置

    https://github.com/alibaba/canal/wiki/AdminGuide#ha%E6%A8%A1%E5%BC%8F%E9%85%8D%E7%BD%AE

     

    HA模式配置

    1. 机器准备

    a. 运行canal的机器: 10.20.144.22 , 10.20.144.51.

    b. zookeeper地址为10.20.144.51:2181

    c. mysql地址:10.20.144.15:3306

    2. 按照部署和配置,在单台机器上各自完成配置,演示时instance name为example

    a. 修改canal.properties,加上zookeeper配置

    canal.zkServers=10.20.144.51:2181
    canal.instance.global.spring.xml = classpath:spring/default-instance.xml

    b. 创建example目录,并修改instance.properties

    canal.instance.mysql.slaveId = 1234 ##另外一台机器改成1235,保证slaveId不重复即可
    canal.instance.master.address = 10.20.144.15:3306

    注意: 两台机器上的instance目录的名字需要保证完全一致,HA模式是依赖于instance name进行管理,同时必须都选择default-instance.xml配置

    3. 启动两台机器的canal

    -------
    ssh 10.20.144.51
    sh bin/startup.sh
    --------
    ssh 10.20.144.22
    sh bin/startup.sh

    启动后,你可以查看logs/example/example.log,只会看到一台机器上出现了启动成功的日志。

    比如我这里启动成功的是10.20.144.51

    2013-03-19 18:18:20.590 [main] INFO  c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [canal.properties]
    2013-03-19 18:18:20.596 [main] INFO  c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [example/instance.properties]
    2013-03-19 18:18:20.831 [main] INFO  c.a.otter.canal.instance.spring.CanalInstanceWithSpring - start CannalInstance for 1-example 
    2013-03-19 18:18:20.845 [main] INFO  c.a.otter.canal.instance.spring.CanalInstanceWithSpring - start successful...

    查看一下zookeeper中的节点信息,也可以知道当前工作的节点为10.20.144.51:11111

    [zk: localhost:2181(CONNECTED) 15] get /otter/canal/destinations/example/running  
    {"active":true,"address":"10.20.144.51:11111","cid":1}

    4. 客户端链接, 消费数据

    a. 可以直接指定zookeeper地址和instance name,canal client会自动从zookeeper中的running节点,获取当前服务的工作节点,然后与其建立链接:

    CanalConnector connector = CanalConnectors.newClusterConnector("10.20.144.51:2181", "example", "", "");

    b. 链接成功后,canal server会记录当前正在工作的canal client信息,比如客户端ip,链接的端口信息等 (聪明的你,应该也可以发现,canal client也可以支持HA功能)

    [zk: localhost:2181(CONNECTED) 17] get /otter/canal/destinations/example/1001/running
    {"active":true,"address":"10.12.48.171:50544","clientId":1001}

    c. 数据消费成功后,canal server会在zookeeper中记录下当前最后一次消费成功的binlog位点. (下次你重启client时,会从这最后一个位点继续进行消费)

    [zk: localhost:2181(CONNECTED) 16] get /otter/canal/destinations/example/1001/cursor
    {"@type":"com.alibaba.otter.canal.protocol.position.LogPosition","identity":{"slaveId":-1,"sourceAddress":{"address":"10.20.144.15","port":3306}},"postion":{"included":false,"journalName":"mysql-bin.002253","position":2574756,"timestamp":1363688722000}}
    

    5. 重启一下canal server

    停止正在工作的10.20.144.51的canal server

    ssh 10.20.144.51 
    sh bin/stop.sh

    这时10.20.144.22会立马启动example instance,提供新的数据服务

    [zk: localhost:2181(CONNECTED) 19] get /otter/canal/destinations/example/running
    {"active":true,"address":"10.20.144.22:11111","cid":1}
    

    与此同时,客户端也会随着canal server的切换,通过获取zookeeper中的最新地址,与新的canal server建立链接,继续消费数据,整个过程自动完成

    触发HA自动切换场景 (server/client HA模式都有效)

    1. 正常场景

       a. 正常关闭canal server(会释放instance的所有资源,包括删除running节点)

       b. 平滑切换(gracefully)

    操作:更新对应instance的running节点内容,将"active"设置为false,对应的running节点收到消息后,会主动释放running节点,让出控制权但自己jvm不退出,gracefully.

    {"active":false,"address":"10.20.144.22:11111","cid":1}

    2. 异常场景

       a. canal server对应的jvm异常crash,running节点的释放会在对应的zookeeper session失效后,释放running节点(EPHEMERAL节点)

    ps. session过期时间默认为zookeeper配置文件中定义的tickTime的20倍,如果不改动zookeeper配置,那默认就是40秒

       b. canal server所在的网络出现闪断,导致zookeeper认为session失效,释放了running节点,此时canal server对应的jvm并未退出,(一种假死状态,非常特殊的情况)

    ps. 为了保护假死状态的canal server,避免因瞬间runing失效导致instance重新分布,所以做了一个策略:canal server在收到running节点释放后,延迟一段时间抢占running,原本running节点的拥有者可以不需要等待延迟,优先取得running节点,可以保证假死状态下尽可能不无谓的释放资源。 目前延迟时间的默认值为5秒,即running节点针对假死状态的保护期为5秒.

    mysql多节点解析配置(parse解析自动切换)

    1. mysql机器准备

    准备两台mysql机器,配置为M-M模式,比如ip为:10.20.144.25:3306,10.20.144.29:3306

    [mysqld] 
    xxxxx ##其他正常master/slave配置
    log_slave_updates=true ##这个配置一定要打开

    2. canal instance配置

    # position info
    canal.instance.master.address = 10.20.144.25:3306
    canal.instance.master.journal.name = 
    canal.instance.master.position = 
    canal.instance.master.timestamp =

    canal.instance.standby.address = 10.20.144.29:3306 canal.instance.standby.journal.name = canal.instance.standby.position = canal.instance.standby.timestamp =

    detecing config

    canal.instance.detecting.enable = true ## 需要开启心跳检查 canal.instance.detecting.sql = insert into retl.xdual values(1,now()) on duplicate key update x=now() ##心跳检查sql,也可以选择类似select 1的query语句 canal.instance.detecting.interval.time = 3 ##心跳检查频率 canal.instance.detecting.retry.threshold = 3 ## 心跳检查失败次数阀值,超过该阀值后会触发mysql链接切换,比如切换到standby机器上继续消费binlog canal.instance.detecting.heartbeatHaEnable = true ## 心跳检查超过失败次数阀值后,是否开启master/standby的切换.

    注意:

    a. 填写master/standby的地址和各自的起始binlog位置,目前配置只支持一个standby配置.

    b. 发生master/standby的切换的条件:(heartbeatHaEnable = true) && (失败次数>=retry.threshold).

    c. 多引入一个heartbeatHaEnable的考虑:开启心跳sql有时候是为client检测canal server是否正常工作,如果定时收到了心跳语句,那说明整个canal server工作正常

    3. 启动 & 测试

    比如关闭一台机器的mysql , /etc/init.d/mysql stop 。在经历大概 interval.time * retry.threshold时间后,就会切换到standby机器上

  • 相关阅读:
    Memcached下载安装和使用
    PHP curl拓展的介绍和使用
    理解PHP面向对象三大特性
    empty()、isset()、is_null()的区别
    ThinkPHP无法打开或点击不了Trace的问题
    jQuery实现动态时间
    jQuery中$.get()和$.post()的异同点
    jQuery中attr()和prop()及removeAttr()和removeProp()的区别
    Windows10测试低版本IE方法
    apache 2.2 和 2.4 访问控制区别 (require 替代 deny)
  • 原文地址:https://www.cnblogs.com/eason-d/p/9300767.html
Copyright © 2011-2022 走看看