canal-admin1.1.15界面化安装配置canal集群详解

安装准备

虚拟机服务器四台
192.168.216.110 (主机名mysql)
192.168.216.111 (主机名hadoop01)
192.168.216.112 (主机名hadoop02)
192.168.216.113 (主机名hadoop03)

canal.admin-1.1.5.tar.gz
canal.deployer-1.1.5.tar.gz
下载地址 https://github.com/alibaba/canal/releases/tag
页面底端

自行安装

zk集群 (本demo—zk地址192.168.216.111:2181,192.168.216.112:2181,192.168.216.113:2181)
mysql5.7(本demo—mysql地址192.168.216.110:3306)
kafka集群(本demo—rocketMQ地址192.168.216.111:9876,192.168.216.112:9876,192.168.216.113:9876)

安装canal-admin

1.创建文件夹canal_admin,将canal.admin-1.1.5.tar.gz解压到该目录
mkdir canal_admin
tar -zxvf canal.admin-1.1.5.tar.gz -C /tmp/canal_admin

2.修改配置application.yml
cd /tmp/canal_admin/conf
vim application.yml

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

spring.datasource:
  address: 192.168.216.110:3306
  database: canal_manager
  username: root
  password: 123456
  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: 123456

3.mysql操作
a. 编辑 mysql配置文件/etc/my.cnf
vim /etc/my.cnf
在mysqld标签下新增如下代码

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
lower_case_table_names=1
log-bin=mysql-bin # 开启 binlog
binlog-format=ROW # 选择 ROW 模式
server_id=1 # 配置 MySQL replaction 需要定义,不要和 canal 的 slaveId 重复

#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
validate_password=off

#server_id = 1
#log-bin=mysql-bin
#binlog_format = ROW
#log_timestamps=SYSTEM

b. 执行/export/servers/canal_admin/conf下的sql语句
cat canal_manager.sql
进入mysql,copy sql文件里的所有sql,直接执行

c.创建一个同步用的数据库
CREATE USER canal IDENTIFIED BY ‘123456’;
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON . TO ‘canal’@’%’;
– GRANT ALL PRIVILEGES ON . TO ‘canal’@’%’ ;
FLUSH PRIVILEGES;

4.启动canal-admin

cd /tmp/canal_admin/bin
sh startup.sh

5.浏览器输入192.168.216.111:8089,输入用户名admin,密码123456
a.点击集群管理,新建集群(集群名称:canal_cluster ; zkurl:192.168.216.111:192.168.216.112:192.168.216.113:2181)

b.选择编辑集群配置,下拉选择主配置

具体代码如下(注:此时canal.destinations参数不需要配置,后面会讲到何时配置)
#################################################
######### 		common argument		#############
#################################################
# tcp bind ip
canal.ip =
# register ip to zookeeper
canal.register.ip =
canal.port = 11111
canal.metrics.pull.port = 11112
# canal instance user/passwd
canal.user = canal
canal.passwd = E3619321C1A937C46A0D8BD1DAC39F93B27D4458

# canal admin config
canal.admin.manager = 192.168.216.111:8089
canal.admin.port = 11110
canal.admin.user = admin
canal.admin.passwd = 6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9

canal.zkServers = 192.168.216.111:2181,192.168.216.112:2181,192.168.216.113:2181
# flush data to zk
canal.zookeeper.flush.period = 1000
canal.withoutNetty = false
# tcp, kafka, RocketMQ
canal.serverMode = RocketMQ
# flush meta cursor/parse position to file
canal.file.data.dir = ${canal.conf.dir}
canal.file.flush.period = 1000
## memory store RingBuffer size, should be Math.pow(2,n)
canal.instance.memory.buffer.size = 16384
## memory store RingBuffer used memory unit size , default 1kb
canal.instance.memory.buffer.memunit = 1024 
## meory store gets mode used MEMSIZE or ITEMSIZE
canal.instance.memory.batch.mode = MEMSIZE
canal.instance.memory.rawEntry = true

