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
复制代码