a. canal的原理是基于mysql binlog技術(shù)剔蹋,所以這里一定需要開啟mysql的binlog寫入功能,建議配置binlog模式為row.
**針對阿里云RDS賬號默認(rèn)已經(jīng)有binlog dump權(quán)限,不需要任何權(quán)限或者binlog設(shè)置,可以直接跳過這一步**
只是記錄
軟件版本cananl1.0.24,mysql在5.7.21 5.6.38測試通過
[mysqld]
log-bin=mysql-bin #添加這一行就ok
binlog-format=ROW #選擇row模式
server_id=1 #配置mysql replaction需要定義浅辙,不能和canal的slaveId重復(fù)
b. canal的原理是模擬自己為mysql slave魔慷,所以這里一定需要做為mysql slave的相關(guān)權(quán)限.
CREATE USER canal IDENTIFIED BY 'canal';?
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
-- GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%' ;
FLUSH PRIVILEGES;
針對已有的賬戶可直接通過grant
啟動步驟:
1. 下載canal
直接下載
訪問:https://github.com/alibaba/canal/releases 丙笋,會列出所有歷史的發(fā)布版本包 下載方式,比如以1.0.17版本為例子:
wget https://github.com/alibaba/canal/releases/download/canal-1.0.17/canal.deployer-1.0.17.tar.gz
or
自己編譯
git clone git@github.com:alibaba/canal.git
cd canal;
mvn clean install -Dmaven.test.skip -Denv=release
編譯完成后芦劣,會在根目錄下產(chǎn)生target/canal.deployer-$version.tar.gz
2. 解壓縮
mkdir /tmp/canal
tar zxvf canal.deployer-$version.tar.gz? -C /tmp/canal
解壓完成后粗俱,進(jìn)入/tmp/canal目錄,可以看到如下結(jié)構(gòu):
drwxr-xr-x 2 jianghang jianghang? 136 2013-02-05 21:51 bin
drwxr-xr-x 4 jianghang jianghang? 160 2013-02-05 21:51 conf
drwxr-xr-x 2 jianghang jianghang 1.3K 2013-02-05 21:51 lib
drwxr-xr-x 2 jianghang jianghang? 48 2013-02-05 21:29 logs
3. 配置修改
應(yīng)用參數(shù):
vi conf/example/instance.properties
#################################################
## mysql serverId
canal.instance.mysql.slaveId = 1234
position info虚吟,需要改成自己的數(shù)據(jù)庫信息
canal.instance.master.address = 127.0.0.1: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寸认,需要改成自己的數(shù)據(jù)庫信息
canal.instance.dbUsername = canal
canal.instance.dbPassword = canal
canal.instance.defaultDatabaseName =
canal.instance.connectionCharset = UTF-8
table regex
canal.instance.filter.regex = .\..
#################################################
說明:
? ? canal.instance.connectionCharset 代表數(shù)據(jù)庫的編碼方式對應(yīng)到j(luò)ava中的編碼類型,比如UTF-8串慰,GBK , ISO-8859-1
注釋:多個客戶端的處理方式:
vi canal.properties
#########? ? ? ? ? ? ? destinations? ? ? ? ? ? #############
#################################################
canal.destinations= example,test
# conf root dir
canal.conf.dir = ../conf
# auto scan instance dir add/remove and start/stop instance
canal.auto.scan = true
canal.auto.scan.interval = 5
4. 準(zhǔn)備啟動
sh bin/startup.sh
5. 查看日志
vi 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 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....
6. 關(guān)閉
sh bin/stop.sh
it's over.