当前位置:网站首页>Canel-简介&使用
Canel-简介&使用
2022-07-17 05:24:00 【顶尖高手养成计划】
简介
canal 的工作原理

canal 的工作原理
很简单,就是把自己伪装成 slave,假装从 master 复制数据
开始使用
前期准备
开启mysql的binlog
sudo vi /etc/mysql/my.cnf[mysqld]
server-id = 1
log-bin=mysql-bin
binlog_format=row
binlog-do-db=gmall
参数说明
- 在[mysqld] ,log-bin=mysql-bin
- mysql binlog 的格式有三种,分别是 STATEMENT,MIXED,ROW。
- binlog-do-db指定监控哪个数据库
配置好以后重启mysql
sudo systemctl restart mysqldmysql> set global validate_password_length=4;
mysql> set global validate_password_policy=0;
mysql> GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO
'canal'@'%' IDENTIFIED BY 'canal' ;使用
canal 架构

下载
https://github.com/alibaba/canal/releases
主体配置
tar -zxvf canal.deployer-1.1.4.tar.gz修改配置文件canal.properties
vi canal.propertiescanal.serverMode = kafka
canal.mq.servers = master:9092,node1:9092,node2:9092canal.destinations = example实例配置
vi instance.propertiescanal.instance.dbUsername=root
canal.instance.dbPassword=root# mq config
canal.mq.topic=gmall_db
# dynamic topic route by schema or table regex
#canal.mq.dynamicTopic=mytest1.user,mytest2\\..*,.*\\..*
#canal.mq.partition=0
# hash partition config,下面的分区数和自己主题的partition数目相同
canal.mq.partitionsNum=4启动
bin/startup.sh
测试
bin/kafka-console-consumer.sh --bootstrap-server master:9092 --topic gmall_db然后往mysql里面监听的数据库插入一条数据看kafka是否有数据接收到
停止
bin/stop.shcanal 高可用
接收到数据的格式例子
添加
{
"data": [
{
"id": "1547090631092903951",
"user_id": "1413",
"nick_name": null,
"head_img": null,
"sku_id": "16",
"spu_id": "4",
"order_id": "5991",
"appraise": "1201",
"comment_txt": "评论内容:51811533721518964616668687831874922222995433369391",
"create_time": "2022-06-28 13:28:44",
"operate_time": null
}
],
"database": "gmall",
"es": 1657690124000,
"id": 211,
"isDdl": false,
"mysqlType": {
"id": "bigint(20)",
"user_id": "bigint(20)",
"nick_name": "varchar(20)",
"head_img": "varchar(200)",
"sku_id": "bigint(20)",
"spu_id": "bigint(20)",
"order_id": "bigint(20)",
"appraise": "varchar(10)",
"comment_txt": "varchar(2000)",
"create_time": "datetime",
"operate_time": "datetime"
},
"old": null,
"pkNames": [
"id"
],
"sql": "",
"sqlType": {
"id": -5,
"user_id": -5,
"nick_name": 12,
"head_img": 12,
"sku_id": -5,
"spu_id": -5,
"order_id": -5,
"appraise": 12,
"comment_txt": 12,
"create_time": 93,
"operate_time": 93
},
"table": "comment_info",
"ts": 1657690130536,
"type": "INSERT"
}删除
{
"data": [
{
"dic_code": "1102",
"dic_name": "微信",
"parent_code": "11",
"create_time": null,
"operate_time": null
}
],
"database": "gmall",
"es": 1657690329000,
"id": 212,
"isDdl": false,
"mysqlType": {
"dic_code": "varchar(10)",
"dic_name": "varchar(100)",
"parent_code": "varchar(10)",
"create_time": "datetime",
"operate_time": "datetime"
},
"old": null,
"pkNames": null,
"sql": "",
"sqlType": {
"dic_code": 12,
"dic_name": 12,
"parent_code": 12,
"create_time": 93,
"operate_time": 93
},
"table": "base_dic",
"ts": 1657690329374,
"type": "DELETE"
}修改
{
"data": [
{
"id": "1",
"login_name": "g4hpd2mp2",
"nick_name": "修改",
"passwd": null,
"name": "沈昌成",
"phone_num": "13973123428",
"email": "[email protected]",
"head_img": null,
"user_level": "1",
"birthday": "2004-08-10",
"gender": "M",
"create_time": "2020-06-10 21:48:29",
"operate_time": "2022-06-28 13:28:34",
"status": null
}
],
"database": "gmall",
"es": 1657690400000,
"id": 213,
"isDdl": false,
"mysqlType": {
"id": "bigint(20)",
"login_name": "varchar(200)",
"nick_name": "varchar(200)",
"passwd": "varchar(200)",
"name": "varchar(200)",
"phone_num": "varchar(200)",
"email": "varchar(200)",
"head_img": "varchar(200)",
"user_level": "varchar(200)",
"birthday": "date",
"gender": "varchar(1)",
"create_time": "datetime",
"operate_time": "datetime",
"status": "varchar(200)"
},
"old": [
{
"nick_name": "雄琛"
}
],
"pkNames": [
"id"
],
"sql": "",
"sqlType": {
"id": -5,
"login_name": 12,
"nick_name": 12,
"passwd": 12,
"name": 12,
"phone_num": 12,
"email": 12,
"head_img": 12,
"user_level": 12,
"birthday": 91,
"gender": 12,
"create_time": 93,
"operate_time": 93,
"status": 12
},
"table": "user_info",
"ts": 1657690400556,
"type": "UPDATE"
}边栏推荐
- Sword finger offer question brushing record - offer 04 Search in two-dimensional array
- Review of 4121 Computer System for Data Science
- Review of 4246 Algorithms for Data Science
- MySql
- How does the advanced anti DDoS server confirm which are malicious ip/ traffic? ip:103.88.32. XXX
- Redis (II) - jedis
- FreeBSD 12 installing RPM packages
- How does legend open its service? What do you need to prepare to open legend private server?
- 爬虫基础—代理的基本原理
- JS不使用async/await解决数据异步/同步问题
猜你喜欢

