1.下载安装canal
下载地址:https://github.com/alibaba/canal/releases
2.解压下载后的canal,其目录结为:
3.编辑/conf/canal.properties目录下的配置文件,选择消息中间件为RocketMQ
#设置服务模式为RocketMQ
canal.serverMode = rocketMQ
##################################################
######### RocketMQ #############
##################################################
rocketmq.producer.group = test
rocketmq.enable.message.trace = false
rocketmq.customized.trace.topic =canal_test
rocketmq.namespace =
rocketmq.namesrv.addr = 127.0.0.1:9876
rocketmq.retry.times.when.send.failed = 0
rocketmq.vip.channel.enabled = false
rocketmq.tag = cannal_tag
4编辑conf/example目录下的instance.properties的配置文件
## mysql serverId,注意不要和mysqlId中的重复
canal.instance.mysql.slaveId=1234
##实例主机的地址
canal.instance.master.address=127.0.0.1:3306
# username/password
canal.instance.dbUsername=canal
canal.instance.dbPassword=canal
canal.instance.connectionCharset = UTF-8
# mq config和canal.properties中的保持一致
canal.mq.topic=canal_test
5.mysql目录结构,重点配置my.ini的binlog
6.binlog的配置为:
#bin-log相关的配置
#1.开启 binlog
log-bin=mysql-bin
#2.选择 ROW 模式
binlog-format=ROW
#3.配置 MySQL replaction 需要定义,不要和 canal 的 slaveId 重复
server_id=1
7.在数据库中查看相关的binlog有没有生效
7查看binlog_fomt
9,创建canal用户并且让MySQL为其授权
create user canal@'%' IDENTIFIED by 'canal';
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT,SUPER ON *.* TO 'canal'@'%';
FLUSH PRIVILEGES;
10.准备要同步的数据库及表
CREATE DATABASE IF NOT EXISTS gmall
CREATE TABLE `canal_test` (
`体温` varchar(255) DEFAULT NULL,
`身高` varchar(255) DEFAULT NULL,
`体重` varchar(255) DEFAULT NULL,
`文章` varchar(255) DEFAULT NULL,
`日期` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `canal_test`(`体温`, `身高`, `体重`, `文章`, `日期`) VALUES ('36.5', '1.70', '180', '4', '2021-06-01');
INSERT INTO `canal_test`(`体温`, `身高`, `体重`, `文章`, `日期`) VALUES ('36.4', '1.70', '160', '8', '2021-06-02');
INSERT INTO `canal_test`(`体温`, `身高`, `体重`, `文章`, `日期`) VALUES ('36.1', '1.90', '134', '1', '2021-06-03');
INSERT INTO `canal_test`(`体温`, `身高`, `体重`, `文章`, `日期`) VALUES ('37.3', '1.70', '110', '14', '2021-06-04');
INSERT INTO `canal_test`(`体温`, `身高`, `体重`, `文章`, `日期`) VALUES ('35.7', '1.70', '133', '0', '2021-06-05');
INSERT INTO `canal_test`(`体温`, `身高`, `体重`, `文章`, `日期`) VALUES ('36.8', '1.90', '200', '6', '2021-06-06');
INSERT INTO `canal_test`(`体温`, `身高`, `体重`, `文章`, `日期`) VALUES ('37.5', '1.70', '132', '25', '2021-06-07');
INSERT INTO `canal_test`(`体温`, `身高`, `体重`, `文章`, `日期`) VALUES ('35.7', '1.70', '160', '2', '2021-06-08');
INSERT INTO `canal_test`(`体温`, `身高`, `体重`, `文章`, `日期`) VALUES ('36.3', '1.80', '131.4', '9', '2021-06-09');
INSERT INTO `canal_test`(`体温`, `身高`, `体重`, `文章`, `日期`) VALUES ('37.3', '1.70', '98.8', '4', '2021-06-10');
INSERT INTO `canal_test`(`体温`, `身高`, `体重`, `文章`, `日期`) VALUES ('37.3', '1.70', '65.8', '4', '2021-06-10');
11.上述内容都准备完后可以启动RocketMQ和canal
RocketMQ windos启动命令:
1.启动rocketmq
start mqnamesrv.cmd
2.启动brocker
start mqbroker.cmd -n 127.0.0.1:9876 autoCreateTopicEnable=true
canal启动比较简单,windows下找到解压文文件中的bin/startup.bat 即可启动
12 修改数据库中的数据然后查MQ消息队列中的消息