介绍 Spring Cloud CLI Launcher

工程 | Spencer Gibb | 2016年11月2日 | ...

入门 Spring Cloud 可能会令人望而生畏。如果您看过 Josh Long 出色的《Cloud Native Java》演示文稿,您会注意到,在能看到您的应用程序运行时,您需要创建几个支持应用程序。

Spring Cloud CLI Launcher

在从 Spring XD 迁移到 Spring Cloud Dataflow 的过程中,一个被提取出来的项目叫做 Spring Cloud Deployer。Deployer 允许在各种平台上启动应用程序,包括在开发人员的机器上启动。

我们希望简化用户尝试 Spring Cloud 的能力,因此诞生了 spring cloud 命令。

spring cloud 命令会自动运行一些在 Spring Cloud 环境中运行应用程序所需的支撑服务器,例如配置服务器 (Config Server) 和 Eureka。

spring cloud logs

安装 Spring Boot CLI

第一步是安装 Spring Boot CLIspring 命令)。所需的最低版本是 1.4.1.RELEASE。我个人更喜欢 SDKMAN 方法

$ sdk install springboot
$ spring --version
Spring Boot v1.4.1.RELEASE

安装 Spring Cloud CLI

接下来,您需要通过 Spring Boot CLI 安装 Spring Cloud Launcher CLI(spring cloud 命令)。

$ spring install org.springframework.cloud:spring-cloud-cli:1.2.1.RELEASE

默认服务器

如果您在没有参数的情况下运行 spring cloud,它将启动配置服务器 (Config Server) 和 Eureka。配置服务器会先于其他服务启动,以便其他服务可以拉取它们的配置。

可启动的服务器

以下服务器可供启动:

$ spring cloud --list
configserver dataflow eureka h2 hystrixdashboard kafka zipkin

要运行一组特定的服务器,只需将它们作为参数列出即可。

$ spring cloud configserver eureka hystrixdashboard

前面的命令运行了配置服务器 (Config Server)、Eureka 和 Hystrix Dashboard。

用法

$ spring help cloud
spring cloud - Start Spring Cloud services, like Eureka, Config Server, etc.

Option         Description
------         -----------
-d, --debug    Debug logging for the deployer
-l, --list     List the deployables (don't launch
                 anything)
-v, --version  Show the version (don't launch

examples:

    Launch Eureka:
        $ spring cloud eureka

    Launch Config Server and Eureka:
        $ spring cloud configserver eureka

    List deployable apps:
        $ spring cloud --list

    Show version:
        $ spring cloud --version

配置进程

每个进程都可以使用具有特殊名称和位置的常规 Spring Boot 外部配置文件进行配置。文件名基于进程的名称(再次参见 spring cloud --list 获取完整列表)。例如,配置服务器 (Config Server) 可以配置在名为 configserver.ymlconfigserver.properties 的文件中。配置文件搜索路径是当前目录 (.)、./config$HOME/.spring-cloud/

默认情况下,configserver 进程使用其 JAR 中的 native profile 和配置。例如,让我们全局配置配置服务器 (Config Server) 以从 GitHub 存储库加载属性。$HOME/.spring-cloud/configserver.yml 的内容可以是:

spring:
  profiles:
    active: git
  cloud:
    config:
      server:
        git:
          uri: https://github.com/spring-cloud-samples/config-repo

进程信息

进程 端口 URL
configserver 8888 /info
eureka 8761 不适用
hystrixdashboard 7979 /hystrix
dataflow 9393 /dashboard
kafka 9092 不适用
zipkin 9411 不适用
h2 9095 /

URL 列是注册到 Eureka(如果正在运行)的内容。这允许您点击 Eureka Dashboard 中的实例链接。

Eureka Dashboard

如果一个进程注册到 Eureka,它将使用“进程”列中的值作为 spring.application.name

kafka 进程还在端口 2181 上启动 ZooKeeper。Kafka 用于 Spring Cloud Bus。

h2 数据库可通过端口 9096 访问,JDBC URL 为:jdbc:h2:tcp://:9096/./target/test。H2 URL 可以通过 spring.datasource.url 属性进行自定义。

结论

请在 GitHub 上查看该项目。团队非常欢迎社区的 issue 和功能增强请求。

获取 Spring 新闻通讯

通过 Spring 新闻通讯保持联系

订阅

领先一步

VMware 提供培训和认证,助您加速进步。

了解更多

获得支持

Tanzu Spring 提供 OpenJDK™、Spring 和 Apache Tomcat® 的支持和二进制文件,只需一份简单的订阅。

了解更多

即将举行的活动

查看 Spring 社区所有即将举行的活动。

查看所有