下载安装
下载地址:
下载解压即可
配置
修改canal.admin-1.1.5\conf\application.yml
server:
port: 8089 #端口根据是否冲突修改
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
spring.datasource:
address: 192.0.16.12:3306#数据库ip和端口
database: canal_manager #默认会创建的数据库
username: canal
password: canal
driver-class-name: com.mysql.cj.jdbc.Driver #原配置是com.mysql.jdbc.Driver,但是Mysql 8的驱动类名是com.mysql.cj.jdbc.Driver,因此需要替换lib包下的msyql驱动包
url: jdbc:mysql://${spring.datasource.address}/${spring.datasource.database}?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai #增加Mysql8配置serverTimezonee=Asia/Shanghai
hikari:
maximum-pool-size: 30
minimum-idle: 1
canal:
adminUser: admin
adminPasswd: admin
替换lib包下的msyql驱动包
本地maven仓库找到mysql驱动jar,并替换掉lib目录下的mysql-connector-java-5.1.48.jar
执行conf/canal_manager.sql
会生成用于管理Canal的相关表
创建canal用户
#如果已有用户则不需要执行下面第一条语句
CREATE USER 'canal'@'%' IDENTIFIED BY 'canal';
# 赋予canal用户对于canal_manager库的所有操作权限
GRANT ALL PRIVILEGES ON canal_manager.* TO 'canal'@'%';
#刷新权限
FLUSH PRIVILEGES;
启动admin
进入bin目录,执行启动命令
./startup.sh
进入log目录查看日志信息,如下就是启动成功
2023-03-05 11:11:14.167 [main] INFO o.s.w.s.m.m.annotation.ExceptionHandlerExceptionResolver - Detected @ExceptionHandler methods in customExceptionHandler
2023-03-05 11:11:14.207 [main] INFO o.s.b.a.web.servlet.WelcomePageHandlerMapping - Adding welcome page: class path resource [public/index.html]
2023-03-05 11:11:14.489 [main] INFO o.s.jmx.export.annotation.AnnotationMBeanExporter - Registering beans for JMX exposure on startup
2023-03-05 11:11:14.493 [main] INFO o.s.jmx.export.annotation.AnnotationMBeanExporter - Bean with name 'dataSource' has been autodetected for JMX exposure
2023-03-05 11:11:14.498 [main] INFO o.s.jmx.export.annotation.AnnotationMBeanExporter - Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2023-03-05 11:11:14.510 [main] INFO org.apache.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-8090"]
2023-03-05 11:11:14.516 [main] INFO org.apache.tomcat.util.net.NioSelectorPool - Using a shared selector for servlet write/read
2023-03-05 11:11:14.530 [main] INFO o.s.boot.web.embedded.tomcat.TomcatWebServer - Tomcat started on port(s): 8090 (http) with context path ''
2023-03-05 11:11:14.535 [main] INFO com.alibaba.otter.canal.admin.CanalAdminApplication - Started CanalAdminApplication in 3.872 seconds (JVM running for 4.538)
登录
部署机器ip+配置端口即可访问
http://192.168.0.141:8089/
账户密码:admin 123456
配置canal-deployer
删除 canal.properties 将 canal_local.properties 重命名为 canal.properties, 添加配置:
# canal admin config
canal.admin.manager = 127.0.0.1:8090
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.admin.register.name =
然后进入canal.deployer-1.1.5/bin,使用./startup.sh命令启动canal服务端
此时canal服务端会自动注册到管理端
配置canal-adapter
参照之前博客中 配置客户端canal-adapter
canal实时同步mysql数据到elasticsearch(部署,配置,测试)(一)
canal-deployer启动可能遇到的问题
example config is not found
问题原因:注册到管理端后,会以管理端的instance配置为准,原canal.deployer-1.1.5/conf/example 会自动失效,这是因为管理端为了保证在集群状态下,多个节点使用的配置文件保持一致
2023-03-05 13:25:23.588 [main] ERROR c.a.o.c.common.zookeeper.running.ServerRunningMonitor - start failed
com.google.common.util.concurrent.UncheckedExecutionException: com.alibaba.otter.canal.common.CanalException: com.alibaba.otter.canal.common.CanalException: instance : example config is not found
需要在 Canal Admin 手动添加实例
然后重启canal-deployer,可以看到auto notify start 新建instance successful.
2023-03-08 14:41:22.220 [canal-instance-scan-0] INFO com.alibaba.otter.canal.deployer.CanalController - auto notify start 新建instance successful.
2023-03-08 14:41:41.865 [Thread-3] INFO com.alibaba.otter.canal.deployer.CanalStarter - ## stop the canal server
2023-03-08 14:41:42.515 [Thread-3] INFO com.alibaba.otter.canal.deployer.CanalController - ## stop the canal server[192.168.122.1(192.168.122.1):11111]
2023-03-08 14:41:42.521 [Thread-3] INFO com.alibaba.otter.canal.deployer.CanalStarter - ## canal server is down.
2023-03-08 14:41:43.428 [main] INFO com.alibaba.otter.canal.deployer.CanalLauncher - ## set default uncaught exception handler
2023-03-08 14:41:43.463 [main] INFO com.alibaba.otter.canal.deployer.CanalLauncher - ## load canal configurations
2023-03-08 14:41:43.879 [main] INFO com.alibaba.otter.canal.deployer.CanalStarter - ## start the canal server.
2023-03-08 14:41:43.921 [main] INFO com.alibaba.otter.canal.deployer.CanalController - ## start the canal server[192.168.122.1(192.168.122.1):11111]
2023-03-08 14:41:44.002 [main] INFO com.alibaba.otter.canal.deployer.CanalStarter - ## the canal server is running now ......
2023-03-08 14:41:45.319 [canal-instance-scan-0] INFO com.alibaba.otter.canal.deployer.CanalController - auto notify start 新建instance successful.
服务端的conf下也会出现新建的instance配置,并且其他目录下的配置会失效!
Error[INSERT command denied to user ‘canal’@‘192.168.0.119’ for table ‘canal_node_server’]
2023-03-05 12:21:50.590 [main] ERROR com.alibaba.otter.canal.deployer.CanalLauncher - ## Something goes wrong when starting up the canal Server:
com.alibaba.otter.canal.common.CanalException: load manager config failed.
Caused by: com.alibaba.otter.canal.common.CanalException: requestGet for canal config error: Error[INSERT command denied to user 'canal'@'192.168.0.119' for table 'canal_node_server']
原因:配置的 MySQL 账户没有具有 canal_manager 库的插入权限
解决:直接全部权限给过去
GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%';
java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ebeanServer' defined in class path resource [com/alibaba/otter/canal/admin/config/EbeanConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.ebean.EbeanServer]: Factory method 'ebeanServer' threw exception; nested exception is javax.persistence.PersistenceException: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:587)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1099)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
at com.alibaba.otter.canal.admin.CanalAdminApplication.main(CanalAdminApplication.java:19)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.ebean.EbeanServer]: Factory method 'ebeanServer' threw exception; nested exception is javax.persistence.PersistenceException: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:579)
... 16 common frames omitted
Caused by: javax.persistence.PersistenceException: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
解决方案:
修改/canal.admin-1.1.5/conf/application.yml的url,增加配置
&allowPublicKeyRetrieval=true
server中的状态为’断开’
应该是密码验证问题:
canal server 与 canal admin 的认证机制
canal admin 的 conf/application.yml 里面定义了账号密码明文
canal.adminUser: admin
canal.adminPasswd:admin
canal server 的 conf/canal_local.properties 里面定义了账号密码密文
canal.admin.user: admin
canal.admin.passwd:4ACFE3202A5FF5CF467898FC58AAB1D615029441
密文的生成方式: select password(‘xxxxxx’);
双向认证: canal server 向 canal admin 注册的时候会以密码密文做认证, canal admin 对 canal
server 做连通性测试的时候也会将密码明文加密之后做认证 (连通性测试失败的时候,canal admin web 会显示对应的
canal server 处于 “断开” 状态)
admin中的单机效果