介绍
canal 1.1.1版本之后, 增加客户端数据落地的适配及启动功能, 目前支持功能:
- 客户端启动器
 
- 同步管理REST接口
 
- 日志适配器, 作为DEMO
 
- 关系型数据库的数据同步(表对表同步), ETL功能
 
- HBase的数据同步(表对表同步), ETL功能
 
- ElasticSearch多表数据同步,ETL功能
 
安装
请先安装以下服务:
- 安装高可用教程
 
- 安装elasticsearch教程
 
安装canal adapter适配器
1 2 3 4 5 6
   |  wget https://github.com/alibaba/canal/releases/download/canal-1.1.4/canal.deployer-1.1.4.tar.gz
  tar xf canal.deployer-1.1.4.tar.gz -C /data/canal.deployer vim /data/canal.deployer/conf/application.yml
 
 
  | 
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
   | server:   port: 8081 spring:   jackson:     date-format: yyyy-MM-dd HH:mm:ss     time-zone: GMT+8     default-property-inclusion: non_null
  canal.conf:   mode: tcp 
 
    zookeeperHosts: 192.168.40.101:2181
 
    batchSize: 500   syncBatchSize: 1000   retries: 0   timeout:   accessKey:   secretKey:
    srcDataSources:     defaultDS:       url: jdbc:mysql://192.168.40.100:3306/test?useUnicode=true       username: root       password: 123123   canalAdapters:      - instance: elastic     groups:     - groupId: g1       outerAdapters:       - name: logger              - name: es         hosts: 192.168.40.101:9300         properties:                                 cluster.name: canal-es
 
  | 
 
创建mysql–elasticsearch映射表文件
1
   | vim /data/canal.deployer/conf/es/test.yml
 
  | 
 
1 2 3 4 5 6 7 8 9 10
   | dataSourceKey: defaultDS destination: elastic groupId: esMapping:   _index: test   _type: _doc   _id: _id   upsert: true   sql: "select a.id as _id,a.name,a.address from test a"   commitBatch: 3000
 
  | 
 
mysql表结构
1 2 3 4 5 6
   | CREATE TABLE `test` (   `id` int(11) NOT NULL,   `name` varchar(200) NOT NULL,   `address` varchar(1000) DEFAULT NULL,   PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
  | 
 
elasticsearch索引创建
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
   | curl -XPUT http: '{     "mappings":{         "_doc":{             "properties":{                 "name":{                     "type":"text"                 },                 "address":{                     "type":"text"                 }             }         }     } }'
 
  | 
 
elastic配置文件
1 2 3 4 5 6 7 8 9
   | cluster.name: canal-es node.name: node-1 network.host: 192.168.40.101 http.port: 9200 discovery.zen.ping.unicast.hosts: ["192.168.40.101"] transport.tcp.port: 9300 transport.tcp.compress: true http.cors.enabled: true http.cors.allow-origin: "*"
 
  | 
 
启动
1 2
   | /data/canal.deployer/bin/startup.sh /data/canal.deployer/bin/stop.sh
 
  | 
 
测试
- 在mysql插入记录
 
- 查看es文档数据