canal簡介mysql
文檔git
mysql --help
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
/usr/local/etc/my.cnf
複製代碼
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
複製代碼
[mysqld]
log-bin=mysql-bin # 開啓 binlog
binlog-format=ROW # 選擇 ROW 模式
server_id=1 # 配置 MySQL replaction 須要定義,不要和 canal 的 slaveId 重複
複製代碼
CREATE USER canal IDENTIFIED BY 'canal';
GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%' ; #親測將全部權限打開,會避免 caching_sha2_password Auth failed 致使的問題
-- GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
FLUSH PRIVILEGES; #刷新權限表(必須)
複製代碼
mysql.server restart #修改了配置,須要從新啓動
複製代碼
wget https://github.com/alibaba/canal/releases/download/canal-1.1.4/canal.deployer-1.1.4.tar.gz
複製代碼
mkdir /tmp/canal # /tmp 目錄下開機重啓會刪除
tar zxvf canal.deployer-1.1.4.tar.gz -C /tmp/canal
複製代碼
drwxr-xr-x 6 shi wheel 192B 9 24 15:35 bin
drwxr-xr-x 8 shi wheel 256B 9 24 15:35 conf
drwxr-xr-x 83 shi wheel 2.6K 9 24 15:35 lib
drwxr-xr-x 2 shi wheel 64B 9 2 15:26 logs
複製代碼
vi conf/example/instance.properties
複製代碼
## mysql serverId
canal.instance.mysql.slaveId = 1234
#position info,須要改爲本身的數據庫信息
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,須要改爲本身的數據庫信息
canal.instance.dbUsername = canal
canal.instance.dbPassword = canal
canal.instance.defaultDatabaseName =
canal.instance.connectionCharset = UTF-8
#table regex
canal.instance.filter.regex = .\*\\\\..\*
複製代碼
須要配置 canal.instance.master.journal.name
參數和 canal.instance.master.position
參數和canal.instance.defaultDatabaseName
參數。github
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000009 | 155 | | | |
+------------------+----------+--------------+------------------+-------------------+
複製代碼
將File和Position分別填入canal.instance.master.journal.name
參數和 canal.instance.master.position
參數中。spring
mysql> create database example;
Query OK, 1 row affected (0.09 sec)
複製代碼
將 example 填入到 canal.instance.defaultDatabaseName
參數中。sql
cd /tmp/canal/
sh bin/startup.sh
複製代碼
vim logs/canal/canal.log
2019-09-27 11:07:24.349 [main] INFO com.alibaba.otter.canal.deployer.CanalStarter - ## start the canal server.
2019-09-27 11:07:24.388 [main] INFO com.alibaba.otter.canal.deployer.CanalController - ## start the canal server[172.19.1.33(172.19.1.33):11111]
2019-09-27 11:07:25.474 [main] INFO com.alibaba.otter.canal.deployer.CanalStarter - ## the canal server is running now ......
複製代碼
vim logs/example/example.log
2019-09-27 11:07:24.992 [main] INFO c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [canal.properties]
2019-09-27 11:07:24.993 [main] INFO c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [example/instance.properties]
2019-09-27 11:07:25.418 [main] INFO c.a.otter.canal.instance.spring.CanalInstanceWithSpring - start CannalInstance for 1-example
2019-09-27 11:07:25.425 [main] WARN c.a.o.canal.parse.inbound.mysql.dbsync.LogEventConvert - --> init table filter : ^.*\..*$
2019-09-27 11:07:25.425 [main] WARN c.a.o.canal.parse.inbound.mysql.dbsync.LogEventConvert - --> init table black filter :
2019-09-27 11:07:25.434 [main] INFO c.a.otter.canal.instance.core.AbstractCanalInstance - start successful....
複製代碼
sh bin/stop.sh
複製代碼