简介
配置过程
1、 找到配置文件,本地数据库配置文件路径为
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
1、 配置文件内容为
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
1、 对于自建MySQL,需要先开启Binlog写入功能,配置binlog-format为ROW模式,my.cnf中配置如下
[mysqld]
log-bin=mysql-bin # 开启 binlog
binlog-format=ROW # 选择 ROW 模式
server_id=1 # 配置 MySQL replaction 需要定义,不要和 canal 的 slaveId 重复
1、 授权 canal 链接 MySQL 账号具有作为 MySQL slave 的权限, 如果已有账户可直接 grant
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 #修改了配置,需要重新启动
1、 启动
- 下载canal,以1.1.4为例:
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
- 解压完成后,进入 /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
参数。
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
参数中。
mysql> create database example;
Query OK, 1 row affected (0.09 sec)
将 example 填入到 canal.instance.defaultDatabaseName
参数中。
- 启动
cd /tmp/canal/
sh bin/startup.sh
- 查看 server 日志
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 ......
- 查看 instance 的日志
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