alibaba-canal-1.1.5源码编译使用整理
1、下载canal获取发布包
可以直接从https://github.com/alibaba/canal/releases
下载release发布包,也可以下载源码后自行编译https://github.com/alibaba/canal.git
,以v1.1.5为例,下载源码后执行编译
cd C:\github\alibaba\canal\
mvn clean package -Denv=release -Dmaven.test.skip=true
注意:编译完成后发布包在
C:\github\alibaba\canal\target
目录中
2、修改mysql配置
mysql需要开启binlog
[mysqld]
log-bin=mysql-bin # 开启 binlog
binlog-format=ROW # 选择 ROW 模式
server_id=1 # 配置 MySQL replaction 需要定义,不要和 canal 的 slaveId 重复
可通过以下语句检查配置是否生效
show variables like 'log_bin'; show variables like 'binlog_format'; show binary logs;
创建用户并授权
CREATE USER `canal-user` IDENTIFIED BY '123456';
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal-user'@'%';
FLUSH PRIVILEGES;
3、部署
发布包说明
发布包 | 说明 |
---|---|
canal.adapter-1.1.5.tar.gz | 客户端适配项目 |
canal.admin-1.1.5.tar.gz | 可视化管理项目 |
canal.deployer-1.1.5.tar.gz | canal服务端 |
canal.example-1.1.5.tar.gz | demo项目 |
- 解压发布包
mkdir adapter admin deployer example
tar -zxvf canal.adapter-1.1.5.tar.gz -C adapter
tar -zxvf canal.admin-1.1.5.tar.gz -C admin
tar -zxvf canal.deployer-1.1.5.tar.gz -C deployer
tar -zxvf canal.example-1.1.5.tar.gz -C example
- 配置canal.deployer
进入解压后的目录并修改以下配置项conf/example/instance.properties
canal.instance.master.address=192.168.80.120:3306
canal.instance.dbUsername=canal-user
canal.instance.dbPassword=123456
同时需要注意配置文件
conf/canal.properties
默认配置,默认的serverMode
为tcp
# tcp, kafka, rocketMQ, rabbitMQ
canal.serverMode = tcp
修改完成后进入目录deployer/bin
执行./startup.sh
即可启动,模拟单机运行,暂不需要zookeeper
,查看日志deployer/logs1
[root@localhost canal]# tail -f canal.log
... com.alibaba.otter.canal.deployer.CanalLauncher - ## set default uncaught exception handler
... com.alibaba.otter.canal.deployer.CanalLauncher - ## load canal configurations
... com.alibaba.otter.canal.deployer.CanalStarter - ## start the canal server.
... com.alibaba.otter.canal.deployer.CanalController - ## start the canal server[192.168.80.131(192.168.80.131):11111]
... com.alibaba.otter.canal.deployer.CanalStarter - ## the canal server is running now ......
- 启动canal.adapter
注意配置文件
conf/application.yml
默认配置项,需与deployer
对应默认为tcp
canal.conf: mode: tcp #tcp kafka rocketMQ rabbitMQ
进入adapter/bin
目录,执行./startup.sh
即可,修改数据库数据即可观察到变更日志。
c.a.o.canal.client.adapter.logger.LoggerAdapterExample - DML: {"data":[{"id":1,"name":"test-2020"}],"database":"canal","destination":"example","es":1634352318000,"groupId":"g1","isDdl":false,"old":[{"name":"test-2019"}],"pkNames":["id"],"sql":"","table":"user","ts":1634352318425,"type":"UPDATE"}