当前位置:网站首页>Canal synchronizes MySQL data changes to Kafka (CentOS deployment)
Canal synchronizes MySQL data changes to Kafka (CentOS deployment)
2022-07-06 04:27:00 【Bean John】
First step : Environmental preparation
- System CentOS7.9: see CentOS edition : cat /etc/redhat-release; The machine memory is at least 2 individual G Memory , because canal The default maximum memory for startup is 2G.
- jdk edition jdk1.8: Please refer to :[https://blog.csdn.net/u010132847/article/details/117002124?spm=1001.2014.3001.5501][https_blog.csdn.net_u010132847_article_details_117002124_spm_1001.2014.3001.5501]
- Deploy mysql8 Version of the machine ip: 192.168.187.132,mysql8 For version installation, see :[https://blog.csdn.net/u010132847/article/details/116905080?spm=1001.2014.3001.5501][https_blog.csdn.net_u010132847_article_details_116905080_spm_1001.2014.3001.5501]
- install canal+kafka Machine ip: 192.168.187.131
The second step :mysql First open Binlog Write function , To configure binlog-format by ROW Pattern .
- mysql8 The version is enabled by default binlog Functional , This step can actually be ignored .
The third step : Create a new database canal Account and give it the right to synchronize the database .
- A new user :create user ‘canal’@‘%’ identified by ‘Canal123!’;
- Give users canal Of SELECT、
REPLICATION SLAVE
andREPLICATION CLIENT
jurisdiction :
- “mysql_native_password ” Special treatment of :mysql8 The default with sha2 This plugin To encrypt the password , If the plug-in is not used in the production of user passwords , When the client accesses, it will report “caching_sha2_password Auth failed” Error of , The following error displays .
2020-05-06 17:19:24.944 [destination = example , address = /192.168.187.132:3306 , EventParser] ERROR com.alibaba.otter.canal.common.alarm.LogAlarmHandler - destination:example[com.alibaba.otter.canal.parse.exception.CanalParseException: java.io.IOException: connect /192.168.187.132:3306 failure
Caused by: java.io.IOException: connect /127.0.0.1:3306 failure
at com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector.connect(MysqlConnector.java:83)
at com.alibaba.otter.canal.parse.inbound.mysql.MysqlConnection.connect(MysqlConnection.java:89)
at com.alibaba.otter.canal.parse.inbound.mysql.MysqlEventParser.preDump(MysqlEventParser.java:86)
at com.alibaba.otter.canal.parse.inbound.AbstractEventParser$3.run(AbstractEventParser.java:183)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: caching_sha2_password Auth failed
at com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector.negotiate(MysqlConnector.java:257)
at com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector.connect(MysqlConnector.java:80)
... 4 more
]
- Therefore, you need to use keywords “mysql_native_password ” The plug-in assigns the account password , as follows :
The expression is as follows :alter user ‘canal’@‘%’ identified with mysql_native_password by ‘Canal123!’;
Step four : Installation and deployment kafka( Include zookeeper)
- Download installation package :wget [https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.8.0/kafka_2.13-2.8.0.tgz][https_mirrors.tuna.tsinghua.edu.cn_apache_kafka_2.8.0_kafka_2.13-2.8.0.tgz]
- Unzip the installation package :tar -zxvf kafka_2.13-2.8.0.tgz
- stay /opt/kafka_2.13-2.8.0/bin The directory can see these startup scripts ( With a little attention, you will find that it also contains zookeeper Script , Yes ,kafka The installation package contains zookeeper Service deployment , There is no need to download the deployment separately , Start directly here ):
- stay /opt/kafka_2.13-2.8.0/config The directory can see the configuration of the service :
- Start... First zookeeper( The configuration file zookeeper.properties No change required ):
command :bin/zookeeper-server-start.sh -daemon config/zookeeper.properties &
remarks : here “-daemon” Indicates that the daemon starts .Daemon Process is also called daemon ,linux Most service processes are implemented through daemons . such as 0 Process of no. ( Scheduling process ) ,1 Process of no. (init process ). From its name guard, we can see that it usually runs when the machine starts , Shut down before stopping . So it should not be affected by the terminal . At the same time, it actually runs in the background .
- Restart kafka( The configuration file config/server.properties Need to change , as follows ):
zookeeper.connect=192.168.187.131:2181
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://localhost:9092 # This machine ip
# ...
Then start the execution command :bin/kafka-server-start.sh -daemon config/server.properties &
stop it kafka Service execution command :bin/kafka-server-stop.sh
Step five : Installation and deployment canal
- download canal: wget [https://github.com/alibaba/canal/releases/download/canal-1.1.5/canal.deployer-1.1.5.tar.gz][https_github.com_alibaba_canal_releases_download_canal-1.1.5_canal.deployer-1.1.5.tar.gz]
- decompression canal(canal Unpack the installation package and put it into the new canal File decompression ): tar -zxvf [canal.deployer-1.1.5.tar.gz][https_github.com_alibaba_canal_releases_download_canal-1.1.5_canal.deployer-1.1.5.tar.gz]
- The unzipped directory is explained as follows :
- bin # Operation and maintenance script file
- conf # Profile directory
canal_local.properties # canal Local configuration , Generally, it does not need to be changed
canal.properties # canal Service configuration
logback.xml # logback Log configuration
metrics # Measurement statistics configuration
spring # spring- The instance configuration , Main and binlog Position calculation 、 Some policy configurations are related , Can be in canal.properties Choose any of the configuration files
example # Instance configuration folder , Generally speaking, a single database corresponds to a separate instance configuration folder
instance.properties # The instance configuration , Generally refers to the configuration of a single database
- lib # Service dependency package
- logs # Log file output directory
- plugin # Supported plug-in directories
connector.kafka-1.1.5-jar-with-dependencies.jar #kafka Dependency package
connector.rabbitmq-1.1.5-jar-with-dependencies.jar #rabbitmq Dependency package
connector.rocketmq-1.1.5-jar-with-dependencies.jar #rocketmq Dependency package
- Modify the configuration file :
The configuration file config/canal.properties find “canal.serverMode” Change the value of to “kafka”, Nothing else needs to be changed .
The configuration file config/exmaple/instance.properties:
find “canal.instance.master.address”, Change its value to installation mysql Server's ip And port number .
find “canal.instance.dbUsername” and “canal.instance.dbPassword” The value of is changed to the previously created mysql Database backup account canal And the password , Nothing else needs to be changed .
- start-up canal service : find /opt/kafka/bin Catalog , Execute the script startup.sh.
Step six : Test the data synchronization function
- Use other tools to create databases 、 The account number of the table permission is mysql The service creates a database and a table .
- We noticed that config/example/instanct.properties There is one “example” Of topic To configure , This is a kafka Test use topic, There is no need to create , Let's take this topic To test , Here's the picture :
- stay kafka Installation directory directory /opt/kafka_2.13-2.8.0, perform kafka Of topic Consumer logs , It is found that there are consumption logs that create corresponding tables .
command :bin/kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --from-beginning --topic example
- Insert another piece of data to see if there is a corresponding message log :
边栏推荐
- Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
- C. The third problem
- HotSpot VM
- Mlapi series - 04 - network variables and network serialization [network synchronization]
- MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
- About some basic DP -- those things about coins (the basic introduction of DP)
- The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry
- [Zhao Yuqiang] deploy kubernetes cluster with binary package
- 绑定在游戏对象上的脚本的执行顺序
- Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
猜你喜欢
Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code
The most detailed and comprehensive update content and all functions of guitar pro 8.0
Solution of storage bar code management system in food industry
The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry
Overturn your cognition? The nature of get and post requests
关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
1291_Xshell日志中增加时间戳的功能
解决“C2001:常量中有换行符“编译问题
Introduction to hashtable
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
随机推荐
About some basic DP -- those things about coins (the basic introduction of DP)
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
Global and Chinese market of rubber wheel wedges 2022-2028: Research Report on technology, participants, trends, market size and share
During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
Global and Chinese markets for patent hole oval devices 2022-2028: Research Report on technology, participants, trends, market size and share
When debugging after pycharm remote server is connected, trying to add breakpoint to file that does not exist: /data appears_ sda/d:/segmentation
Cross domain and jsonp details
P3500 [POI2010]TES-Intelligence Test(二分&离线)
Is the mode of education together - on campus + off campus reliable
Comprehensive ability evaluation system
E. Best Pair
P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
10個 Istio 流量管理 最常用的例子,你知道幾個?
Several important classes in unity
729. My schedule I (set or dynamic open point segment tree)
cdc 能全量拉去oracle 表嘛
About some basic DP -- those things about coins (the basic introduction of DP)
Solution of storage bar code management system in food industry
Redis —— Redis In Action —— Redis 实战—— 实战篇一 —— 基于 Redis 的短信登录功能 —— Redis + Token 的共享 session 应用— 有代码
Leetcode32 longest valid bracket (dynamic programming difficult problem)