canal安裝部署

雅冰石發表於2020-11-05

 

基於日誌增量訂閱和消費的業務包括:

資料庫映象

資料庫實時備份

索引構建和實時維護(拆分異構索引、倒排索引等)

業務 cache 重新整理

帶業務邏輯的增量資料處理

當前的 canal 支援源端 MySQL 版本包括 5.1.x , 5.5.x , 5.6.x , 5.7.x , 8.0.x

一 實驗環境

二 實驗步驟

2.1 配置源端MariaDB

2.1.1 修改配置檔案

my.cnf 中配置如下:

[mysqld]

log-bin=mysql-bin

binlog-format=ROW

server_id=1

2.1.2 為canal建立專用賬號

CREATE USER CanalUser IDENTIFIED BY '密碼'; 

GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'CanalUser'@'192.168.144.242';

FLUSH PRIVILEGES;

2.2 下載安裝canal

2.2.1 下載

下載 canal, 訪問 release 頁面 , 選擇需要的包下載, 如以 1.1.4 版本為例:

開啟網頁後,往下拉,找到1.1.4:

 

再往下拉,展開Asserts:

 

cd /opt && mkdir canal && cd canal

將安裝包上傳到/opt/canal路徑下。

2.2.2 安裝jdk

可參考https://blog.csdn.net/yabingshi_tech/article/details/51498017

2.2.3 安裝canal

mkdir /usr/local/canal

tar zxvf canal.deployer-1.1.4.tar.gz  -C /usr/local/canal

cd  /usr/local/canal

[root@localhost canal]# ll

總用量 4

drwxr-xr-x. 2 root root   76 11月  5 13:28 bin

drwxr-xr-x. 5 root root  123 11月  5 13:28 conf

drwxr-xr-x. 2 root root 4096 11月  5 13:28 lib

drwxrwxrwx. 2 root root    6 9月   2 2019 logs

2.2.4 修改配置檔案

cd conf/example/

mv instance.properties instance.properties_bak_20201105

vi instance.properties

新增:

#不能與mysql的server_id重複

canal.instance.mysql.slaveId = 1234

#position info

canal.instance.master.address = 192.168.144.241:3306

canal.instance.master.journal.name =

canal.instance.master.position =

canal.instance.master.timestamp =

#canal.instance.standby.address =

#canal.instance.standby.journal.name =

#canal.instance.standby.position =

#canal.instance.standby.timestamp =

#username/password,需要改成自己的資料庫資訊

canal.instance.dbUsername = CanalUser

canal.instance.dbPassword = canal

canal.instance.defaultDatabaseName =

canal.instance.connectionCharset = UTF-8

#table regex

canal.instance.filter.regex = .\*\\\\..\*

2.3 啟動canal

2.3.1 啟動

sh /usr/local/canal/bin/startup.sh

#對應的關閉命令是:

sh /usr/local/canal/bin/stop.sh

2.3.2 檢查日誌是否有報錯

下面兩個日誌必須都是成功啟動的狀態:

#檢查server 日誌

vi  /usr/local/canal/logs/canal/canal.log

2013-02-05 22:45:27.967 [main] INFO  com.alibaba.otter.canal.deployer.CanalLauncher - ## start the canal server.

2013-02-05 22:45:28.113 [main] INFO  com.alibaba.otter.canal.deployer.CanalController - ## start the canal server[10.1.29.120:11111]

2013-02-05 22:45:28.210 [main] INFO  com.alibaba.otter.canal.deployer.CanalLauncher - ## the canal server is running now ......

 

#檢查instance 的日誌

vi /usr/local/canal/logs/example/example.log

2013-02-05 22:50:45.636 [main] INFO  c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [canal.properties]

2013-02-05 22:50:45.641 [main] INFO  c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [example/instance.properties]

2013-02-05 22:50:45.803 [main] INFO  c.a.otter.canal.instance.spring.CanalInstanceWithSpring - start CannalInstance for 1-example

2013-02-05 22:50:45.810 [main] INFO  c.a.otter.canal.instance.spring.CanalInstanceWithSpring - start successful....

 

--本篇文章主要參考自https://github.com/alibaba/canal/wiki/QuickStart