自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Canal實(shí)現(xiàn)MySQL數(shù)據(jù)庫(kù)實(shí)時(shí)數(shù)據(jù)同步

數(shù)據(jù)庫(kù) MySQL
Canal Server能夠解析MySQL binlog并訂閱數(shù)據(jù)更改,而Canal Client可以實(shí)現(xiàn)將更改廣播到任何地方,例如數(shù)據(jù)庫(kù)和Apache Kafka。

[[343023]]

簡(jiǎn)介

1.1 canal介紹

Canal是一個(gè)基于MySQL二進(jìn)制日志的高性能數(shù)據(jù)同步系統(tǒng)。Canal廣泛用于阿里巴巴集團(tuán)(包括https://www.taobao.com),以提供可靠的低延遲增量數(shù)據(jù)管道,github地址:https://github.com/alibaba/canal

Canal Server能夠解析MySQL binlog并訂閱數(shù)據(jù)更改,而Canal Client可以實(shí)現(xiàn)將更改廣播到任何地方,例如數(shù)據(jù)庫(kù)和Apache Kafka。

它具有以下功能:

  •  支持所有平臺(tái)。
  •  支持由Prometheus提供支持的細(xì)粒度系統(tǒng)監(jiān)控。
  •  支持通過(guò)不同方式解析和訂閱MySQL binlog,例如通過(guò)GTID。
  •  支持高性能,實(shí)時(shí)數(shù)據(jù)同步。(詳見Performance)
  •  Canal Server和Canal Client都支持HA / Scalability,由Apache ZooKeeper提供支持
  •  Docker支持。

缺點(diǎn):

不支持全量更新,只支持增量更新。

完整wiki地址:https://github.com/alibaba/canal/wiki

1.2 運(yùn)作原理

原理很簡(jiǎn)單:

  1.  Canal模擬MySQL的slave的交互協(xié)議,偽裝成mysql slave,并將轉(zhuǎn)發(fā)協(xié)議發(fā)送到MySQL Master服務(wù)器。
  2.  MySQL Master接收到轉(zhuǎn)儲(chǔ)請(qǐng)求并開始將二進(jìn)制日志推送到slave(即canal)。
  3.  Canal將二進(jìn)制日志對(duì)象解析為自己的數(shù)據(jù)類型(原始字節(jié)流)

如圖所示:

準(zhǔn)備工作

2.1 下載解壓canal-server

通過(guò) github 下載 canal-server release 版本(本次安裝文檔使用v1.1.4) 

  1. root@locahost:/# wget  https://github.com/alibaba/canal/releases/download/canal-1.1.4/canal.deployer-1.1.4.tar.gz 

解壓 

  1. tar -zxvf canal.deployer-1.1.4.tar.gz 

2.2 下載解壓 canal-adapter

通過(guò) github 下載 canal-adapter release 版本(本次安裝文檔使用v1.1.4) 

  1. root@locahost:/# wget https://github.com/alibaba/canal/releases/download/canal-1.1.4/canal.adapter-1.1.4.tar.gz 

解壓 

  1. tar -zxvf canal.adapter-1.1.4.tar.gz 

配置 canal-server

3.1 canal-server 配置

解壓之后進(jìn)入 conf文件夾中,修改 canal.properties 根據(jù)實(shí)際需要來(lái)修改(如果不使用kafka或MQ 默認(rèn)tcp即可) 

  1. canal.destinations = prod # 指定instance的名字多個(gè)使用逗號(hào)分隔 

保存之后在conf目錄創(chuàng)建 prod 文件夾并將 example文件夾中的 nstance.properties copy 到and_prod中 

  1. mkdir ant_prod  #創(chuàng)建文件夾  
  2. cp example/nstance.properties  prod/ # copy 文件 

修改 nstance.properties 配置如下: 

  1. canal.instance.master.address=127.0.0.1:3306      # 源Mysql地址  
  2. canalcanal.instance.dbUsername=canal                   # 源Mysql賬號(hào)  
  3. canalcanal.instance.dbPassword=canal                   # 源Mysql密碼  
  4. canal.instance.connectionCharset=UTF-8            # 與源數(shù)據(jù)庫(kù)編碼格式一致   
  5. canal.instance.defaultDatabaseName=test_database  # 默認(rèn)監(jiān)聽源數(shù)據(jù)庫(kù) 

3.2 canal-server 啟動(dòng)

進(jìn)入 canal-server bin 目錄 啟動(dòng) 

  1. cd canal-server/bin # 進(jìn)入目錄  
  2. ./startup.sh & # 后臺(tái)啟動(dòng) 

查看日志,是否啟動(dòng)成功 

  1. cd canal-server/logs/ant_prod #進(jìn)入日志目錄 

啟動(dòng)成功: 

  1. 2020-06-09 17:13:04.956 [main] WARN  o.s.beans.GenericTypeAwarePropertyDescriptor - Invalid JavaBean property 'connectionCharset' being accessed! Ambiguous write methods found next to actually used [public void com.alibaba.otter.canal.parse.inbound.mysql.AbstractMysqlEventParser.setConnectionCharset(java.nio.charset.Charset)]: [public void com.alibaba.otter.canal.parse.inbound.mysql.AbstractMysqlEventParser.setConnectionCharset(java.lang.String)] 
  2. 2020-06-09 17:13:04.990 [main] INFO  c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [canal.properties] 
  3. 2020-06-09 17:13:04.990 [main] INFO  c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [ant_prod/instance.properties] 
  4. 2020-06-09 17:13:05.305 [main] INFO  c.a.otter.canal.instance.spring.CanalInstanceWithSpring - start CannalInstance for 1-ant_prod  
  5. 2020-06-09 17:13:05.311 [main] WARN  c.a.o.canal.parse.inbound.mysql.dbsync.LogEventConvert - --> init table filter : ^.*\..*$ 
  6. 2020-06-09 17:13:05.311 [main] WARN  c.a.o.canal.parse.inbound.mysql.dbsync.LogEventConvert - --> init table black filter :  
  7. 2020-06-09 17:13:05.315 [main] INFO  c.a.otter.canal.instance.core.AbstractCanalInstance - start successful.... 
  8. 2020-06-09 17:13:05.422 [destination = ant_prod , address = rm-wz99s5v03gso12521.mysql.rds.aliyuncs.com/192.xxxxxx:3306 , EventParser] WARN  c.a.o.c.p.inbound.mysql.rds.RdsBinlogEventParserProxy - ---> begin to find start position, it will be long time for reset or first position 
  9. 2020-06-09 17:13:05.423 [destination = ant_prod , address = rm-wz99s5v03gso12521.mysql.rds.aliyuncs.com/192.xxxxxx:3306 , EventParser] WARN  c.a.o.c.p.inbound.mysql.rds.RdsBinlogEventParserProxy - prepare to find start position just show master status 
  10. 2020-06-09 17:13:06.483 [destination = ant_prod , address = rm-wz99s5v03gso12521.mysql.rds.aliyuncs.com/192.xxxxxx:3306 , EventParser] WARN  c.a.o.c.p.inbound.mysql.rds.RdsBinlogEventParserProxy - ---> find start position successfully, EntryPosition[included=false,journalName=mysql-bin.000234,position=6676924,serverId=184376678,gtid=,timestamp=1591693973000] cost : 1051ms , the next step is binlog dump 

配置 canal-adapter

4.1 canal-adapter 配置

由于Mysql 是8.0 這里需要下載 mysql-connector-java-8.0.20.jar,并將其放入lib中 

  1. cp mysql-connector-java-8.0.20.jar /canal-adapter/lib/ 

解壓之后進(jìn)入 conf文件夾中,修改 application.yml 

  1. server:  
  2.   port: 8089  
  3. spring:  
  4.   jackson:  
  5.     date-format: yyyy-MM-dd HH:mm:ss  
  6.     time-zone: GMT+8  
  7.     default-property-inclusion: non_null  
  8. canal.conf:  
  9.   mode: tcp # kafka rocketMQ  
  10.   canalServerHost: 127.0.0.1:11111  
  11.   batchSize: 500  
  12.   syncBatchSize: 1000  
  13.   retries: 0  
  14.   timeout: 
  15.    accessKey:  
  16.   secretKey:  
  17. # 源Mysql 地址賬號(hào)密碼等  
  18.   srcDataSources:   
  19.     defaultDS:  
  20.       url: jdbc:mysql://localhost:3306/test_database?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai 
  21.        username: canal  
  22.       password: canal  
  23. # 需要實(shí)時(shí)同步數(shù)據(jù)庫(kù),如果多個(gè)實(shí)例進(jìn)行區(qū)分即可  
  24.   canalAdapters:  
  25.   - instance: prod # canal instance,在canal-server中指定instance的名稱  
  26.     groups:  
  27.     - groupId: g1  
  28.       outerAdapters:  
  29.       - name: rdb  
  30.         key: mysql1 # 唯一標(biāo)示  
  31.         properties:  
  32.           jdbc.driverClassName: com.mysql.jdbc.Driver  
  33.           jdbc.url: jdbc:mysql://localhost:3306/test_database_01?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai  
  34.           jdbc.username: canal  
  35.           jdbc.password: canal 

編輯rdb目錄下面表的映射文件,數(shù)據(jù)庫(kù)/表 (多個(gè)表創(chuàng)建多個(gè)映射文件,文件名對(duì)應(yīng)表名)以此類推 

  1. dataSourceKey: defaultDS  
  2. destination: prod  
  3. outerAdapterKey: mysql1  
  4. concurrent: true  
  5. dbMapping:  
  6.   database: test_database_01  
  7.   table: test  
  8.   targetTable: test_database_01.test  
  9.   targetPk:  
  10.     id: id  
  11.   mapAll: true 

4.1 canal-adapter 啟動(dòng)

進(jìn)入 canal-adapter/bin 目錄 啟動(dòng) 

  1. cd canal-adapter/bin # 進(jìn)入目錄  
  2. ./startup.sh & # 后臺(tái)啟動(dòng) 

查看日志,是否啟動(dòng)成功 

  1. cd canal-adapter/adapter/logs/ #進(jìn)入日志目錄  
  2. tail -f adapter.log # 查看日志是否啟動(dòng)成功 

測(cè)試數(shù)據(jù)庫(kù)同步 

  1. 更新/刪除/批量插入/批量更新/批量刪除  

 

責(zé)任編輯:龐桂玉 來(lái)源: 馬哥Linux運(yùn)維
相關(guān)推薦

2024-10-30 08:15:18

2011-06-07 17:01:44

2010-06-02 16:57:50

MySQL數(shù)據(jù)庫(kù)同步

2010-06-09 17:36:45

MySQL數(shù)據(jù)庫(kù)同步

2010-06-09 15:01:18

MySQL數(shù)據(jù)庫(kù)同步

2010-05-17 14:00:07

MySql數(shù)據(jù)庫(kù)

2023-08-31 08:32:52

2019-10-08 15:54:42

SQL數(shù)據(jù)庫(kù)技術(shù)

2019-07-23 10:43:28

MariaDB數(shù)據(jù)庫(kù)MySQL

2024-12-06 08:29:29

2023-09-26 08:11:22

Spring配置MySQL

2012-04-13 13:46:27

SAPHANASybase

2011-04-14 10:36:36

2010-08-27 09:59:51

SQL Server

2023-09-08 10:13:30

開發(fā)技術(shù)

2010-07-01 15:44:22

SQL Server數(shù)

2025-04-01 08:38:41

2020-08-31 07:00:00

數(shù)據(jù)庫(kù)數(shù)據(jù)庫(kù)同步

2023-05-31 08:56:24

2010-05-12 18:41:34

MySQL數(shù)據(jù)庫(kù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)