You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
username/password
canal.instance.dbUsername=canal
canal.instance.dbPassword=NWF3DPxKGGs+gj/XLdi6B269CTyLemfqagQg5D0nVMgPets7Zol6toOrbGLhMByRyQzkYUHWb9moSQiWrFZppw==
canal.instance.connectionCharset = UTF-8
enable druid Decrypt database password
canal.instance.
enableDruid=true
canal.instance.
pwdPublicKey
=MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAocbCrurZGbC5GArEHKlAfDSZi7gFBnd4yxOt0rwTqKBFzGyhtQLu5PRKjEiOXVa95aeIIBJ6OhC2f8FjqFUpawIDAQABAkAPejKaBYHrwUqUEEOe8lpnB6lBAsQIUFnQI
但是启动instance报错:
2020-12-29 18:31:23.483 [canal-instance-scan-0] INFO c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [canal.properties]
2020-12-29 18:31:23.483 [canal-instance-scan-0] INFO c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [canal_smart_transfer/instance.properties]
2020-12-29 18:31:23.484 [canal-instance-scan-0] WARN c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Could not load properties from class path resource [canal_smart_transfer/instance.properties]: class path resource [canal_smart_transfer/instance.properties] cannot be opened because it does not exist
2020-12-29 18:31:23.490 [canal-instance-scan-0] WARN o.s.context.support.ClassPathXmlApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'instance' defined in class path resource [spring/file-instance.xml]: Cannot resolve reference to bean 'eventParser' while setting bean property 'eventParser'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eventParser' defined in class path resource [spring/file-instance.xml]: Cannot create inner bean 'com.alibaba.otter.canal.parse.support.AuthenticationInfo#6a623670' of type [com.alibaba.otter.canal.parse.support.AuthenticationInfo] while setting bean property 'masterInfo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.alibaba.otter.canal.parse.support.AuthenticationInfo#6a623670' defined in class path resource [spring/file-instance.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to get public key
2020-12-29 18:31:23.491 [canal-instance-scan-0] ERROR c.a.o.canal.instance.spring.SpringCanalInstanceGenerator - generator instance failed.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'instance' defined in class path resource [spring/file-instance.xml]: Cannot resolve reference to bean 'eventParser' while setting bean property 'eventParser'; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'eventParser' defined in class path resource [spring/file-instance.xml]: Cannot create inner bean 'com.alibaba.otter.canal.parse.support.AuthenticationInfo#6a623670' of type
[com.alibaba.otter.canal.parse.support.AuthenticationInfo] while setting bean property 'masterInfo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.alibaba.otter.canal.parse.support.AuthenticationInfo#6a623670' defined in class path resource [spring/file-instance.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to get public key
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:334) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1419) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:638) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:942) ~[spring-context-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[spring-context-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) ~[spring-context-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83) ~[spring-context-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at com.alibaba.otter.canal.instance.manager.PlainCanalInstanceGenerator.getBeanFactory(PlainCanalInstanceGenerator.java:71) ~[canal.instance.manager-1.1.4.jar:na]
at com.alibaba.otter.canal.instance.manager.PlainCanalInstanceGenerator.generate(PlainCanalInstanceGenerator.java:52) ~[canal.instance.manager-1.1.4.jar:na]
at com.alibaba.otter.canal.deployer.CanalController$5.generate(CanalController.java:388) [canal.deployer-1.1.4.jar:na]
at com.alibaba.otter.canal.server.embedded.CanalServerWithEmbedded$1.apply(CanalServerWithEmbedded.java:85) [canal.server-1.1.4.jar:na]
at com.alibaba.otter.canal.server.embedded.CanalServerWithEmbedded$1.apply(CanalServerWithEmbedded.java:82) [canal.server-1.1.4.jar:na]
at com.google.common.collect.ComputingConcurrentHashMap$ComputingValueReference.compute(ComputingConcurrentHashMap.java:356) [guava-18.0.jar:na]
at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.compute(ComputingConcurrentHashMap.java:182) [guava-18.0.jar:na]
at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.getOrCompute(ComputingConcurrentHashMap.java:151) [guava-18.0.jar:na]
at com.google.common.collect.ComputingConcurrentHashMap.getOrCompute(ComputingConcurrentHashMap.java:67) [guava-18.0.jar:na]
at com.google.common.collect.MapMaker$ComputingMapAdapter.get(MapMaker.java:885) [guava-18.0.jar:na]
at com.alibaba.otter.canal.server.embedded.CanalServerWithEmbedded.start(CanalServerWithEmbedded.java:137) [canal.server-1.1.4.jar:na]
at com.alibaba.otter.canal.deployer.CanalController$2$1.processActiveEnter(CanalController.java:160) [canal.deployer-1.1.4.jar:na]
at com.alibaba.otter.canal.common.zookeeper.running.ServerRunningMonitor.processActiveEnter(ServerRunningMonitor.java:247) [canal.common-1.1.4.jar:na]
at com.alibaba.otter.canal.common.zookeeper.running.ServerRunningMonitor.start(ServerRunningMonitor.java:104) [canal.common-1.1.4.jar:na]
at com.alibaba.otter.canal.deployer.CanalController$3.start(CanalController.java:248) [canal.deployer-1.1.4.jar:na]
at com.alibaba.otter.canal.deployer.monitor.ManagerInstanceConfigMonitor.notifyStart(ManagerInstanceConfigMonitor.java:129) [canal.deployer-1.1.4.jar:na]
at com.alibaba.otter.canal.deployer.monitor.ManagerInstanceConfigMonitor.lambda$scan$3(ManagerInstanceConfigMonitor.java:122) [canal.deployer-1.1.4.jar:na]
at java.util.ArrayList.forEach(ArrayList.java:1257) ~[na:1.8.0_242]
at com.alibaba.otter.canal.deployer.monitor.ManagerInstanceConfigMonitor.scan(ManagerInstanceConfigMonitor.java:121) [canal.deployer-1.1.4.jar:na]
at com.alibaba.otter.canal.deployer.monitor.ManagerInstanceConfigMonitor.access$000(ManagerInstanceConfigMonitor.java:29) [canal.deployer-1.1.4.jar:na]
at com.alibaba.otter.canal.deployer.monitor.ManagerInstanceConfigMonitor$2.run(ManagerInstanceConfigMonitor.java:53) ~[canal.deployer-1.1.4.jar:na]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_242]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) ~[na:1.8.0_242]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) ~[na:1.8.0_242]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) ~[na:1.8.0_242]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_242]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_242]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_242]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eventParser' defined in class path resource [spring/file-instance.xml]: Cannot create inner bean 'com.alibaba.otter.canal.parse.support.AuthenticationInfo#6a623670' of type [com.alibaba.otter.canal.parse.support.AuthenticationInfo] while setting bean property 'masterInfo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.alibaba.otter.canal.parse.support.AuthenticationInfo#6a623670' defined in class path resource [spring/file-instance.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to get public key
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:287) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:122) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1419) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
... 42 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.alibaba.otter.canal.parse.support.AuthenticationInfo#6a623670' defined in class path resource [spring/file-instance.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to get public key
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1514) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:276) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
... 52 common frames omitted
Caused by: java.lang.IllegalArgumentException: Failed to get public key
at com.alibaba.druid.filter.config.ConfigTools.getPublicKey(ConfigTools.java:101) ~[druid-1.1.9.jar:1.1.9]
at com.alibaba.druid.filter.config.ConfigTools.decrypt(ConfigTools.java:63) ~[druid-1.1.9.jar:1.1.9]
at com.alibaba.otter.canal.parse.support.AuthenticationInfo.initPwd(AuthenticationInfo.java:28) ~[canal.parse-1.1.4.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_242]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_242]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_242]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_242]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1640) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1581) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1511) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE]
... 55 common frames omitted
Caused by: java.lang.IllegalArgumentException: String length must be a multiple of four.
at com.alibaba.druid.util.Base64.base64ToByteArray(Base64.java:122) ~[druid-1.1.9.jar:1.1.9]
at com.alibaba.druid.util.Base64.base64ToByteArray(Base64.java:107) ~[druid-1.1.9.jar:1.1.9]
at com.alibaba.druid.filter.config.ConfigTools.getPublicKey(ConfigTools.java:94) ~[druid-1.1.9.jar:1.1.9]
... 64 common frames omitted
分析了一下代码,除了上面的bean加载失败的问题,感觉这个类的加解密也有点看不懂,是不是canal.instance.enableDruid配置成true这个功能不生效;
com.alibaba.druid.filter.config.ConfigTools.java
AuthenticationInfo.class
为什么解密用公钥呢?
this.password = ConfigTools.decrypt(pwdPublicKey, password);
依赖
Druid
实现工具类[ConfigTools]进行用户认证,即私钥进行签名,公钥进行认证(请先区分RSA 加密场景与RSA 签名场景)
从上面的报错来看,应该是传入的密码或公钥不对
详细生成公钥与密码方法,可参考以下DEMO
public static void main(String[] args) throws Exception {
String pwd = "123456";
// pair[0] -> privateKey
// pair[1] -> publicKey
String[] pair = ConfigTools.genKeyPair(512);
String privateKey = pair[0];
String publicKey = pair[1];
String enPwd = ConfigTools.encrypt(privateKey, pwd);
System.out.println("canal.instance.dbPassword=" + enPwd);
System.out.println("canal.instance.pwdPublicKey=" + publicKey);
System.out.println(ConfigTools.decrypt(publicKey, enPwd));
感谢解答,我知道为什么不行了,应该是把私钥当成公钥了,用了你给的方法可以了,谢谢
public static void main(String[] args) throws Exception {
String passwordStr = ConfigTools.encrypt(
"canal");
System.out.println(passwordStr);
下面这个DEFAULT_PRIVATE_KEY_STRING是私钥,我应该取这个ConfigTools文件里的DEFAULT_PUBLIC_KEY_STRING去配置文件里面配置,结果直接拿成DEFAULT_PRIVATE_KEY_STRING了,
public static String encrypt(String key, String plainText) throws Exception {
if (key == null) {
key = DEFAULT_PRIVATE_KEY_STRING;
byte[] keyBytes = Base64.base64ToByteArray(key);
return encrypt(keyBytes, plainText);
canal.instance.dbUsername=root
#连接的数据库的密码
canal.instance.dbPassword=rYpohrYRt9kh/VjQmkOEBU+qJFq3gxrxzR2TfDJoqVx5fSkKW+KSEHSD4USwox1Xno33coiw2d8GnbQhycXRSQ==
#连接的数据库的编码格式
canal.instance.connectionCharset = UTF-8
enable druid Decrypt database password
canal.instance.enableDruid=true
canal.instance.pwdPublicKey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAK/wdLkPgBwCU0L+1ZYw0+xEBX/RQE+YuiSpoM5nv+bkokFdqgX52td9YdA7phJ4zOOknthsoGL0U3OErSAFZd8CAwEAAQ==
enableDruid设置为true
pwdPublicKey要填写
dbPassword要写加密后的
pwdPublicKey和dbPassword都是自己用Druid工具生成的,和mysql端的PublicKey没关系。
还是有疑问,instance.properties可见,直接解密一下不就好了?