ataSourceKey: defaultDS #无需修改
destination: example #这个对应application.yml文件中的
groupId: g1
outerAdapterKey: mysql1
concurrent: true # 并行同步的表必须保证主键不会更改及主键不能为其他同步表的外键
dbMapping:
mirrorDb: true
database: epidemic #需要同步的数据库名,两台服务器的数据库名最好命名成一样的,不然可能有各种意外情况发生
table: user #需要同步的表名
targetTable: user #同步到目标服务器对应的表名
targetPk:
id: id # 主键,格式为, 源表主键名:目标表主键名
mapAll: true # 映射所有字段,这里改为true的话,下面的targetColumns就可以不用改了,除非两边的数据结构不一样
# targetColumns: #如果字段名称不一样时,前面时目标表字段名称后面时源数据表字段名称
# id:
# name:
# role_id:
# c_time:
# test1:
# etlCondition: "where c_time>={}"
commitBatch: 3000 # 批量提交的大小,保持不动即可
1. deployer配置
instance.properties文件
#################################################
## mysql serverId , v1.0.26+ will autoGen
# canal.instance.mysql.slaveId=0
# enable gtid use true/false
canal.instance.gtidon=false
# position info
canal.instance.master.address=这里填写源数据库的ip:端口
canal.instance.master.journal.name=
canal.instance.master.position=
canal.instance.master.timestamp=
canal.instance.master.gtid=
# rds oss binlog
canal.instance.rds.accesskey=
canal.instance.rds.secretkey=
canal.instance.rds.instanceId=
# table meta tsdb info
canal.instance.tsdb.enable=true
#canal.instance.tsdb.url=jdbc:mysql://127.0.0.1:3306/canal_tsdb
#canal.instance.tsdb.dbUsername=canal
#canal.instance.tsdb.dbPassword=canal
#canal.instance.standby.address =
#canal.instance.standby.journal.name =
#canal.instance.standby.position =
#canal.instance.standby.timestamp =
#canal.instance.standby.gtid=
# username/password
canal.instance.dbUsername=填写源数据库用户名,例:root
canal.instance.dbPassword=填写源数据库密码,例:root
canal.instance.connectionCharset = UTF-8
# enable druid Decrypt database password
canal.instance.enableDruid=false
#canal.instance.pwdPublicKey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALK4BUxdDltRRE5/zXpVEVPUgunvscYFtEip3pmLlhrWpacX7y7GCMo2/JM6LeHmiiNdH1FWgGCpUfircSwlWKUCAwEAAQ==
# table regex
canal.instance.filter.regex=这里填写需要进行同步的数据库表名,格式:数据库名.表名,多个表用逗号分分隔,例如:testdb.user,testdb.role,testdb.menu
# table black regex
canal.instance.filter.black.regex=mysql\\.slave_.*
# table field filter(format: schema1.tableName1:field1/field2,schema2.tableName2:field1/field2)
#canal.instance.filter.field=test1.t_product:id/subject/keywords,test2.t_company:id/name/contact/ch
# table field black filter(format: schema1.tableName1:field1/field2,schema2.tableName2:field1/field2)
#canal.instance.filter.black.field=test1.t_product:subject/product_image,test2.t_company:id/name/contact/ch
# table field black filter(format: schema1.tableName1:field1/field2,schema2.tableName2:field1/field2)
#canal.instance.filter.black.field=test1.t_product:subject/product_image,test2.t_company:id/name/contact/ch
# mq config
canal.mq.topic=example
# dynamic topic route by schema or table regex
#canal.mq.dynamicTopic=mytest1.user,topic2:mytest2\\..*,.*\\..*
canal.mq.partition=0
# hash partition config
#canal.mq.enableDynamicQueuePartition=false
#canal.mq.partitionsNum=3
#canal.mq.dynamicTopicPartitionNum=test.*:4,mycanal:6
#canal.mq.partitionHash=test.table:id^name,.*\\..*
#################################################
2.adapter配置
bootstrap.yml文件
用admin的服务,需要连Canal自身的数据库
canal:
manager:
jdbc:
url: jdbc:mysql://127.0.0.1:3306/canal_manager?useUnicode=true&characterEncoding=UTF-8
username: canal
password: canal
application.yml文件
主要关注canal.conf.srcDataSources和canal.conf.canalAdapters下的配置
srcDataSources:
defaultDS:
url: 这里填源数据库的jdbc连接信息,例:jdbc:mysql://127.0.0.1:3306/testdb
username: 数据库账号,例:root
password: 数据库密码,例:root
maxActive: 100 #额外增加这一行,默认的连接数只有3,会导致全量同步出现异常,导致全量同步数据缺失,最好改大一点
canalAdapters:
- instance: example #这里就保留叫example,只是个命名
groups:
- groupId: g1
outerAdapters:
- name: logger
- name: rdb
key: mysql1 # 这里保持默认即可
properties:
jdbc.driverClassName: com.mysql.jdbc.Driver #数据库驱动就保持这个驱动,不要修改为带cj的那个驱动,如果这个驱动有问题,再考虑更换驱动
jdbc.url: 这里填写需要同步接收方的数据库链接,例:jdbc:mysql://192.168.1.2:3309/testdb?useUnicode=true
jdbc.username: root
jdbc.password: 123456
druid.stat.enable: false
druid.stat.slowSqlMillis: 1000
表同步配置文件例如:user.yml
ataSourceKey: defaultDS #无需修改
destination: example #这个对应application.yml文件中的
groupId: g1
outerAdapterKey: mysql1
concurrent: true
dbMapping:
database: epidemic #需要同步的数据库名,两台服务器的数据库名最好命名成一样的,不然可能有各种意外情况发生
table: user #需要同步的表名
targetTable: user #同步到目标服务器对应的表名
targetPk:
id: id # 主键,格式为, 源表主键名:目标表主键名
mapAll: true # 映射所有字段,这里改为true的话,下面的targetColumns就可以不用改了,除非两边的数据结构不一样
# targetColumns: #如果字段名称不一样时,前面时目标表字段名称后面时源数据表字段名称
# id:
# name:
# role_id:
# c_time:
# test1:
# etlCondition: "where c_time>={}"
commitBatch: 3000 # 批量提交的大小,保持不动即可
注意:本文归作者所有,未经作者允许,不得转载