Bluemix上Eureka服务器的正确配置是什么

时间:2016-02-15 09:14:34

标签: spring-boot ibm-cloud netflix-eureka

我尝试使用Netflix的Eureka按照使用Spring和Bluemix设置微服务的说明来发现服务。 bootstrap.yml遵循spring.io/blog

中的说明

这一发现无效。运行时错误日志具有以下内容:

15/2/2016 08:26:11  OUT App Caused by: java.net.ConnectException: Connection refused
    15/2/2016 08:26:11  OUT App at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) ~[na:1.8.0-internal]
    15/2/2016 08:26:11  OUT App at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ~[na:1.8.0-internal]
    15/2/2016 08:26:11  OUT App at java.net.AbstractPlainSocketImpl.connect(Unknown Source) ~[na:1.8.0-internal]
    15/2/2016 08:26:11  OUT App at java.net.SocksSocketImpl.connect(Unknown Source) ~[na:1.8.0-internal]
    15/2/2016 08:26:11  OUT App at java.net.Socket.connect(Unknown Source) ~[na:1.8.0-internal]
    15/2/2016 08:26:11  OUT App at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117) ~[httpclient-4.5.1.jar!/:4.5.1]
    15/2/2016 08:26:11  OUT App at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177) ~[httpclient-4.5.1.jar!/:4.5.1]
    15/2/2016 08:26:11  OUT App at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144) ~[httpclient-4.5.1.jar!/:4.5.1]
    15/2/2016 08:26:11  OUT App at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:131) ~[httpclient-4.5.1.jar!/:4.5.1]
    15/2/2016 08:26:11  OUT App at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611) ~[httpclient-4.5.1.jar!/:4.5.1]
    15/2/2016 08:26:11  OUT App at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446) ~[httpclient-4.5.1.jar!/:4.5.1]
    15/2/2016 08:26:11  OUT App at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882) ~[httpclient-4.5.1.jar!/:4.5.1]
    15/2/2016 08:26:11  OUT App at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:117) ~[httpclient-4.5.1.jar!/:4.5.1]
    15/2/2016 08:26:11  OUT App at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55) ~[httpclient-4.5.1.jar!/:4.5.1]
    15/2/2016 08:26:11  OUT App at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173) ~[jersey-apache-client4-1.19.jar!/:1.19]
    15/2/2016 08:26:11  OUT App ... 19 common frames omitted
    15/2/2016 08:26:11  OUT App 2016-02-15 08:26:11.968  WARN 29 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_MFERESTSERVER/968a9f4f59be49cb9b395db8d4228e59 - registration failed java.net.ConnectException: Connection refused
    15/2/2016 08:26:11  OUT App com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused
    15/2/2016 08:26:11  OUT App at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.jar!/:1.19]
    15/2/2016 08:26:11  OUT App at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) ~[jersey-client-1.19.jar!/:1.19]
    15/2/2016 08:26:11  OUT App at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.3.8.jar!/:1.3.8]
    15/2/2016 08:26:11  OUT App at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.jar!/:1.19]
    15/2/2016 08:26:11  OUT App at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.jar!/:1.19]
    15/2/2016 08:26:11  OUT App at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~[jersey-client-1.19.jar!/:1.19]
    15/2/2016 08:26:11  OUT App at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570) ~[jersey-client-1.19.jar!/:1.19]
    15/2/2016 08:26:11  OUT App at com.netflix.discovery.DiscoveryClient.makeRemoteCall(DiscoveryClient.java:1562) ~[eureka-client-1.3.8.jar!/:1.3.8]
    15/2/2016 08:26:11  OUT App at com.netflix.discovery.DiscoveryClient.makeRemoteCallWithFollowRedirect(DiscoveryClient.java:1460) ~[eureka-client-1.3.8.jar!/:1.3.8]
    15/2/2016 08:26:11  OUT App at com.netflix.discovery.DiscoveryClient.makeRemoteCall(DiscoveryClient.java:1443) ~[eureka-client-1.3.8.jar!/:1.3.8]
    15/2/2016 08:26:11  OUT App at com.netflix.discovery.DiscoveryClient.makeRemoteCall(DiscoveryClient.java:1394) ~[eureka-client-1.3.8.jar!/:1.3.8]
    15/2/2016 08:26:11  OUT App at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:879) ~[eureka-client-1.3.8.jar!/:1.3.8]
    15/2/2016 08:26:11  OUT App at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:103) [eureka-client-1.3.8.jar!/:1.3.8]
    15/2/2016 08:26:11  OUT App at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [na:1.8.0-internal]
    15/2/2016 08:26:11  OUT App at java.util.concurrent.FutureTask.run(Unknown Source) [na:1.8.0-internal]
    15/2/2016 08:26:11  OUT App at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source) [na:1.8.0-internal]
    15/2/2016 08:26:11  OUT App at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [na:1.8.0-internal]
    15/2/2016 08:26:11  OUT App at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0-internal]
    15/2/2016 08:26:11  OUT App at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0-internal]
    15/2/2016 08:26:11  OUT App at java.lang.Thread.run(Unknown Source) [na:1.8.0-internal]
    15/2/2016 08:26:11  OUT App Caused by: java.net.ConnectException: Connection refused
    15/2/2016 08:26:11  OUT App at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) ~[na:1.8.0-internal]
    15/2/2016 08:26:11  OUT App at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ~[na

我的感觉是VCAP中有一些更新,所以我把它包括在内

System-Provided:
{
 "VCAP_SERVICES": {
  "user-provided": [
   {
    "credentials": {
     "password": "xxxxxx",
     "port": "10336",
     "uri": "xxxx10.dblayer.com",
     "user": "xxxxx"
    },
    "label": "user-provided",
    "name": "MongoDB by Compose-w9",
    "syslog_drain_url": "",
    "tags": []
   },
   {
    "credentials": {
     "uri": "http://eurekaServer.mybluemix.net"
    },
    "label": "user-provided",
    "name": "eureka-service",
    "syslog_drain_url": "",
    "tags": []
   }
  ]
 }
}

{
 "VCAP_APPLICATION": {
  "application_id": "xxdf3f0906",
  "application_name": "restServer",
  "application_uris": [
   "MfeRestServer.mybluemix.net"
  ],
  "application_version": "047127",
  "limits": {
   "disk": 1024,
   "fds": 16384,
   "mem": 1024
  },
  "name": "restServer",
  "space_id": "xxxxxxd89089d9",   
  "space_name": "xxxxxxxx", 
  "uris": [
   "MfeRestServer.mybluemix.net"
  ],
  "users": null,
  "version": "601cce96-5d69-4f06-9259-dadad8047127"
 }
}

User-Provided:
APPLICATION_PROFILE: mferestserver
SPRING_PROFILES_ACTIVE: cloud

Running Environment Variable Groups:
BLUEMIX_REGION: ibm:yp:us-south

Staging Environment Variable Groups:
BLUEMIX_REGION: ibm:yp:us-south

1 个答案:

答案 0 :(得分:1)

我在编写自己的eureka服务器和客户端时遇到了这个问题。这是因为客户端主机名和serviceUrl的配置。它必须是动态的才能托管在云上

以下是我在IBM Bluemix上运行我的Eureka服务器和客户端的示例

我使用了以下Cloud Foundry Environment变量并且它有效

对于Eureka客户端

eureka:
  client:
    serviceUrl:
      defaultZone: http://eurekaregistry.mybluemix.net/eureka/
  instance:
    hostname: ${CF_INSTANCE_IP:localhost}
    nonSecurePort: ${CF_INSTANCE_PORT:${PORT:${server.port:8888}}}

对于eureka服务器

eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://eurekaregistry2.mybluemix.net/eureka/

代码存储库