当前位置:网站首页>Canal ha mode configuration
Canal ha mode configuration
2022-06-12 09:56:00 【A pig without food】
Canal HA Mode configuration
Server side HA Mode configuration
canal It's supporting HA Of , In fact, the implementation mechanism also depends on zookeeper To achieve , The features used are watcher and EPHEMERAL node ( and session Life cycle binding ), And HDFS Of HA similar .
canal Of ha In two parts ,canal server and canal client There are corresponding ha Realization
- canal server: In order to reduce the mysql dump Request , Different server Upper instance( Different server The same on instance) You can only be at the same time running, The others are in standby state (standby yes instance The state of ).
- canal client: In order to ensure order , One copy instance Only one at a time canal client Conduct get/ack/rollback operation , Otherwise, the order of client receiving cannot be guaranteed .
Machine preparation
- function canal Machine : node1 , node2
- zookeeper The address is node1:2181,node2:2181,node3:2181
- mysql Address :node1:3306
Canal HA Server configuration
According to deployment and configuration , Complete the configuration on a single machine , Demonstration time instance name by example
modify canal.properties, add zookeeper To configure
canal.zkServers=node1:2181,node2,node3
canal.instance.global.spring.xml = classpath:spring/default-instance.xml
establish example Catalog , And modify it instance.properties
canal.instance.mysql.slaveId = 1234 ## The other machine is changed to 1235, Guarantee slaveId Don't repeat
canal.instance.master.address = node1:3306
Be careful : On two machines instance The names of the directories need to be exactly the same ,HA Patterns depend on instance name Conduct management , At the same time, we must all choose default-instance.xml To configure
Start the... Of both machines canal
-------
ssh node1
sh bin/startup.sh
--------
ssh node2
sh bin/startup.sh
After starting , You can see logs/example/example.log, You will only see a successful startup log on one machine .
For example, the successful startup here is node1
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...
Check it out. zookeeper Node information in , You can also know that the current working node is node1:11111
[zk: localhost:2181(CONNECTED) 15] get /otter/canal/destinations/example/running
{
"active":true,"address":"192.168.88.120:11111","cid":1}
Client link , Consumption data
1、 You can specify zookeeper Address and instance name,canal client Automatically from zookeeper Medium running node , Get the working node of the current service , And then build a link with it :
CanalConnector connector = CanalConnectors.newClusterConnector("node1:2181", "example", "canal", "canal");
2、 After the link is successful ,canal server Will record what is currently working canal client Information , For example, client ip, Port information of link etc
[zk: localhost:2181(CONNECTED) 17] get /otter/canal/destinations/example/1001/running
{
"active":true,"address":"192.168.88.1:60957","clientId":1001}
3、 After the success of data consumption ,canal server Will be in zookeeper The last successful consumption is recorded in binlog site . ( Next restart client when , Will continue to consume from this last point )
[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":"node1","port":3306}},"postion":{
"included":false,"journalName":"mysql-bin.000025","position":51944693,"serverId":1,"timestamp":1575424854000}}
Restart it canal server
Stop working node1 Of canal server
ssh node1
sh bin/stop.sh
At this time node2 It'll start right away example instance, Provide new data services
[zk: localhost:2181(CONNECTED) 19] get /otter/canal/destinations/example/running
{"active":true,"address":"192.168.88.121:11111","cid":1}
meanwhile , The client will follow canal server Handoff , By acquiring zookeeper The latest address in , With the new canal server Building links , Continue to consume data , The whole process is done automatically
Canal Server HA Flow chart of
- canal server To start something canal instance Always go first to zookeeper Make an attempt to start the judgment ( Realization : establish EPHEMERAL node , Whoever creates successfully will be allowed to start )
- establish zookeeper After node success , Corresponding canal server Start the corresponding canal instance, No successful canal instance Will be in standby state
- once zookeeper Find out canal server A After the created node disappears , Inform the others immediately canal server Step again 1 The operation of , Choose a new one canal server start-up instance.
- canal client Every time connect when , First of all zookeeper Ask who is currently starting canal instance, And then link to it , Once the link is not available , Will try again connect.
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-smQFGnoR-1613006260310)(F:/ Project video / Actual combat of shucang project - Dual real-time part / Real time data warehouse / Hundreds of billions of dollars of data warehouse 02 God /1. The notes /assets/image-20200214112119544.png)]
client HA Mode configuration
Canal Client And canal server Similar way , It's also the use of zookeeper To seize EPHEMERAL The way nodes control .
HA The implementation of the , The client is ClientRunningMonitor, The server is ServerRunningMonitor.
Take several directly Canal client , If it starts at the same time , Only one client can be accessed from Canal The server gets binlog news , Other clients cannot pull to binlog news .
From the run configuration , Copy the same configuration . Then start running .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-uN2GtWMl-1613006260312)(F:/ Project video / Actual combat of shucang project - Dual real-time part / Real time data warehouse / Hundreds of billions of dollars of data warehouse 02 God /1. The notes /assets/image-20191204100238491.png)]
Close the previous client , Then wait a little , Check whether another client can get binlog Log message .
Client1 Log :
****************************************************
* Batch Id: [3] ,count : [3] , memsize : [198] , Time : 2017-10-12 17:59:59
* Start : [mysql-bin.000004:1656:1507802398000(2017-10-12 17:59:58)]
* End : [mysql-bin.000004:1831:1507802398000(2017-10-12 17:59:58)]
****************************************************
================> binlog[mysql-bin.000004:1656] , executeTime : 1507802398000 , delay : 1188ms
BEGIN ----> Thread id: 768
----------------> binlog[mysql-bin.000004:1782] , name[canal_test,test] , eventType : UPDATE , executeTime : 1507802398000 , delay : 1199ms
uid : 1 type=int(4)
name : zqh type=varchar(10) update=true
----------------
END ----> transaction id: 0
================> binlog[mysql-bin.000004:1831] , executeTime : 1507802398000 , delay : 1236ms
## stop the canal client## canal client is down.
stop it Client1 after ,Client2 Log :
****************************************************
* Batch Id: [4] ,count : [3] , memsize : [198] , Time : 2017-10-12 18:02:15
* Start : [mysql-bin.000004:1906:1507802534000(2017-10-12 18:02:14)]
* End : [mysql-bin.000004:2081:1507802534000(2017-10-12 18:02:14)]
****************************************************
================> binlog[mysql-bin.000004:1906] , executeTime : 1507802534000 , delay : 1807ms
BEGIN ----> Thread id: 768
----------------> binlog[mysql-bin.000004:2032] , name[canal_test,test] , eventType : UPDATE , executeTime : 1507802534000 , delay : 1819ms
uid : 1 type=int(4)
name : zqhx type=varchar(10) update=true
----------------
END ----> transaction id: 0
================> binlog[mysql-bin.000004:2081] , executeTime : 1507802534000 , delay : 1855ms
Observe ZK In nodes instance Corresponding client node , stay Client When switching , Changes will be made .
For example, the following clients are from 56806 The port is switched to 56842 port .
Shut down all clients ,1001 Under no running. Express instance No client consumption binlog 了 .
Start two clients , The first client (56806) Running
[zk: 192.168.6.52:2181(CONNECTED) 29] get /otter/canal/destinations/example/1001/running
{"active":true,"address":"10.57.241.44:56806","clientId":1001}
Stop the first client , Delete node
[zk: 192.168.6.52:2181(CONNECTED) 30] get /otter/canal/destinations/example/1001/running
Node does not exist: /otter/canal/destinations/example/1001/running
The second client (56842) Become lord
[zk: 192.168.6.52:2181(CONNECTED) 31] get /otter/canal/destinations/example/1001/running
{"active":true,"address":"10.57.241.44:56842","clientId":1001}
[zk: 192.168.6.52:2181(CONNECTED) 32] ls /otter/canal/destinations/example/1001
[cursor]
The specific implementation related classes are :ClientRunningMonitor/ClientRunningListener/ClientRunningData.
client running Related control , Mainly to solve client Self failover Mechanism .
canal client It is allowed to start multiple at the same time canal client,
adopt running Mechanism , There is only one guarantee client at work , other client As a cold standby .
When in operation client Hang up ,running Control the cold standby client Switch to working mode ,
This will ensure that canal client It will not be a single point . Ensure the high availability of the whole system .
The left side of the figure below is the client side HA Realization , On the right is the server HA Realization
ilover Mechanism .
canal client It is allowed to start multiple at the same time canal client,
adopt running Mechanism , There is only one guarantee client at work , other client As a cold standby .
When in operation client Hang up ,running Control the cold standby client Switch to working mode ,
This will ensure that canal client It will not be a single point . Ensure the high availability of the whole system .
The left side of the figure below is the client side HA Realization , On the right is the server HA Realization
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-vDw20GjK-1613006260314)(F:/ Project video / Actual combat of shucang project - Dual real-time part / Real time data warehouse / Hundreds of billions of dollars of data warehouse 02 God /1. The notes /assets/image-20200214112840115.png)]
边栏推荐
- The Dragon Boat Festival is in good health -- people are becoming more and more important in my heart
- Principle analysis of mongodb storage engine wiredtiger
- redis学习记录:字典(dict)源码分析
- Clickhouse column basic data type description
- 软件定义存储概览(一篇就够)
- Japanese economic foam and house price foam
- How CEPH improves storage performance and storage stability
- Differences among list, set and map
- Chained hash table
- PandoraBox 使用防火墙规则定义非上网时间
猜你喜欢

