1.1. 一、开启mysql binlog

1、查看目标mysql是否开启binlog(10.0.0.5)

show variables like 'log_bin';

截屏2022-06-06 10.39.49

若显示为“ON”,说明已经开启binlog(跳到《二、安装canal》),否则没有开启,继续执行(《2、修改配置》)

2、修改配置

#修改MySQL配置文件
vim /etc/mysql/mysql.conf.d/mysqld.cnf
#添加的内容如下:
log-bin=mysql-bin
binlog-format=ROW #开启binlog 选择ROW模式 
server_id=1

3、重启mysql 4、查看配置状态

show variables like 'log_bin';
show variables like 'binlog_format';
show master status;

1.2. 二、安装canal

1、下载canal 1.1.5(git)

wget https://ld0522.oss-cn-hangzhou.aliyuncs.com/design/canal.deployer-1.1.5.tar.gz

2、解压

tar zxvf canal.deployer-1.1.5.tar.gz -C /root/app/canal

3、查看解压文件 截屏2022-06-06 10.43.49

1.3. 三、修改配置

vim conf/canal.properties

...
# 1、指定rabbitmq
canal.serverMode = rabbitmq
...
#2、设置过滤的binlog
canal.instance.filter.druid.ddl = true
canal.instance.filter.query.dcl = true
canal.instance.filter.query.dml = true
canal.instance.filter.query.ddl = true
canal.instance.filter.table.error = true
#binlog 开启row模式
canal.instance.filter.rows = false
canal.instance.filter.transaction.entry = true
# 监听insert语句
canal.instance.filter.dml.insert = false
# 监听insert语句
canal.instance.filter.dml.update = false
# 监听insert语句
canal.instance.filter.dml.delete = false
...
# 3、设置实例配置文件
canal.destinations = example,example1
...
# 4、修改rabbitmq连接信息
rabbitmq.host = 10.0.0.62
rabbitmq.virtual.host = /
rabbitmq.exchange = xiaomi_pictorial_exchange
rabbitmq.username = 1plAaFyr
rabbitmq.password = lPOKTkuoCdYUT2TM5zrI9KmXbLTUWW5j
rabbitmq.deliveryMode = direct
vim conf/example/instance.properties

#1、指定主节点地址mysql
canal.instance.master.address=10.0.0.5:3306
...
#2、用户名密码
canal.instance.dbUsername=inforec
canal.instance.dbPassword=t1VMkZLU
...
#3、设置需要监控的库和表 .*\\..*(所有库所有表) notification\\..*(该库下所有表)
canal.instance.filter.regex=inforec\\.cont_pool_article
...
#4、指定rabbitmq的routingkey
canal.mq.topic=xiaomi_pictorial_routeKey

1.4. 四、启动canal

启动与停止

#启动
./bin/startup.sh

#停止
./bin/stop.sh

查看日志

cat logs/canal/canal.log 

cat logs/example/example.log

截屏2022-06-06 10.52.33

1.5. 五、验证

当有内容入大库(10.0.0.5)inforec.cont_pool_article时,会将内容直接同步到rabbitmq上的队列xiaomi_pictorial_queue

截屏2022-06-06 10.58.59

截屏2022-06-06 10.59.20如上图可以看到有消息投递到该队列中

results matching ""

    No results matching ""