使用背景,由于生产环境带宽不大,拉取巨量的计划素材服务部署到公司内网,把素材上传到oss,把url 同步到 生产环境。
canal 版本,下载地址:https://github.com/alibaba/canal/releases
# 下载内容
# admin: canal.admin-1.1.7-SNAPSHOT.tar.gz
# deployer: canal.deployer-1.1.7-SNAPSHOT.tar.gz
# adapter: canal.adapter-1.1.7-SNAPSHOT.tar.gz
部署 admin,如果不要管理界面,这步可以忽略
# 创建文件夹, 上传canal.admin-1.1.7-SNAPSHOT.tar.gz 文件到 /usr/local/canal
mkdir -p /usr/local/canal/admin && cd /usr/local/canal
#解压
tar -xf canal.admin-1.1.7-SNAPSHOT.tar.gz -C admin/
# cd /usr/local/canal/admin/conf 把canal_manager.sql 导入数据库
# 编辑 application.yml 配置数据库
spring.datasource:
address: 192.168.0.31:3306
database: canal_manager
username: root
password: root
# 启动服务
/usr/local/canal/admin/bin/startup.sh
浏览器访问, ip:8089 用户 admin 密码:123456
部署 canal.deployer
# 创建 deployer 文件夹, 上传canal.deployer-1.1.7-SNAPSHOT.tar.gz 文件到 /usr/local/canal
mkdir -p /usr/local/canal/deployer && cd /usr/local/canal
# 解压
tar -xf canal.deployer-1.1.7-SNAPSHOT.tar.gz -C deployer
# 配置 admin,
cd /usr/local/canal/deployer/conf
#备份 canal.properties
mv canal.properties canal.properties.bak
#改 canal_local.properties 为 canal.properties
mv canal_local.properties canal.properties
# 启动
/usr/local/canal/deployer/bin/startup.sh
查看效果
要是没有,手动添加下
重要的两步,配置mysql 开启 binlog,log-bin, binlog-do-db,binlog_forma
1
log-bin=/usr/local/mysql/data/mysql-bin
expire_logs_days=5
server-id=3
gtid-mode=on
enforce-gtid-consistency=on
explicit_defaults_for_timestamp
wait_timeout=7200
interactive_timeout=7200
sync_binlog=0
expire_logs_days=7
# 指定要备份的数据库
binlog-do-db=report
binlog_format=ROW
default-time_zone = '+8:00'
2, 登录mysql 创建用户
CREATE USER 'canal'@'%' IDENTIFIED BY 'canal';
GRANT ALL ON report.* TO 'canal'@'%';
grant replication slave on *.* to 'canal'@'%' identified by 'canal';
flush privileges;
创建Instances
查看日志
更重要的最后一步,部署 canal.adapter-1.1.7-SNAPSHOT.tar.gz
# 创建 adapter 文件夹, 上传canal.adapter-1.1.7-SNAPSHOT.tar.gz 文件到 /usr/local/canal
mkdir -p /usr/local/canal/adapter && cd /usr/local/canal
# 解压
tar -xf canal.adapter-1.1.7-SNAPSHOT.tar.gz -C adapter
# 配置 Instance
cd /usr/local/canal/adapter/conf
# 配置 bootstrap.yml, canal_manager 数据库
canal:
manager:
jdbc:
url: jdbc:mysql://192.168.0.31:3306/canal_manager?useUnicode=true&characterEncoding=UTF-8
### application.yml 配置目标数据库, 重要参数 report, 要跟上一步创建Instances 名称相同
canalAdapters:
- instance: report
groups:
- groupId: g0
outerAdapters:
- name: rdb
key: mysql_report
properties:
jdbc.driverClassName: com.mysql.jdbc.Driver
jdbc.url: jdbc:mysql://192.168.0.1:3306/report?useUnicode=true
jdbc.username: report
jdbc.password: root
# 配置rdb
vim rdb/report.yml
# 内容 ,dataSourceKey,跟上一步创建Instances 名称相同,因为你里面配置了数据源
dataSourceKey: report
destination: report
groupId: g0
outerAdapterKey: mysql_report
concurrent: true
dbMapping:
database: report
table: tbl_file_report
targetTable: tbl_file_report
targetPk:
id: id
mapAll: true
etlCondition: "where c_time>={}"
commitBatch: 3000
查看日志
tailf /usr/local/canal/adapter/logs/adapter/adapter.log
end
谢谢观看