True north reading notes

Strange error -- frame detected by contour detection, expansion corrosion, and reversal of opening and closing operation effect

优质好书助成长 猿辅导携四大出版社推荐“暑期好书”

榜样访谈——董宇航:在俱乐部中收获爱情

电阻的作用有哪些?(超全)

2026年中国软件定义存储市场容量将接近45.1亿美元

UE4_ Explore the method of creating background scenes with ready-made resources

Ceph如何改善存储性能以及提升存储稳定性

Differences among list, set and map

Transport layer protocol -- TCP protocol
随机推荐
[cloud native] what exactly does it mean? This article shares the answer with you
002:数据湖有哪些特征
Storage R & D Engineer Recruitment
Access and traversal of string class objects
SAP HANA 错误消息 SYS_XSA authentication failed SQLSTATE - 28000
Autojs learning notes 6:text (txt) Findone() will report an error when switching apps. Finally, solve the implementation effect and switch any app until the script finds the control with the specified
抽象类和接口
Record and store user video playback history selection
在线电路仿真以及开源电子硬件设计介绍
There is always a negative line (upper shadow line) that will stop the advance of many armies, and there is always a positive line (lower shadow line) that will stop the rampant bombing of the air for
Mysql5.7 partition table
markdown_ Picture side by side scheme
Difference between MySQL unreal reading and non repeatable reading
Transport layer protocol -- TCP protocol
003:AWS认为什么是数据湖?
Implementation of hotspot synchronized
Introduction to applet
硬盘 SMART 检测参数详解
MySQL索引常见问题
Golandidea 2020.01 cracked version