2017-05-04 98 views
0

嘿,我試圖運行2春季啓動APS(尤里卡服務器&尤里卡客戶端)和1 postgresql數據庫在本地機器上的單獨碼頭集裝箱,我面臨一些與尤里卡問題客戶。尤里卡服務器和碼頭彈簧啓動應用程序

一切工作正常,如果我在碼頭集裝箱以外運行它們。

尤里卡服務器application.yml:

server: 
    port: 8070 

eureka: 
    instance: 
    hostname: localhost 
# prefer-ip-address: false 
    client: 
    registerWithEureka: false 
    fetchRegistry: false 
    serviceUrl: 
     defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ 

security: 
    basic: 
    enabled: true 
    user: 
    name: admin 
    password: admin 

尤里卡服務器Dockerfile:

FROM java:8 
EXPOSE 8070 
VOLUME /tmp 
ADD service-registry-0.0.1-SNAPSHOT.jar app.jar 
RUN sh -c 'touch /app.jar' 
ENV JAVA_OPTS="" 
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] 

尤里卡服務器泊塢窗運行:

docker run --rm -P --name xxx-service-registry -e "SPRING_PROFILES_ACTIVE=dev" -p 8070:8070 xxx/service-registry 

尤里卡客戶application.yml:

server: 
    port: 8020 

spring: 
    application: 
    name: eureka-client 
    profiles: 
    active: dev 

eureka: 
    enabled: true 
# instance: 
# leaseRenewalIntervalInSeconds: 1 
# leaseExpirationDurationInSeconds: 2 
    client: 
    registerWithEureka: true 
    fetchRegistry: true 
    serviceUrl: 
     defaultZone: http://admin:[email protected]/eureka/ 
# lease: 
#  duration: 5 

spring: 
    datasource: 
    platform: POSTGRESQL 
    url: jdbc:postgresql://xxx-database/yyy 
    username: yyy 
    password: yyy 

ribbon: 
    eureka: 
    enabled: true 

尤里卡客戶Dockerfile:

FROM java:8 
EXPOSE 8020 
VOLUME /tmp 
ADD eureka-client-0.0.1-SNAPSHOT.jar app.jar 
RUN sh -c 'touch /app.jar' 
ENV JAVA_OPTS="" 
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] 

尤里卡客戶搬運工運行:

docker run --rm -P --name xxx-eureka-client --link xxx-service-registry --link xxx-database -e "SPRING_PROFILES_ACTIVE=dev" -p 8020:8020 xxx/eureka-client 

所以我尤里卡服務器啓動時,我可以從我的本地機器訪問它http://localhost:8070/eureka/ 我的數據庫開始爲好吧,我也可以訪問它。 我尤里卡客戶開始,到數據庫的連接工作正常(用xxx-數據庫連接泊塢窗),但尤里卡服務器的連接與此失敗:

