使用配置服务器和eureka

时间:2016-01-06 22:07:30

标签: spring-boot spring-cloud

我需要做些什么才能让我的Droplet(myapp)从configserver.local.lattice.cf上的正确服务获取其配置?

我可以部署redis,mysql,eureka和configserver。

我必须使用--privileged部署configserver才能使用我们的git存储库,因为它无法创建/ target / config目录。

现在我正在尝试部署我们的应用程序。

$ ltc --version
ltc version v0.6.0-34-g32acfa9 (diego 0.1434.0)

我使用以下示例部署了图像:http://lattice.cf/docs/docker-image-examples/

ltc create mysql mysql --memory-mb 512 --env MYSQL_ROOT_PASSWORD=password --tcp-route 3306:3306
...
ltc list
------------------------------= Apps =-------------------------------
App Name    Instances   DiskMB      MemoryMB    Route
configserver    1/1     0       512     configserver.local.lattice.cf => 8888, configserver-8888.local.lattice.cf => 8888
eureka      1/1     0       512     eureka.local.lattice.cf => 8761, eureka-8761.local.lattice.cf => 8761
mysql       1/1     0       512     local.lattice.cf:3306 => 3306
redis       1/1     0       256     local.lattice.cf:6379 => 6379

------------------------------= Tasks =------------------------------
No tasks to display.

我可以在eureka仪表板(eureka.local.lattice.cf)中看到configserver已经注册:

Instances currently registered with Eureka

Application AMIs    Availability Zones  Status
CONFIGSERVER    n/a (1) (1) UP (1) - 192.168.11.11

我也可以从configserver请求配置(configserver.local.lattice.cf/myapp/env)

{"name":"myapp","profiles":["env"],"label":"master","propertySources":[{"name":"overrides","source":{"eureka.instance.nonSecurePort":"${CF_INSTANCE_PORT:${PORT:${server.port:8080}}}","eureka.instance.hostname":"${CF_INSTANCE_IP:localhost}","eureka.client.serviceUrl.defaultZone":"http://eureka.local.lattice.cf/"}}
...

我使用以下命令创建Droplet,这是一个spring-boot应用程序:

ltc build-droplet myapp java -p ./target/myapp-0.0.1-SNAPSHOT.jar --env spring.cloud.config.uri=http://configserver.local.lattice.cf
Uploading application bits...
Uploaded.
Submitted build of myapp
01/06 15:43:38.08 [BUILD|0] Successfully created container
01/06 15:43:39.49 [DROPLET|0] Deleted http://local.lattice.cf:8444/blobs/myapp/bits.zip.
01/06 15:43:39.50 [DROPLET|0] Exit status 0
01/06 15:43:39.55 [BUILD|0] Exit status 0
01/06 15:43:43.90 [BUILD|0] -----> Java Buildpack Version: ab72dd5 | https://github.com/cloudfoundry/java-buildpack.git#ab72dd5
01/06 15:45:06.41 [BUILD|0] -----> Downloading Open Jdk JRE 1.8.0_65 from https://download.run.pivotal.io/openjdk/trusty/x86_64/openjdk-1.8.0_65.tar.gz (1m 22s)
01/06 15:45:07.47 [BUILD|0]        Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.0s)
01/06 15:45:09.34 [BUILD|0] -----> Downloading Open JDK Like Memory Calculator 2.0.1_RELEASE from https://download.run.pivotal.io/memory-calculator/trusty/x86_64/memory-calculator-2.0.1_RELEASE.tar.gz (1.8s)
01/06 15:45:09.38 [BUILD|0]        Memory Settings: -XX:MaxMetaspaceSize=64M -Xss568K -Xms54613K -XX:MetaspaceSize=64M -Xmx54613K
01/06 15:45:12.03 [BUILD|0] -----> Downloading Spring Auto Reconfiguration 1.10.0_RELEASE from https://download.run.pivotal.io/auto-reconfiguration/auto-reconfiguration-1.10.0_RELEASE.jar (2.6s)
01/06 15:45:21.94 [BUILD|0] Exit status 0
01/06 15:45:22.36 [DROPLET|0] Uploaded /tmp/droplet to http://local.lattice.cf:8444/blobs/myapp/droplet.tgz.
01/06 15:45:22.36 [DROPLET|0] Exit status 0
01/06 15:45:22.46 [DROPLET|0] Uploaded /tmp/result.json to http://local.lattice.cf:8444/blobs/myapp/result.json.
01/06 15:45:22.50 [DROPLET|0] Exit status 0
Build completed

到目前为止,事情看起来还不错?使用此env可提供相同的结果:

--env CONFIG_SERVER_URL=http://configserver.local.lattice.cf

当我尝试使用以下方式启动Droplet时

ltc launch-droplet myapp myapp

无法连接到配置服务器:

01/06 15:55:52.22 [APP|0] 2016-01-06 21:55:52.213  INFO 13 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
01/06 15:55:52.77 [APP|0] 2016-01-06 21:55:52.773  WARN 13 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/myapp/cloud":Connection refused; nested exception is java.net.ConnectException: Connection refused

1 个答案:

答案 0 :(得分:0)

我的问题的根本原因是我没有意识到"云"当发射具有晶格(ltc)的液滴时,轮廓是活跃的。

为了让我获得预期的结果,我必须在" myapp"中更新我的云配置文件。配置和默认的"应用程序"我设置的yaml文件。