1、下载 canal adapter
wget https://github.com/alibaba/canal/releases/download/canal-1.1.4/canal.adapter-1.1.4.tar.gz
https://github.com/alibaba/canal/wiki/ClientAdapter
2、安装canal adapter
mkdir /yourpath/soft/canal.adapter-1.1.4
tar zxvf canal.adapter-1.1.4.tar.gz -C /yourpath/soft/canal.adapter-1.1.4
编辑application.yml
server:
port: 8081
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
default-property-inclusion: non_null
canal.conf:
mode: tcp # kafka rocketMQ
# canalServerHost: 127.0.0.1:11111
#HA ZK
zookeeperHosts: 192.168.1.111:2181
#扩展监控手机
mobiles:
#扩展订阅
subscribe: seata_order.t_order,seata_order.Test
# mqServers: 127.0.0.1:9092 #or rocketmq
# flatMessage: true
batchSize: 500
syncBatchSize: 1000
#错误重试次数
retries: 3
timeout:
accessKey:
secretKey:
srcDataSources:
defaultDS:
#源数据地址
url: jdbc:mysql://192.168.1.115:3306/seata_order?useUnicode=true
username: root
password: 123456
canalAdapters: #可配置多个实例
- instance: example # canal instance Name or mq topic name
groups:
- groupId: g1
outerAdapters:
- name: logger
- name: rdb #可配置多个目标数据库
# 在所有目标端的同步中key是一个必须要配置的参数,不配置可能会出现数据丢失的问题
key: mysql1
properties:
jdbc.driverClassName: com.mysql.jdbc.Driver
#目标数据库地址
jdbc.url: jdbc:mysql://192.168.1.115:3306/seata_account?useUnicode=true
jdbc.username: root
jdbc.password: 123456
# - name: rdb
# key: oracle1
# properties:
# jdbc.driverClassName: oracle.jdbc.OracleDriver
# jdbc.url: jdbc:oracle:thin:@localhost:49161:XE
# jdbc.username: mytest
# jdbc.password: m121212
# - name: rdb
# key: postgres1
# properties:
# jdbc.driverClassName: org.postgresql.Driver
# jdbc.url: jdbc:postgresql://localhost:5432/postgres
# jdbc.username: postgres
# jdbc.password: 121212
# threads: 1
# commitSize: 3000
# hbase
# - name: hbase
# properties:
# hbase.zookeeper.quorum: 127.0.0.1
# hbase.zookeeper.property.clientPort: 2181
# zookeeper.znode.parent: /hbase
# es
# - name: es
# hosts: 127.0.0.1:9300 # 127.0.0.1:9200 for rest mode
# properties:
# mode: transport # or rest
# # security.auth: test:123456 # only used for rest mode
# cluster.name: elasticsearch
配置rdb目录下面表的映射文件
dataSourceKey: defaultDS
destination: example
groupId: g1
# 在所有目标端的同步中outerAdapterKey是一个必须要配置的参数,不配置可能会出现数据丢失的问题
# 对应application.yml中key字段
outerAdapterKey: mysql1
concurrent: true
dbMapping:
#master数据库
database: mytest
table: user
#目标数据库表
targetTable: mytest2.user
targetPk: #主键映射
id: id #复合主键可以映射多个
# mapAll: true #字段完全一样可以打开
targetColumns: #字段映射
id:
name:
role_id:
c_time:
test1:
etlCondition: "where c_time>={}"
commitBatch: 3000 # 批量提交的大小
## Mirror schema synchronize config
#dataSourceKey: defaultDS
#destination: example
#groupId: g1
#outerAdapterKey: mysql1
#concurrent: true
#dbMapping:
# mirrorDb: true
# database: mytest
启动canal.adapter : ./startup.sh
Canal-Adapter源码在IDEA部署运行
下载地址:https://github.com/alibaba/canal
源码导入到IDEA中的结构如下
修改源码后编译打包