一、 下载canal
分别下载 canal.deployer-1.1.4 和 canal.adapter-1.1.4
二、安装canal
1. 分别解压canal.deployer-1.1.4和canal.adapter-1.1.4
mkdir /software
tar -xzvf canal.deployer-1.1.4.tar.gz -C /software/canal
tar -xzvf canal.deployer-1.1.4.tar.gz -C /software/canal-adapter-1.1.4
2. mysql相关配置
① mysql开启binlog,修改 my.cnf
[mysqld]
log-bin=mysql-bin
binlog-format=ROW
server_id=1
查看是否成功
show variables like '%log_bin%'
② 创建canal用户,并赋权
CREATE USER canal IDENTIFIED BY 'Canal@123456';
update user set plugin='mysql_native_password' where user='canal';
grant all privileges ON *.* TO 'canal'@'%';
FLUSH PRIVILEGES;
③ 查看binlog偏移量并记录
show master status;
④ 导出目标表历史数据,并在目标库创建表并导入 (请自行操作,注意时间格式)
3. 配置canal.deployer-1.1.4
配置instance.properties
注意:/software/canal/conf/example路径下,首次启动或者数据库变更后,请将此路径下除instance.properties以外的文件删除,否则可能报错
vim /software/canal/conf/example/instance.properties
canal.instance.master.address=127.0.0.1:3306
canal.instance.master.journal.name=mysql-bin.000005
canal.instance.master.position=820633026
canal.instance.master.timestamp=
canal.instance.master.gtid=
canal.instance.dbUsername=canal
canal.instance.dbPassword=Canal@123456
canal.instance.connectionCharset = UTF-8
canal.instance.enableDruid=false
canal.instance.filter.regex=.*\\..*
canal.instance.filter.black.regex=
4. 配置canal.adapter-1.1.4
① 修改application.yml
vim /software/canal-adapter-1.1.4/conf/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
canalServerHost: 10.10.10.10:11111
batchSize: 500
syncBatchSize: 1000
retries: 0
timeout:
accessKey:
secretKey:
srcDataSources:
defaultDS:
url: jdbc:mysql://127.0.0.1:3306/person?useUnicode=true
username: canal
password: Canal@123456
canalAdapters:
- instance: example
groups:
- groupId: g1
outerAdapters:
- name: rdb
key: mysql1
properties:
jdbc.driverClassName: com.mysql.jdbc.Driver
jdbc.url: jdbc:mysql://8.8.8.1:3306/person?useUnicode=true
jdbc.username: root
jdbc.password: root@123.com
- groupId: g2
outerAdapters:
- name: hbase
properties:
hbase.zookeeper.quorum: 8.8.8.5,8.8.8.6,8.8.8.7
hbase.zookeeper.property.clientPort: 2181
zookeeper.znode.parent: /hbase
② 添加mysql同步配置文件,每张表新建一个文件,名称随意
vim /software/canal-adapter-1.1.4/conf/rdb/teacher.yml
dataSourceKey: defaultDS
destination: example
groupId: g1
outerAdapterKey: mysql1
concurrent: true
dbMapping:
database: person
table: teacher
targetTable: teacher
targetPk:
id: id
mapAll: true
commitBatch: 3000
vim /software/canal-adapter-1.1.4/conf/rdb/student.yml
dataSourceKey: defaultDS
destination: example
groupId: g1
outerAdapterKey: mysql1
concurrent: true
dbMapping:
database: person
table: student
targetTable: student
targetPk:
id: id
mapAll: true
commitBatch: 3000
③ 修改hbase同步配置
dataSourceKey: defaultDS
destination: example
hbaseMapping:
mode: STRING
database: person
table: student
hbaseTable: test:student
family: info
uppercaseQualifier: false
commitBatch: 3000
rowKey: vin
columns:
id: info:id
name: info:name
excludeColumns:
- score
三、启动
1. 启动canal.deployer-1.1.4
sh /software/canal/bin/startup.sh
sh /software/canal/bin/restart.sh
sh /software/canal/bin/stop.sh
2. 启动canal.adapter-1.1.4
sh /software/canal-adapter-1.1.4/bin/startup.sh
sh /software/canal-adapter-1.1.4/bin/restart.sh
sh /software/canal-adapter-1.1.4/bin/stop.sh
3. 查看log
tail -100f /software/canal/logs/example/example.log
tail -100f /software/canal-adapter-1.1.4/logs/adapter/adapter.log
四、问题
1. 用户赋权报错
SHOW GRANTS FOR 'canal'@'%' > 1141 - There is no such grant defined for user 'canal' on host '%'
解决方法:删除用户,重新创建,赋权
drop user 'canal'@'%';
CREATE USER canal IDENTIFIED BY 'Canal@123456';
update user set plugin='mysql_native_password' where user='canal';
grant all privileges ON *.* TO 'canal'@'%';
FLUSH PRIVILEGES;
|