Alibaba Canal 组件

[TOC]

Canal Server 部署

canal server 安装包下载,当前(2019-10-10)最新稳定版本为1.1.4

我们直接下载 canal.deployer

直接在 Aliyun ECS 中下载,有神秘下载速度加成

wget https://github.com/alibaba/canal/releases/download/canal-1.1.4/canal.deployer-1.1.4.tar.gz

解压 canal.deployer 到指定目录:

mkdir /data/canal/canal.deployer-1.1.4
tar -zcvf canal.deployer-1.1.4.tar.gz -C /data/canal/canal.deployer-1.1.4

更改 /etc/my.cnf 配置,开启 MySQL bin-log 功能。

(因为我用的是 wamp,在配置文件my.ini中,默认的项目是[wampmysqld],应该新建[mysqld]后再配置)

[mysqld]
# 用于mysql主从复制功能,注意要与 canal 的 slave_id 区分
server_id=1

# Enable MySQL Binlog
log-bin=mysql-bin
binlog-format=ROW

# 可选项,指定要开启 binlog 的db。比如这里我想只对 ffss 库开启binlog
binlog-do-db=ffss

重启 service mysqld restart,查看更新后的状态

show variables like 'log_bin'; # `ON` 表示开启了binlog
show variables like 'binlog_format'; # `ROW`
select version();

canal 的原理是将自己模拟为 MySQL 的 slave,所以一定需要提前做好一个 MySQL slave 的相关权限配置

CREATE USER 'canal'@'%' IDENTIFIED BY 'canal';
CREATE USER 'canal'@'localhost' IDENTIFIED BY 'canal';
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'localhost';
FLUSH PRIVILEGES;

# 针对已有的账户可通过grants查询权限
show grants for 'canal';

canal.deployer 目录结构:

drwxr-xr-x 2 root root 4096 Oct 10 09:02 bin
drwxr-xr-x 5 root root 4096 Oct 10 09:02 conf
drwxr-xr-x 2 root root 4096 Oct 10 09:02 lib
drwxrwxrwx 2 root root 4096 Sep  2 15:26 logs

canal/conf 目录结构(tree 命令):

├── canal_local.properties
├── canal.properties
├── example
│   └── instance.properties
├── logback.xml
├── metrics
│   └── Canal_instances_tmpl.json
└── spring
    ├── base-instance.xml
    ├── default-instance.xml
    ├── file-instance.xml
    ├── group-instance.xml
    ├── memory-instance.xml
    └── tsdb
        ├── h2-tsdb.xml
        ├── mysql-tsdb.xml
        ├── sql
        │   └── create_table.sql
        └── sql-map
            ├── sqlmap-config.xml
            ├── sqlmap_history.xml
            └── sqlmap_snapshot.xml

Canal.Admin 可视化 WebUI 组件

下载

wget https://github.com/alibaba/canal/releases/download/canal-1.1.4/canal.admin-1.1.4.tar.gz

解压缩

mkdir /data/canal/canal-admin
tar zxvf canal.admin-1.1.4.tar.gz  -C /data/canal/canal-admin

修改配置

vi conf/application.yml

application.yml

server:
  port: 8089
spring:
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8

spring.datasource:
  address: 127.0.0.1:3306
  database: canal_manager
  username: canal
  password: canal
  driver-class-name: com.mysql.jdbc.Driver
  url: jdbc:mysql://${spring.datasource.address}/${spring.datasource.database}?useUnicode=true&characterEncoding=UTF-8&useSSL=false
  hikari:
    maximum-pool-size: 30
    minimum-idle: 1

canal:
  adminUser: admin
  adminPasswd: admin

初始化 Canal Admin manager SQL脚本

mysql -h127.0.0.1 -uroot -p
source conf/canal_manager.sql

访问

http:/127.0.0.1:8089/

默认账号:admin/123456

canal admin 配合 canal server 使用

在 canal-server 端,使用 canal_local.properties 覆盖 canal.properties

# register ip
canal.register.ip =

# canal admin config
canal.admin.manager = 127.0.0.1:8089
canal.admin.port = 11110
canal.admin.user = admin
canal.admin.passwd = 4ACFE3202A5FF5CF467898FC58AAB1D615029441
# admin auto register
canal.admin.register.auto = true
canal.admin.register.cluster =

如果不想更改 canal.properties 配置,也可以使用启动参数

sh canal/bin/startup.sh local

你可能感兴趣的:(Alibaba Canal 组件)