## detecing config
canal.instance.detecting.enable = false
#canal.instance.detecting.sql = insert into retl.xdual values(1,now()) on duplicate key update x=now()
canal.instance.detecting.sql = select 1
canal.instance.detecting.interval.time = 3
canal.instance.detecting.retry.threshold = 3
canal.instance.detecting.heartbeatHaEnable = false

# support maximum transaction size, more than the size of the transaction will be cut into multiple transactions delivery
canal.instance.transaction.size =  1024
# mysql fallback connected to new master should fallback times
canal.instance.fallbackIntervalInSeconds = 60

# network config
canal.instance.network.receiveBufferSize = 16384
canal.instance.network.sendBufferSize = 16384
canal.instance.network.soTimeout = 30

# binlog filter config
canal.instance.filter.druid.ddl = true
canal.instance.filter.query.dcl = false
canal.instance.filter.query.dml = false
canal.instance.filter.query.ddl = false
canal.instance.filter.table.error = false
canal.instance.filter.rows = false
canal.instance.filter.transaction.entry = false

# binlog format/image check
canal.instance.binlog.format = ROW,STATEMENT,MIXED 
canal.instance.binlog.image = FULL,MINIMAL,NOBLOB

# binlog ddl isolation
canal.instance.get.ddl.isolation = false

# parallel parser config
canal.instance.parser.parallel = true
## concurrent thread number, default 60% available processors, suggest not to exceed Runtime.getRuntime().availableProcessors()
#canal.instance.parser.parallelThreadSize = 16
## disruptor ringbuffer size, must be power of 2
canal.instance.parser.parallelBufferSize = 256

# table meta tsdb info
canal.instance.tsdb.enable = true
canal.instance.tsdb.dir = ${canal.file.data.dir:../conf}/${canal.instance.destination:}
canal.instance.tsdb.url = jdbc:h2:${canal.instance.tsdb.dir}/h2;CACHE_SIZE=1000;MODE=MYSQL;
canal.instance.tsdb.dbUsername = canal
canal.instance.tsdb.dbPassword = 123456
# dump snapshot interval, default 24 hour
canal.instance.tsdb.snapshot.interval = 24
# purge snapshot expire , default 360 hour(15 days)
canal.instance.tsdb.snapshot.expire = 360

# aliyun ak/sk , support rds/mq
canal.aliyun.accessKey =
canal.aliyun.secretKey =

#################################################
######### 		destinations		#############
#################################################
canal.destinations = 
# conf root dir
canal.conf.dir = ../conf
# auto scan instance dir add/remove and start/stop instance
canal.auto.scan = true
canal.auto.scan.interval = 5

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.mode = manager
canal.instance.global.lazy = false
canal.instance.global.manager.address = ${canal.admin.manager}
#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

##################################################
######### 		     MQ 		     #############
##################################################
rocketmq.producer.group = test
rocketmq.enable.message.trace = false
rocketmq.customized.trace.topic =
rocketmq.namespace =
rocketmq.namesrv.addr = 192.168.216.111:9876,192.168.216.112:9876,192.168.216.113:9876
rocketmq.retry.times.when.send.failed = 0
rocketmq.vip.channel.enabled = false

安装canal服务端

1.创建文件夹canal,将canal.deployer-1.1.5.tar.gz解压到该目录
mkdir canal
tar -zxvf canal.deployer-1.1.5.tar.gz -C /tmp/canal

2.将canal_local.properties文件内容覆盖到canal.properties,并编辑canal.properties

# register ip
canal.register.ip =192.168.216.111

# canal admin config
canal.admin.manager = 192.168.216.111: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 = cancal_cluster

3.将canal文件夹发送到 另外2台机
scp -r canal root@hadoop02: /tmp/canal
scp -r canal root@hadoop03: /tmp/canal
并修改canal.properties中canal.register.ip参数为各自服务器ip,其余参数保持不变
hadoop02上 canal.register.ip = 192.168.216.112
hadoop03上 canal.register.ip = 192.168.216.113

4.分别启动三台服务器上的canal服务

cd /tmp/canal/bin
sh startup.sh

5.刷新浏览器,点击server管理,发现已自动注入三个实例