1. Usage scenarios
- canal deployer is a canal standard package, which can be regarded as a canal server . It is responsible for masquerading as a mysql slave library, receiving, parsing binlog and delivering it to the specified target ( RDS , MQ or canal adapter )
- The canal adapter is a canal client, which can be regarded as a canal client . Among them, RDB includes Oracle , MySQL , PostgreSQL , SQLServer and other databases
2. Detailed explanation of canal deployer package parameters
2.1. canal deployer package directory structure
tree canal expand source code
- bin - store start, restart, stop scripts
- conf - configuration file directory
- lib - store library files, no need to operate this directory
- logs - storage log directory
2.2. conf directory
tree canal conf expand source code
- canal.properties - canal program main configuration file
argument |
illustrate |
Defaults |
example (--to keep the default) |
canal.ip |
The local IP information bound to the canal server . If not configured, a local IP is selected by default to start the service |
none |
|
canal.register.ip |
The ip registered by the canal server to the zk cluster |
none |
|
canal.port |
The port where the canal server provides socket services |
11111 |
-- |
canal.metrics.pull.port |
Monitoring interface port (used with Prometheus) |
11112 |
-- |
canal.admin.port |
Access port for canal admin |
11110 |
-- |
canal.admin.user |
Canal admin login user |
admin |
-- |
canal.admin.passwd |
Canal admin login user password |
-- |
|
canal.zkServers |
zookeeper server cluster address |
-- |
|
canal.zookeeper.flush.period |
The update frequency of canal persistent data to zookeeper, in milliseconds |
1000 |
-- |
canal.withoutNetty |
Whether to close the netty service on the server side |
false |
-- |
canal.serverMode |
tcp: The client pulls incremental data from the Canal server through tcp Kafka: The Canal server synchronizes incremental data to Kafka, and the client consumes data from Kafka. At this time, the client cannot perceive the existence of Canal, and only needs to interact with Kafka RocketMQ: Same as kafka, incremental data is synchronized to RocketMQ |
tcp |
-- |
canal.file.data.dir |
flush meta cursor/parse position to file . Record the consumption site to the file, when using the spring/file-instance.xml configuration file |
${canal.conf.dir} |
-- |
canal.file.flush.period |
The update frequency of canal persistent data to the file, in milliseconds |
1000 |
-- |
canal.instance.memory.buffer.size |
The number of cacheable buffer records in the canal memory store, which needs to be an index of 2 |
16384 |
-- |
canal.instance.memory.buffer.memunit |
The unit size of the memory record, the default is 1KB, and the combination of buffer.size determines the final memory usage size |
1024 |
-- |
canal.instance.memory.batch.mode |
Data cache mode in canal memory store |
MEMSIZE |
-- |
canal.instance.memory.rawEntry |
batch.mode related parameters, the default is fine |
true |
-- |
canal.instance.detecting.enable |
Whether to enable heartbeat check |
false |
-- |
canal.instance.detecting.sql |
heartbeat check sql |
select 1 |
-- |
canal.instance.detecting.interval.time |
Heartbeat check frequency, in seconds |
3 |
-- |
canal.instance.detecting.retry.threshold |
心跳检查失败重试次数 |
3 |
-- |
canal.instance.detecting.heartbeatHaEnable |
心跳检查失败后,是否开启自动mysql自动切换 |
false |
-- |
canal.instance.transaction.size |
最大事务完整解析的长度支持。超过该长度后,一个事务可能会被拆分成多次提交到canal store中,无法保证事务的完整可见性 |
1024 |
-- |
canal.instance.fallbackIntervalInSeconds |
canal发生mysql切换时,在新的mysql库上查找binlog时需要往前查找的时间,单位秒 |
60 |
-- |
canal.instance.network.receiveBufferSize |
网络链接参数,SocketOptions.SO_RCVBUF |
16384 |
-- |
canal.instance.network.sendBufferSize |
网络链接参数,SocketOptions.SO_SNDBUF |
16384 |
-- |
canal.instance.network.soTimeout |
网络链接参数,SocketOptions.SO_TIMEOUT |
30 |
-- |
canal.instance.filter.druid.ddl |
是否使用druid处理所有的ddl解析来获取库和表名 |
true |
-- |
canal.instance.filter.query.dcl |
是否忽略dcl语句 |
false |
-- |
canal.instance.filter.query.dml |
是否忽略dml语句 |
false |
-- |
canal.instance.filter.query.ddl |
是否忽略ddl语句 |
false |
-- |
canal.instance.filter.table.error |
是否忽略binlog表结构获取失败的异常 |
false |
-- |
canal.instance.filter.rows |
是否忽略dml的数据变更事件 |
false |
-- |
canal.instance.filter.transaction.entry |
是否忽略事务头和尾,比如针对写入kakfa的消息时,不需要写入TransactionBegin/Transactionend事件 |
false |
-- |
canal.instance.binlog.format |
支持的binlog/format格式列表 |
ROW,STATEMENT,MIXED |
-- |
canal.instance.binlog.image |
支持的binlog/image格式列表 |
FULL,MINIMAL,NOBLOB |
-- |
canal.instance.get.ddl.isolation |
ddl语句是否单独一个batch返回 |
false |
-- |
canal.instance.parser.parallel |
是否开启binlog并行解析模式 |
true |
-- |
canal.instance.parser.parallelBufferSize |
binlog并行解析的异步ringbuffer队列 |
256 |
-- |
canal.instance.tsdb.enable |
是否开启tablemeta的 tsdb 功能 |
true |
false |
canal.instance.tsdb.dir |
主要针对h2-tsdb.xml时对应h2文件的存放目录,默认为conf/xx/h2.mv.db |
[Math Processing Error]�����.����.����.���:../����/{canal.instance.destination:} |
-- |
canal.instance.tsdb.url |
jdbc url的配置 |
jdbc:h2:${canal.instance.tsdb.dir}/h2;CACHE_SIZE=1000;MODE=MYSQL; |
-- |
canal.instance.tsdb.dbUsername |
tsdb用户名 |
canal |
-- |
canal.instance.tsdb.dbPassword |
tsdb密码 |
canal |
-- |
canal.instance.tsdb.snapshot.interval |
导出快照间隔,默认24小时 |
24 |
-- |
canal.instance.tsdb.snapshot.expire |
清理快照时间间隔,默认360小时 |
360 |
-- |
canal.aliyun.accessKey |
阿里云 access key(如果不需要在本地binlog超过18小时被清理后自动下载oss上的binlog,可以忽略该值) |
无 |
-- |
canal.aliyun.secretKey |
阿里云 secret key(如果不需要在本地binlog超过18小时被清理后自动下载oss上的binlog,可以忽略该值) |
无 |
-- |
- logback.xml —— 日志功能配置文件,一般不用修改
- metrics —— 监控项配置文件目录
- spring —— spring 框架配置文件目录,其中 *-instance.xml 文件用于指定 binlog 的位点信息存放于文件、内存、zk 等位置
- default-instance.xml: store选择了内存模式,其余的parser/sink依赖的位点管理选择了持久化模式,目前持久化的方式主要是写入zookeeper,保证数据集群共享。
- 特点:支持HA
- 场景:生产环境,集群化部署.
- memory-instance.xml:所有的组件(parser , sink , store)都选择了内存版模式,记录位点的都选择了memory模式,重启后又会回到初始位点进行解析。
- 特点:速度最快,依赖最少(不需要zookeeper)
- 场景:一般应用在quickstart,或者是出现问题后,进行数据分析的场景,不应该将其应用于生产环境
- group-instance.xml:主要针对需要进行多库合并时,可以将多个物理instance合并为一个逻辑instance,提供客户端访问。
- file-instance.xml:store选择了内存模式,其余的parser/sink依赖的位点管理选择了持久化模式,目前持久化的方式主要是写入文件,文件位置在instance目录下meta.dat,当前Canal节点重启会从该文件读取解析位置,无法在数据集群共享。
- default-instance.xml: store选择了内存模式,其余的parser/sink依赖的位点管理选择了持久化模式,目前持久化的方式主要是写入zookeeper,保证数据集群共享。
- mid_db —— 为 canal 实例配置文件,主要配置 mysql binlog 的起始位置、表过滤、MQ 目标 topic 等信息
2.3. canal.properties 文件详解
- canal.properties 文件分为了4大部分
- common argument
- destinations
- MQ
- Kafka Kerberos Info
2.3.1. common argument 部分
2.3.2. destinations 部分
argument |
说明 |
默认值 |
示例 |
canal.destinations |
当前server上部署的instance列表,多个实例用逗号分隔 |
无 |
mysql_mysql |
canal.conf.dir |
conf 目录所在的路径 |
../conf |
-- |
canal.auto.scan |
开启instance自动扫描 |
true |
-- |
canal.auto.scan.interval |
instance自动扫描的间隔时间,单位秒 |
5 |
-- |
canal.instance.tsdb.spring.xml |
tsdb 的 xml 配置文件 |
classpath:spring/tsdb/h2-tsdb.xml |
-- |
canal.instance.global.mode |
全局配置加载方式 |
spring |
-- |
canal.instance.global.lazy |
全局lazy模式 |
false |
-- |
canal.instance.global.manager.address |
全局的manager配置方式的连接信息 |
${canal.admin.manager} |
-- |
canal.instance.global.spring.xml |
全局的spring配置方式的组件文件,连接 zk 使用 default 文件 |
classpath:spring/file-instance.xml |
classpath:spring/default-instance.xml |
2.3.3. MQ 部分
argument |
说明 |
默认值 |
示例 |
canal.mq.servers |
kafka为bootstrap.servers |
127.0.0.1:6667 |
-- |
canal.mq.retries |
发送失败重试次数 |
0 |
-- |
canal.mq.batchSize |
kafka为ProducerConfig.BATCH_SIZE_CONFIG |
16384 |
-- |
canal.mq.maxRequestSize |
kafka为ProducerConfig.MAX_REQUEST_SIZE_CONFIG |
1048576 |
-- |
canal.mq.lingerMs |
kafka为ProducerConfig.LINGER_MS_CONFIG , 如果是flatMessage格式建议将该值调大, 如: 200 |
100 |
-- |
canal.mq.bufferMemory |
kafka为ProducerConfig.BUFFER_MEMORY_CONFIG |
33554432 |
-- |
canal.mq.canalBatchSize |
Canal的batch size, 默认50K, 由于kafka最大消息体限制请勿超过1M(900K以下) |
50 |
-- |
canal.mq.canalGetTimeout |
Canal get数据的超时时间, 单位: 毫秒, 空为不限超时 |
100 |
-- |
canal.mq.flatMessage |
是否为flat json格式对象 |
true |
-- |
canal.mq.compressionType |
压缩类型 |
none |
-- |
canal.mq.acks |
kafka为ProducerConfig.ACKS_CONFIG |
all |
-- |
canal.mq.producerGroup |
kafka无意义 |
Canal-Producer |
-- |
canal.mq.accessChannel |
kafka无意义 |
local |
-- |
2.3.4. Kafka Kerberos Info 部分
argument |
说明 |
默认值 |
示例(--为保持默认) |
canal.mq.kafka.kerberos.enable |
kafka为ProducerConfig.ACKS_CONFIG |
false |
-- |
canal.mq.kafka.kerberos.krb5FilePath |
kafka kerberos认证 |
"../conf/kerberos/krb5.conf" |
-- |
canal.mq.kafka.kerberos.jaasFilePath |
kafka kerberos认证 |
"../conf/kerberos/jaas.conf" |
-- |