当前位置:网站首页>安装和配置Canal
安装和配置Canal
2022-04-21 13:03:00 【墨天轮】
安装和配置Canal
下面我们就开启mysql的主从同步机制,让Canal来模拟salve
1.开启MySQL主从
Canal是基于MySQL的主从同步功能,因此必须先开启MySQL的主从功能才可以。
这里以之前用Docker运行的mysql为例:
1.1.开启binlog
打开mysql容器挂载的日志文件,我的在/tmp/mysql/conf目录:

修改文件:
vi /tmp/mysql/conf/my.cnf
添加内容:
log-bin=/var/lib/mysql/mysql-binbinlog-do-db=heima
配置解读:
log-bin=/var/lib/mysql/mysql-bin:设置binary log文件的存放地址和文件名,叫做mysql-binbinlog-do-db=heima:指定对哪个database记录binary log events,这里记录heima这个库
最终效果:
[mysqld]skip-name-resolvecharacter_set_server=utf8datadir=/var/lib/mysqlserver-id=1000log-bin=/var/lib/mysql/mysql-binbinlog-do-db=heima
1.2.设置用户权限
接下来添加一个仅用于数据同步的账户,出于安全考虑,这里仅提供对heima这个库的操作权限。
create user canal@'%' IDENTIFIED by 'canal';GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT,SUPER ON *.* TO 'canal'@'%' identified by 'canal';FLUSH PRIVILEGES;
重启mysql容器即可
docker restart mysql
测试设置是否成功:在mysql控制台,或者Navicat中,输入命令:
show master status;

2.安装Canal
2.1.创建网络
我们需要创建一个网络,将MySQL、Canal、MQ放到同一个Docker网络中:
docker network create heima
让mysql加入这个网络:
docker network connect heima mysql
2.3.安装Canal
canal的镜像压缩包, 大家可以上传到虚拟机,然后通过命令导入:
docker load -i canal.tar
然后运行命令创建Canal容器:
docker run -p 11111:11111 --name canal \-e canal.destinations=heima \-e canal.instance.master.address=mysql:3306 \-e canal.instance.dbUsername=canal \-e canal.instance.dbPassword=canal \-e canal.instance.connectionCharset=UTF-8 \-e canal.instance.tsdb.enable=true \-e canal.instance.gtidon=false \-e canal.instance.filter.regex=heima\\..* \--network heima \-d canal/canal-server:v1.1.5
说明:
-p 11111:11111:这是canal的默认监听端口-e canal.instance.master.address=mysql:3306:数据库地址和端口,如果不知道mysql容器地址,可以通过docker inspect 容器id来查看-e canal.instance.dbUsername=canal:数据库用户名-e canal.instance.dbPassword=canal:数据库密码-e canal.instance.filter.regex=:要监听的表名称
表名称监听支持的语法:
mysql 数据解析关注的表,Perl正则表达式.多个正则之间以逗号(,)分隔,转义符需要双斜杠(\\) 常见例子:1. 所有表:.* or .*\\..*2. canal schema下所有表: canal\\..*3. canal下的以canal打头的表:canal\\.canal.*4. canal schema下的一张表:canal.test15. 多个规则组合使用然后以逗号隔开:canal\\..*,mysql.test1,mysql.test2
版权声明
本文为[墨天轮]所创,转载请带上原文链接,感谢
https://www.modb.pro/db/396311
边栏推荐
- Modify the name of the string through the list
- Decompilation of Revit secondary development
- Revit secondary development - creating floors (phase 12)
- Algorithem_ Merge Two Binary Trees
- [source code analysis] encoding in style: a stylegan encoder for image to image translation
- Building QML applications
- GSMA announced: 2022 MWC Shanghai postponed
- redis-击穿、穿透、雪崩
- Ceph实战(一)-分布式存储介绍与原理架构概述
- Elements of network
猜你喜欢

利用Cisco配置VRRP(虚拟路由器冗余协议)

美创科技受邀为海淀区教育科学研究院开展数据安全培训

Meichuang technology was invited to carry out data security training for Haidian District academy of Educational Sciences

2022年G3锅炉水处理上岗证题目及答案

Operation of simulated examination platform of test question bank for operation certificate of safety management personnel of hazardous chemical business units in 2022

Q:如何论文中附录编号随着正文变化。

Simulated Login of selenium's slider verification code (pig Bajie website)

深入剖析Focal loss损失函数

(建议精读)this指北

GSMA announced: 2022 MWC Shanghai postponed
随机推荐
构建QML应用程序
CPT 102_LEC 10
Interface advanced actual combat (unfinished)
2022年G3锅炉水处理上岗证题目及答案
IEEE PR for paper | 202b
诗词学习-
滑动窗口系列-寻找最小覆盖字串
Jiaozuo Third People's Hospital joined hands with meichuang to open a new situation of data security construction
20210818日记
Problems encountered by programmers in learning
L2-013 red alarm (25 points)
4 years of Android development 13K, completed this 1307 page Android interview full set of real problem analysis, job hopping and salary increase 15K
China Database ranking in April 2022: the spring breeze blows the face, the spring is warm, and the score rises in April
Sliding window series - find minimum overlay string
2022年4月中国数据库排行榜:春风拂面春意暖,分数回升四月天
Creating plug-in panel for Revit secondary development (issue 15)
程序员学习遇到的问题
How a person makes self media videos, and the operation skills in the field of agriculture, rural areas and farmers
赛事解析|乒乓球时序动作定位大赛亚军方案分享
3、 Label preparation