当前位置:网站首页>Canel Introduction & use
Canel Introduction & use
2022-07-19 07:44:00 【Top master cultivation plan】
brief introduction
canal How it works

canal How it works
It's simple , Namely Disguise yourself as slave, Pretend to be from master Copy the data
Start using
Preparation
Turn on mysql Of binlog
sudo vi /etc/mysql/my.cnf[mysqld]
server-id = 1
log-bin=mysql-bin
binlog_format=row
binlog-do-db=gmall
Parameter description
- stay [mysqld] ,log-bin=mysql-bin
- mysql binlog There are three formats for , Namely STATEMENT,MIXED,ROW.
- binlog-do-db Specify which database to monitor
Restart after configuration 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' ;Use
canal framework

download
https://github.com/alibaba/canal/releases
Main body configuration
tar -zxvf canal.deployer-1.1.4.tar.gzModify the configuration file canal.properties
vi canal.propertiescanal.serverMode = kafka
canal.mq.servers = master:9092,node1:9092,node2:9092canal.destinations = exampleThe instance configuration
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, The number of partitions below is the same as that of your theme partition The same number
canal.mq.partitionsNum=4start-up
bin/startup.sh
test
bin/kafka-console-consumer.sh --bootstrap-server master:9092 --topic gmall_dbThen go to mysql Insert a piece of data into the monitored database to see kafka Whether there is data received
stop it
bin/stop.shcanal High availability
Format example of received data
add to
{
"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": " Comment content :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"
}Delete
{
"data": [
{
"dic_code": "1102",
"dic_name": " WeChat ",
"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"
}modify
{
"data": [
{
"id": "1",
"login_name": "g4hpd2mp2",
"nick_name": " modify ",
"passwd": null,
"name": " Shenchangcheng ",
"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": " Xiongchen "
}
],
"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"
}边栏推荐
猜你喜欢

How does Jenkins set the mailbox to automatically send mail?

Spark3.x entry to proficiency - stage 3 (in-depth analysis of the whole process of spark data processing)

Review of 4246 Algorithms for Data Science

Environment variables and folder placement location

express

Product Case Interviews

Network knowledge-03 data link layer PPP

面部关键点检测-CNN

Spark入门到精通-番外篇(Standaone集群的运维和简单操作)

fiddler 抓包工具使用
随机推荐
Freebsd12 install gnome3 graphical interface
Xiaodi network security note information collection CDN bypass technology (7)
What is the difference between Samsung series NAND flash?
AB Testing Review
Edit close automatically generate configuration file when saving
MySql
網絡知識-03 數據鏈路層-PPPoE
express
MySQL regular expression ^ and $usage
SQL刷题总结 SQL Leetcode Review
High concurrency day02 (concurrent package)
Where is the future of HMI conceptual design?
Use Altium designer software to draw a design based on stm32
Spark3.x entry to proficiency - stage 3 (in-depth analysis of the whole process of spark data processing)
Hypothesis testing
Solve MySQL (1064) error: 1064 - you have an error in your SQL syntax;
理解LSTM和GRU
环境变量和文件夹放置位置
This article introduces you to SOA interface testing
Spark3.x entry to proficiency - stage 6 (RDD advanced operator explanation & Illustration & shuffle tuning)