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
#擴(kuò)展監(jiān)控手機(jī)
mobiles:
#擴(kuò)展訂閱
subscribe: seata_order.t_order,seata_order.Test
# mqServers: 127.0.0.1:9092 #or rocketmq
# flatMessage: true
batchSize: 500
syncBatchSize: 1000
#錯誤重試次數(shù)
retries: 3
timeout:
accessKey:
secretKey:
srcDataSources:
defaultDS:
#源數(shù)據(jù)地址
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 #可配置多個目標(biāo)數(shù)據(jù)庫
# 在所有目標(biāo)端的同步中key是一個必須要配置的參數(shù),不配置可能會出現(xiàn)數(shù)據(jù)丟失的問題
key: mysql1
properties:
jdbc.driverClassName: com.mysql.jdbc.Driver
#目標(biāo)數(shù)據(jù)庫地址
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
# 在所有目標(biāo)端的同步中outerAdapterKey是一個必須要配置的參數(shù),不配置可能會出現(xiàn)數(shù)據(jù)丟失的問題
# 對應(yīng)application.yml中key字段
outerAdapterKey: mysql1
concurrent: true
dbMapping:
#master數(shù)據(jù)庫
database: mytest
table: user
#目標(biāo)數(shù)據(jù)庫表
targetTable: mytest2.user
targetPk: #主鍵映射
id: id #復(fù)合主鍵可以映射多個
# 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
源碼導(dǎo)入到IDEA中的結(jié)構(gòu)如下

image.png
修改源碼后編譯打包

image.png