Canal学习笔记(MySQL增量数据订阅消费)

发表于 2020-07-24 14:01:10
阅读 174

介绍

介绍

福哥在学习Java的过程中发现阿里帝国有个开源的好东西,用来实现捕获MySQL数据库的数据变化的信息,这个工具就是alibaba/canal

今天我们就来学习一下如何使用canal来监听MySQL数据库的数据变化

安装

下载

通过github下载最新版本

https://github.com/alibaba/canal/releases

[root@tfhome ~]# cd /packages/
[root@tfhome packages]# wget https://github.com/alibaba/canal/releases/download/canal-1.1.4/canal.deployer-1.1.4.tar.gz

安装

直接解压缩即可

[root@tfhome packages]# mkdir /tongfu.net/env/canal-1.1.4
[root@tfhome packages]# tar -xzvf canal.deployer-1.1.4.tar.gz -C /tongfu.net/env/canal-1.1.4/
[root@tfhome packages]# cd /tongfu.net/env/canal-1.1.4/

配置

打开 conf/example/instance.properties 配置文件

[root@tfhome canal-1.1.4]# vi conf/example/instance.properties

设置 mysql 主机和端口

canal.instance.master.address=127.0.0.1:3306

设置 mysql 账号和密码

canal.instance.dbUsername=canal
canal.instance.dbPassword=canal_passwd

设置连接编码

canal.instance.connectionCharset = UTF-8

授权 mysql 账号

GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'localhost' IDENTIFIED BY 'canal_passwd'

启动

通过 startup.sh 启动

[root@tfhome canal-1.1.4]# ./bin/startup.sh

检测启动状态

[root@tfhome canal-1.1.4]# ./bin/startup.sh 
found canal.pid , Please run stop.sh first ,then startup.sh

停止

通过 stop.sh 停止

[root@tfhome canal-1.1.4]# ./bin/stop.sh 
tfhome: stopping canal 27533 ... 
Oook! cost:1