Cracking Metric/Business Case/Product Sense Problems

Network knowledge-04 network layer ICMP Protocol

Matlab simulation of cognitive femtocell performance in m3gpp LTE communication network

Network knowledge-02 physical layer

WCDMA soft handoff performance matlab simulation m, comparing the average number of activation sets (MasN), activation set update rate (Asur) and call interruption probability (OP) three performance i

ivew 穿梭框Transfer组件高亮显示操作值

网络知识-03 数据链路层-PPPoE

High concurrency day04 (Zab protocol, observer, NC, Avro, RPC)

OpenSUSE install Netease cloud music (tumblefeed) (LEAP)

Connaissance du réseau - 03 couche de liaison de données - PPPoE
随机推荐
Sword finger offer question brushing record - offer 06 Print linked list from end to end
网络知识-04 网络层-ICMP协议
Pytorch learning notes (I)
网络知识-05 传输层-TCP
express
4. Installation and use of idea
Web Security (XSS and CSRF)
Legendary game setup tutorial
High concurrency day01 (NiO, concurrent package)
TypeScript(ts-loader,tsconfig.json及lodash)
A2B音频总线在智能座舱中的应用
解决Mysql (1064) 错误: 1064 - You have an error in your SQL syntax;
Security自动登录与防CSRF攻击冲突解决办法
组件emit基础
Review of 4705 NLP
Crawler Basics - session and cookies
Cracking Metric/Business Case/Product Sense Problems
爬虫基础—代理的基本原理
Matlab simulation of cognitive femtocell performance in m3gpp LTE communication network
M simulation of cooperative MIMO distributed space-time coding technology based on MATLAB