版本:canal-server v1.1.5 + mysql 5.7 + canal-php
canal-server默认端口是11111,确保这个端口不被占用
一、mysql配置
- mysql开启binlog
需要注意的是mysql server-id需要跟canal的slaveId不一样,canal默认为0
# my.cnf
log-bin=mysql-bin
binlog-format=ROW
server_id=1
- 创建canal用户
canal连接mysql默认的账户和密码都是canal
grant SELECT, REPLICATION SLAVE, REPLICATION CLIENT on *.* to 'canal'@'%' identified by "canal";
flush privileges;
二、canal配置
- 拉取canal镜像
docker pull canal/canal-server:v1.1.5
- 复制配置文件
### instance.properties 目录 /home/admin/canal-server/conf/example
canal.instance.gtidon=false
# position info
canal.instance.master.address=[本机ipv4]:3306
canal.instance.master.journal.name=
canal.instance.master.position=
canal.instance.master.timestamp=
canal.instance.master.gtid=
# rds oss binlog
canal.instance.rds.accesskey=
canal.instance.rds.secretkey=
canal.instance.rds.instanceId=
# table meta tsdb info
canal.instance.tsdb.enable=true
# username/password
canal.instance.dbUsername=canal
canal.instance.dbPassword=canal
canal.instance.connectionCharset = UTF-8
# enable druid Decrypt database password
canal.instance.enableDruid=false
# table regex
canal.instance.filter.regex=backendorder\\.t_kry_takeout_.*,backendorder\\.t_kry_product_.*,backendshare\\.t_backend_keruyun_bom_.*,backend\\.t_wx_.*
# table black regex
canal.instance.filter.black.regex=mysql\\.slave_.*
# mq config
canal.mq.topic=example
canal.mq.partition=0
- 创建canal容器
docker run -d -v [本机文件位置]:/home/admin/canal-server/conf/example/instance.properties -p 11111:11111 --name canal canal/canal-server:v1.1.5
查看/home/admin/canal-server/logs/example/example.log
查看与数据库的连接情况
三、canal-php配置
- 拉取代码
$ composer require xingwenge/canal_php
或者直接下载
$ git clone https://github.com/xingwenge/canal-php.git
-
运行测试