Skip to content

Canal高级使用及问题解决

Kervin edited this page Jun 17, 2020 · 9 revisions

Canal安装与部署

1. MySQL的row模式以及赋权

  • 开启MySQL的binlog功能并配置为row模式(my.ini)
  #docker下文件为:/etc/mysql/conf.d/docker.cnf
  #log bin
  log-bin=mysql-bin
  #binlog mode: ROW mode
  binlog-format=ROW
  #master/slave模式log_slave_update这个配置一定要打开
  #log_slave_updates=true
  #config mysql replaction privileges,mustn't repeat with slaveId of canal
  server-id=1

set global binlog_format = "ROW";
set session binlog_format = 'ROW';
set global server_id=1;
set session server_id=1;

-- canal用户赋权

create user canal identified by 'canal'; 
revoke all privileges on *.* from 'canal'@'%' ;  
grant select,super, replication slave, replication client on *.* to 'canal'@'%';  
-- grant all privileges on *.* to 'canal'@'%' ;  
flush privileges;

-- 查看权限及模式

-- 查询canal权限
show grants for 'canal';
-- 查看binlog(log_bin必须为ON以及log_bin_basename)
show variables like '%log_bin%';
-- canal用户查看状态(必须有解析点)
show master status;
-- 查询canal连接情况
select * from information_schema.processlist where user='canal';
-- 查杀Sleep进程
select concat("kill ",id,";") from information_schema.processlist where Command="Sleep";

2. 下载Canal并解压至指定路径

3. 配置canal

  • canal.properties配置(以下可修改,其他默认)
canal.id= 1
#配置IP地址(若为空将自动扫描地址)
canal.ip= 127.0.0.1
#canal端口
canal.port= 11111
#配置zookeeper注册中心(若为空则不使用注册中心)
canal.zkServers=
#canal当前server上部署的instance列表
canal.destinations= example,otter

canal.instance.tsdb.spring.xml=classpath:spring/tsdb/h2-tsdb.xml
#canal.instance.tsdb.spring.xml=classpath:spring/tsdb/mysql-tsdb.xml

#canal.instance.global.spring.xml = classpath:spring/local-instance.xml
#canal.instance.global.spring.xml = classpath:spring/memory-instance.xml
#canal.instance.global.spring.xml = classpath:spring/file-instance.xml
canal.instance.global.spring.xml = classpath:spring/default-instance.xml
  • instance.properties配置(destinations配置后修改样例路径conf\example-->\conf\otter)
#实例slaveId(不与canal.id相同,集群也不相同,唯一的)
canal.instance.mysql.slaveId = 1234
#MySQL数据库配置
canal.instance.master.address = 127.0.0.1:3306
canal.instance.dbUsername = canal
canal.instance.dbPassword = canal
#默认数据库名称(可为空)
canal.instance.defaultDatabaseName = 
canal.instance.connectionCharset = UTF-8
# table regex
canal.instance.filter.regex=.*\\..*
# table black regex
canal.instance.filter.black.regex=

4. 常见问题

问题:**(at least one of)SUPER, REPLICATION SLAVE PRIVILEGES of this operation

解决办法:

  • 检查canal用户权限(包括SELECT,SUPER, REPLICATION SLAVE, REPLICATION CLIENT)
      -- 查询canal权限
      show grants for 'canal';
  • 检查数据库log-bin以及Row模式
      -- 查看binlog(log_bin必须为ON以及log_bin_basename)
      show variables like '%log_bin%';

问题:** server_id not set null

解决办法:

  • 检查server_id
      -- 查看server_id
      show variables like '%server_id%';

问题:** CanalParseException: can't find start position for example 解决办法:

  • 查看解析点
    -- 查看binlog当前解析文件)
    show master status;
    -- 查看binlong列表
    show master logs;
    -- 刷新binlog文件并以新编号记录
    flush logs;
    -- 重置(清除)binlog文件重新开始编号000001
    reset master;
    -- 清除mysql-bin.000100之前所有日志
    purge master logs to 'mysql-bin.000100';
  • 配置解析点 canal.instance.master.journal.name=mysql-bin.000001 //其值show master status获得

zookeeper节点含义(./zkCli.sh)

  • 查看canal的server端集群信息
 ls /otter/canal/cluster
  • 查看canal的server端example实例集群信息
 ls /otter/canal/destinations/example/cluster
  • 查看canal的server端example实例主节点信息
 get /otter/canal/destinations/example/running
  • 查看canal的server端example实例解析点信息
 get /otter/canal/destinations/example/parse
  • 查看canal的client端example实例集群信息
 ls /otter/canal/destinations/example/1001/cluster
  • 查看canal的client端example实例主节点信息
 get /otter/canal/destinations/example/1001/running
  • 查看canal的client端example实例解析位置信息
 get /otter/canal/destinations/example/1001/cursor