2017-05-04 17:40:38.409 INFO 7 --- [   main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0 
2017-05-04 17:40:38.418 INFO 7 --- [   main] o.s.c.n.eureka.InstanceInfoFactory  : Setting initial instance status as: STARTING 
2017-05-04 17:40:38.472 INFO 7 --- [   main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1 
2017-05-04 17:40:38.671 INFO 7 --- [   main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson 
2017-05-04 17:40:38.672 INFO 7 --- [   main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson 
2017-05-04 17:40:38.832 INFO 7 --- [   main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml 
2017-05-04 17:40:38.833 INFO 7 --- [   main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml 
2017-05-04 17:40:39.074 INFO 7 --- [   main] c.n.d.s.r.aws.ConfigClusterResolver  : Resolving eureka endpoints via configuration 
2017-05-04 17:40:39.112 INFO 7 --- [   main] com.netflix.discovery.DiscoveryClient : Disable delta property : false 
2017-05-04 17:40:39.112 INFO 7 --- [   main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null 
2017-05-04 17:40:39.112 INFO 7 --- [   main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false 
2017-05-04 17:40:39.112 INFO 7 --- [   main] com.netflix.discovery.DiscoveryClient : Application is null : false 
2017-05-04 17:40:39.112 INFO 7 --- [   main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true 
2017-05-04 17:40:39.112 INFO 7 --- [   main] com.netflix.discovery.DiscoveryClient : Application version is -1: true 
2017-05-04 17:40:39.113 INFO 7 --- [   main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server 
2017-05-04 17:40:39.215 ERROR 7 --- [   main] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error 

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused) 
    at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) 
    at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) 
    at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) 
    at com.sun.jersey.api.client.Client.handle(Client.java:652) 
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) 
    at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) 
    at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:509) 
    at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.getApplicationsInternal(AbstractJerseyEurekaHttpClient.java:194) 
    at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.getApplications(AbstractJerseyEurekaHttpClient.java:165) 
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) 
    at com.netflix.discovery.shared.transport.decorator.MetricsCollectingEurekaHttpClient.execute(MetricsCollectingEurekaHttpClient.java:73) 
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) 
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) 
    at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:118) 
    at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.execute(RedirectingEurekaHttpClient.java:79) 
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) 
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) 
    at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:119) 
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) 
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) 
    at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) 
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) 
    at com.netflix.discovery.DiscoveryClient.getAndStoreFullRegistry(DiscoveryClient.java:1013) 
    at com.netflix.discovery.DiscoveryClient.fetchRegistry(DiscoveryClient.java:927) 
    at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:408) 
    at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:266) 
    at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:262) 
    at org.springframework.cloud.netflix.eureka.CloudEurekaClient.<init>(CloudEurekaClient.java:60) 
    at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.eurekaClient(EurekaClientAutoConfiguration.java:225) 
    at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$6eaebe88.CGLIB$eurekaClient$1(<generated>) 
    at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$6eaebe88$$FastClassBySpringCGLIB$$fe359a98.invoke(<generated>) 
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) 
    at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$6eaebe88.eurekaClient(<generated>) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:345) 
    at org.springframework.cloud.context.scope.GenericScope$BeanLifecycleWrapper.getBean(GenericScope.java:359) 
    at org.springframework.cloud.context.scope.GenericScope.get(GenericScope.java:176) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:340) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 
    at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35) 
    at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getTargetObject(EurekaRegistration.java:133) 
    at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getEurekaClient(EurekaRegistration.java:122) 
    at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:56) 
    at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:37) 
    at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:73) 
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:175) 
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50) 
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:348) 
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:151) 
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:114) 
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:879) 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) 
    at xxx.AgregationApplication.main(AgregationApplication.java:17) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) 
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) 
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) 
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) 
Caused by: java.net.ConnectException: Connection refused (Connection refused) 
    at java.net.PlainSocketImpl.socketConnect(Native Method) 
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) 
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) 
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) 
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) 
    at java.net.Socket.connect(Socket.java:589) 
    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121) 
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) 
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144) 
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134) 
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610) 
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445) 
    at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) 
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) 
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) 
    at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173) 
    ... 77 common frames omitted 

2017-05-04 17:40:39.216 WARN 7 --- [   main] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused) 
2017-05-04 17:40:39.217 ERROR 7 --- [   main] com.netflix.discovery.DiscoveryClient : DiscoveryClient_AGREGATION/002efb573472:agregation:8020 - was unable to refresh its cache! status = Cannot execute request on any known server 

任何想法?謝謝 !

回答

1

先給默認區域在你的微服務這樣

eureka: 
    enabled: true 
# instance: 
# leaseRenewalIntervalInSeconds: 1 
# leaseExpirationDurationInSeconds: 2 
    client: 
    registerWithEureka: true 
    fetchRegistry: true 
    serviceUrl: 
     defaultZone: http://admin:[email protected]:8070/eureka/ 
# lease: 
#  duration: 5 

您可能忽略了提供的服務的端口。

相關問題