解决java连接zookeeper很慢的问题

目录
  • java连接zookeeper很慢
  • 记一次惨痛的zookeeper连接教训

java连接zookeeper很慢

最近在学习zookeeper,但是在连接zookeeper服务端时很慢,每次都超过18s

在头条尝试搜索了一下这个问题,找到了答案

原因是在服务器端集群时,设置的host是使用hostname,而不是ip,且客户端没有配置hostname和ip的映射导致的问题,

在客户端加上第一张图中的ip映射关系即可,或者把服务端的server中的hostname换成ip即可

记一次惨痛的zookeeper连接教训

因为工作需要导致需要重启tomcat,结果重启一直不成功,tomcat每次都卡在一个地方,也没用报错信息。由于一直没头绪,所以暂时先放着,让tomcat自己在那卡着,哈哈哈~~~

后面,大概半小时过去查看tomcat日志发现出现了一个错误(第一次看到报错这么激动)

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘appInvestConsultaApiImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.linewell.invest.api.IInvestConsultaApi com.linewell.guide.api.invest.impl.AppInvestConsultaApiImpl.investConsultaApi; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘investConsultaAPI': FactoryBean threw exception on object creation; nested exception is org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server within timeout: 2000000
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory 1. g e t O b j e c t ( A b s t r a c t B e a n F a c t o r y . j a v a : 303 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t S i n g l e t o n B e a n R e g i s t r y . g e t S i n g l e t o n ( D e f a u l t S i n g l e t o n B e a n R e g i s t r y . j a v a : 230 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . d o G e t B e a n ( A b s t r a c t B e a n F a c t o r y . j a v a : 299 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . g e t B e a n ( A b s t r a c t B e a n F a c t o r y . j a v a : 194 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t L i s t a b l e B e a n F a c t o r y . p r e I n s t a n t i a t e S i n g l e t o n s ( D e f a u l t L i s t a b l e B e a n F a c t o r y . j a v a : 755 ) a t o r g . s p r i n g f r a m e w o r k . c o n t e x t . s u p p o r t . A b s t r a c t A p p l i c a t i o n C o n t e x t . f i n i s h B e a n F a c t o r y I n i t i a l i z a t i o n ( A b s t r a c t A p p l i c a t i o n C o n t e x t . j a v a : 757 ) a t o r g . s p r i n g f r a m e w o r k . c o n t e x t . s u p p o r t . A b s t r a c t A p p l i c a t i o n C o n t e x t . r e f r e s h ( A b s t r a c t A p p l i c a t i o n C o n t e x t . j a v a : 480 ) a t o r g . s p r i n g f r a m e w o r k . w e b . c o n t e x t . C o n t e x t L o a d e r . c o n f i g u r e A n d R e f r e s h W e b A p p l i c a t i o n C o n t e x t ( C o n t e x t L o a d e r . j a v a : 434 ) a t o r g . s p r i n g f r a m e w o r k . w e b . c o n t e x t . C o n t e x t L o a d e r . i n i t W e b A p p l i c a t i o n C o n t e x t ( C o n t e x t L o a d e r . j a v a : 306 ) a t o r g . s p r i n g f r a m e w o r k . w e b . c o n t e x t . C o n t e x t L o a d e r L i s t e n e r . c o n t e x t I n i t i a l i z e d ( C o n t e x t L o a d e r L i s t e n e r . j a v a : 106 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . S t a n d a r d C o n t e x t . l i s t e n e r S t a r t ( S t a n d a r d C o n t e x t . j a v a : 5157 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . S t a n d a r d C o n t e x t . s t a r t I n t e r n a l ( S t a n d a r d C o n t e x t . j a v a : 5680 ) a t o r g . a p a c h e . c a t a l i n a . u t i l . L i f e c y c l e B a s e . s t a r t ( L i f e c y c l e B a s e . j a v a : 145 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . C o n t a i n e r B a s e . a d d C h i l d I n t e r n a l ( C o n t a i n e r B a s e . j a v a : 1018 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . C o n t a i n e r B a s e . a d d C h i l d ( C o n t a i n e r B a s e . j a v a : 994 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . S t a n d a r d H o s t . a d d C h i l d ( S t a n d a r d H o s t . j a v a : 652 ) a t o r g . a p a c h e . c a t a l i n a . s t a r t u p . H o s t C o n f i g . d e p l o y D e s c r i p t o r ( H o s t C o n f i g . j a v a : 712 ) a t o r g . a p a c h e . c a t a l i n a . s t a r t u p . H o s t C o n f i g 1.getObject(AbstractBeanFactory.java:303) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:434) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5157) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5680) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1018) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:994) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:712) at org.apache.catalina.startup.HostConfig 1.getObject(AbstractBeanFactory.java:303)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)atorg.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:434)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5157)atorg.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5680)atorg.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)atorg.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1018)atorg.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:994)atorg.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)atorg.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:712)atorg.apache.catalina.startup.HostConfigDeployDescriptor.run(HostConfig.java:2003)
at java.util.concurrent.Executors R u n n a b l e A d a p t e r . c a l l ( E x e c u t o r s . j a v a : 511 ) a t j a v a . u t i l . c o n c u r r e n t . F u t u r e T a s k . r u n ( F u t u r e T a s k . j a v a : 266 ) a t j a v a . u t i l . c o n c u r r e n t . T h r e a d P o o l E x e c u t o r . r u n W o r k e r ( T h r e a d P o o l E x e c u t o r . j a v a : 1149 ) a t j a v a . u t i l . c o n c u r r e n t . T h r e a d P o o l E x e c u t o r RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor RunnableAdapter.call(Executors.java:511)atjava.util.concurrent.FutureTask.run(FutureTask.java:266)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)atjava.util.concurrent.ThreadPoolExecutorWorker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.linewell.invest.api.IInvestConsultaApi com.linewell.guide.api.invest.impl.AppInvestConsultaApiImpl.investConsultaApi; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘investConsultaAPI': FactoryBean threw exception on object creation; nested exception is org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server within timeout: 2000000
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor A u t o w i r e d F i e l d E l e m e n t . i n j e c t ( A u t o w i r e d A n n o t a t i o n B e a n P o s t P r o c e s s o r . j a v a : 561 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . a n n o t a t i o n . I n j e c t i o n M e t a d a t a . i n j e c t ( I n j e c t i o n M e t a d a t a . j a v a : 88 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . a n n o t a t i o n . A u t o w i r e d A n n o t a t i o n B e a n P o s t P r o c e s s o r . p o s t P r o c e s s P r o p e r t y V a l u e s ( A u t o w i r e d A n n o t a t i o n B e a n P o s t P r o c e s s o r . j a v a : 331 ) . . . 26 m o r e C a u s e d b y : o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . B e a n C r e a t i o n E x c e p t i o n : E r r o r c r e a t i n g b e a n w i t h n a m e ′ i n v e s t C o n s u l t a A P I ′ : F a c t o r y B e a n t h r e w e x c e p t i o n o n o b j e c t c r e a t i o n ; n e s t e d e x c e p t i o n i s o r g . I 0 I t e c . z k c l i e n t . e x c e p t i o n . Z k T i m e o u t E x c e p t i o n : U n a b l e t o c o n n e c t t o z o o k e e p e r s e r v e r w i t h i n t i m e o u t : 2000000 a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . F a c t o r y B e a n R e g i s t r y S u p p o r t . d o G e t O b j e c t F r o m F a c t o r y B e a n ( F a c t o r y B e a n R e g i s t r y S u p p o r t . j a v a : 175 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . F a c t o r y B e a n R e g i s t r y S u p p o r t . g e t O b j e c t F r o m F a c t o r y B e a n ( F a c t o r y B e a n R e g i s t r y S u p p o r t . j a v a : 103 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . g e t O b j e c t F o r B e a n I n s t a n c e ( A b s t r a c t B e a n F a c t o r y . j a v a : 1523 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . d o G e t B e a n ( A b s t r a c t B e a n F a c t o r y . j a v a : 251 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . g e t B e a n ( A b s t r a c t B e a n F a c t o r y . j a v a : 194 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t L i s t a b l e B e a n F a c t o r y . f i n d A u t o w i r e C a n d i d a t e s ( D e f a u l t L i s t a b l e B e a n F a c t o r y . j a v a : 1120 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t L i s t a b l e B e a n F a c t o r y . d o R e s o l v e D e p e n d e n c y ( D e f a u l t L i s t a b l e B e a n F a c t o r y . j a v a : 1044 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t L i s t a b l e B e a n F a c t o r y . r e s o l v e D e p e n d e n c y ( D e f a u l t L i s t a b l e B e a n F a c t o r y . j a v a : 942 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . a n n o t a t i o n . A u t o w i r e d A n n o t a t i o n B e a n P o s t P r o c e s s o r AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ... 26 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'investConsultaAPI': FactoryBean threw exception on object creation; nested exception is org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server within timeout: 2000000 at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103) at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1523) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)atorg.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)...26moreCausedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname′investConsultaAPI′:FactoryBeanthrewexceptiononobjectcreation;nestedexceptionisorg.I0Itec.zkclient.exception.ZkTimeoutException:Unabletoconnecttozookeeperserverwithintimeout:2000000atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175)atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)atorg.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1523)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessorAutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
… 28 more
Caused by: org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server within timeout: 2000000
at org.I0Itec.zkclient.ZkClient.connect(ZkClient.java:876)
at org.I0Itec.zkclient.ZkClient.(ZkClient.java:98)
at org.I0Itec.zkclient.ZkClient.(ZkClient.java:92)
at org.I0Itec.zkclient.ZkClient.(ZkClient.java:80)
at com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperClient.(ZkclientZookeeperClient.java:26)
at com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperTransporter.connect(ZkclientZookeeperTransporter.java:10)
at com.alibaba.dubbo.remoting.zookeeper.ZookeeperTransporter A d p a t i v e . c o n n e c t ( Z o o k e e p e r T r a n s p o r t e r Adpative.connect(ZookeeperTransporter Adpative.connect(ZookeeperTransporterAdpative.java)
at com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry.(ZookeeperRegistry.java:69)
at com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistryFactory.createRegistry(ZookeeperRegistryFactory.java:37)
at com.alibaba.dubbo.registry.support.AbstractRegistryFactory.getRegistry(AbstractRegistryFactory.java:94)
at com.alibaba.dubbo.registry.RegistryFactory A d p a t i v e . g e t R e g i s t r y ( R e g i s t r y F a c t o r y Adpative.getRegistry(RegistryFactory Adpative.getRegistry(RegistryFactoryAdpative.java)
at com.alibaba.dubbo.registry.integration.RegistryProtocol.refer(RegistryProtocol.java:240)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.refer(ProtocolFilterWrapper.java:60)
at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.refer(ProtocolListenerWrapper.java:63)
at com.alibaba.dubbo.rpc.Protocol A d p a t i v e . r e f e r ( P r o t o c o l Adpative.refer(Protocol Adpative.refer(ProtocolAdpative.java)
at com.alibaba.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:392)
at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:300)
at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:138)
at com.alibaba.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:65)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)
… 36 more

然后确认是zookeeper连接的问题,确认问题后该找原因咯,为什么之前没问题现在出现了,由于项目是采用dubbo框架,所以就去dubbo框架的配置文件中找问题

因为是在一个tomcat上跑多个项目,前两个项目部署成功到第三个就出错了,于是比较3个配置文件的差异,发现问题就在id为tzydZk这个上面了,于是ping了这个地址发现ping不通,说明服务器那边出问题了。结果一问,是服务器地址改动了。。。。。

简直无语。修改地址为新的服务器地址,搞定。

总结:dubbo+zookeeper在部署项目时,若出现卡主无响应情况,可以检查项目中的zookeeper是否能正常运行,此处会卡主很久是因为zookeeper设置的连接超时限制很长。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • java 中 zookeeper简单使用

    一.zookeeper的基本原理 数据模型,如下: ZooKeeper数据模型的结构与Unix文件系统很类似,整体上可以看作是一棵树,每个节点称做一个ZNode.每个ZNode都可以通过其路径唯一标识,比如上图中第三层的第一个ZNode,它的路径是/app1/c1.在每个ZNode上可存储少量数据(默认是1M, 可以通过配置修改,通常不建议在ZNode上存储大量的数据),这个特性非常有用.另外,每个ZNode上还存储了其Acl信息,这里需要注意,虽说ZNode的树形结构跟Unix文件系统很类似,

  • zookeeper服务优化的一些建议

    1.快照文件和事务日志文件分别挂在不同磁盘.zoo.cfg文件中,dataDir是存放快照数据的,dataLogDir是存放事务日志的.zookeeper更新操作过程:先写事务日志,再写内存,周期性落到磁盘(刷新内存到快照文件).事务日志的对写请求的性能影响很大,保证dataLogDir所在磁盘性能良好.没有竞争者. 2. 默认jvm没有配置Xmx.Xms等信息,可以在conf目录下创建java.env文件(内存堆空间一定要小于机器内存,避免使用swap) export JVMFLAGS="-X

  • java连接zookeeper实现zookeeper教程

    目录 java连接zookeeper实现zookeeper Java服务端连接Zookeeper,进行节点信息的获取,管理-整理成一个基本工具 添加依赖: <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.3.6</version> </dependency> 具体

  • java连接zookeeper的3种方式小结

    目录 java连接zookeeper3种方式 1.使用zookeeper原始api 2.使用ZkClient客户端连接,这种连接比较简单 3.使用curator连接 Java集成zookeeper笔记 一.引入zookeeper-3.4.5.jar(原生zk包) 二.手写ZookeeperBase.java java连接zookeeper3种方式 1.使用zookeeper原始api public class Demo { private static String ip = "192.168.

  • 解决java连接zookeeper很慢的问题

    目录 java连接zookeeper很慢 记一次惨痛的zookeeper连接教训 java连接zookeeper很慢 最近在学习zookeeper,但是在连接zookeeper服务端时很慢,每次都超过18s 在头条尝试搜索了一下这个问题,找到了答案 原因是在服务器端集群时,设置的host是使用hostname,而不是ip,且客户端没有配置hostname和ip的映射导致的问题, 在客户端加上第一张图中的ip映射关系即可,或者把服务端的server中的hostname换成ip即可 记一次惨痛的zo

  • 解决java连接虚拟机Hbase无反应的问题

    目录 问题说明 代码如下 解决方案 1.由于Hbase自带有zookeeper 2.由于这里只是想测试下java连接hbae 3.再对zookeeper进行配置 zoo.cfg 4.因为是在windows环境下 问题说明 自己用虚拟机安装了Hbase.zookeeper,然后想用java访问. 代码如下 import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop

  • 解决远程连接mysql很慢的方法(mysql_connect 打开连接慢)

    在进行 ping和route后发现网络通信都是正常的,而且在mysql机器上进行本地连接发现是很快的,所以网络问题基本上被排除了.以前也遇到过一次这样的问题,可后来就不知怎么突然好了,这次又遭遇这样的问题,所以想看看是不是mysql的配置问题.在查询mysql相关文档和网络搜索后,发现了一个配置似乎可以解决这样的问题,就是在mysql的配置文件中增加如下配置参数: [mysqld]skip-name-resolve 在linux下配置文件是/etc/my.cnf,在windows下配置文件是my

  • java连接HBase,连接不上报错can not resolve问题及解决

    目录 java连接HBase,连接不上报错can not resolve java连接Hbase异常 问题原因 解决办法 java连接HBase,连接不上报错can not resolve [INFO] [2020-06-23 21:30:16][org.apache.hadoop.hbase.client.RpcRetryingCaller - 165]Call exception, tries=10, retries=35, started=47508 ms ago, cancelled=f

  • 如何使用Java操作Zookeeper

    简介 Java操作Zookeeper有很多种方式,如zookeeper.zkclient.curator等等,下面介绍下使用zkclient的方式操作Zookeeper. Maven依赖: <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.11</version> </dependency&g

  • Java连接Redis全过程讲解

    目录 Java连接Redis 引入jar包 编写测试类 Jedis常用方法API 一.首先把 jedis-2.1.0.jar(jedis基础包) 二.创建 jedis对象 三.键操作 四.字符串操作 五.整数和浮点数操作 六.列表(List)操作 七.集合(Set)操作 八.哈希(Hash)操作 九.有序集合(Zsort)操作 十.排序操作 Java连接Redis Jedis Client是Redis官网推荐的一个面向java客户端,库文件实现了对redis各类API进行封装调用. 引入jar包

  • 解决java启动时报线程占用报错:Exception in thread “Thread-14“ java.net.BindException: Address already in use: bind

    目录 前言 1 异常 2 问题定位 2.1 第一种情况 2.2 第二种情况 2.3 第三种情况 3 问题原因 4 思考学习 总结 前言 本文提供三种不同的解决方式,也是三种不同的情况和思路 我的问题是在springboot整合了xxl-job一段时间后出现的.如果你程序里集成了xxl-job或者有需要配置其它端口的地方,这篇文章或许可以给你带来启发或者解决你的问题. 1 异常 启动项目后抛出异常,但是奇怪的是执行器在任务调度中心中注册成功,也能成功执行 . ____ _ __ _ _ /\\ /

随机推荐