在 Linux 上准备开发环境Prepare your development environment on Linux

若要在 Linux 开发计算机上部署和运行 Azure Service Fabric 应用程序,请安装运行时和常用 SDK。To deploy and run Azure Service Fabric applications on your Linux development machine, install the runtime and common SDK. 还可以安装用于 Java 和 .NET Core 开发的可选 SDK。You can also install optional SDKs for Java and .NET Core development.

本文中的步骤假设你在 Linux 上进行本地安装,或者使用 Service Fabric OneBox 容器映像 mcr.microsoft.com/service-fabric/onebox:latestThe steps in this article assume that you install natively on Linux or use the Service Fabric OneBox container image, mcr.microsoft.com/service-fabric/onebox:latest.

不支持在适用于 Linux 的 Windows 子系统上安装 Service Fabric 运行时和 SDK。Installing the Service Fabric runtime and SDK on Windows Subsystem for Linux is not supported. 可以使用受支持的 Azure Service Fabric 命令行接口 (CLI) 来管理托管在云中或本地其他位置的 Service Fabric 实体。You can manage Service Fabric entities hosted elsewhere in the cloud or on-premises with the Azure Service Fabric command-line interface (CLI), which is supported. 有关如何安装 CLI 的信息,请参阅设置 Service Fabric CLIFor information on how to install the CLI, see Set up the Service Fabric CLI.


支持使用以下操作系统版本进行开发。These operating system versions are supported for development.

  • Ubuntu 16.04 (Xenial Xerus)、18.04 (Bionic Beaver)Ubuntu 16.04 (Xenial Xerus), 18.04 (Bionic Beaver)

    确保已安装 apt-transport-https 包。Make sure that the apt-transport-https package is installed.

    sudo apt-get install apt-transport-https
  • Red Hat Enterprise Linux 7.4(Service Fabric 预览版支持)Red Hat Enterprise Linux 7.4 (Service Fabric preview support)

安装方法Installation methods

脚本安装 (Ubuntu)Script installation (Ubuntu)

为方便起见,我们提供了一个脚本用于连同 sfctl CLI 一起安装 Service Fabric 运行时和 Service Fabric 通用 SDK。For convenience, a script is provided to install the Service Fabric runtime and the Service Fabric common SDK along with the sfctl CLI. 在以下部分中执行手动安装步骤。Run the manual installation steps in the next section. 可以看到正在安装的组件和相关许可证。You see what is being installed and the associated licenses. 运行该脚本即认为你同意所要安装的所有软件的许可条款。Running the script assumes you agree to the licenses for all the software that is being installed.

成功运行脚本后,可以跳转到设置本地群集After the script runs successfully, you can skip to Set up a local cluster.

sudo curl -s https://raw.githubusercontent.com/Azure/service-fabric-scripts-and-templates/master/scripts/SetupServiceFabric/SetupServiceFabric.sh | sudo bash

手动安装Manual installation

有关手动安装 Service Fabric 运行时和通用 SDK,请遵照本指南的余下部分操作。For manual installation of the Service Fabric runtime and common SDK, follow the rest of this guide.

更新 APT 源或 Yum 存储库Update your APT sources or Yum repositories

若要通过 apt-get 命令行工具安装 SDK 和关联的运行时包,必须首先更新高级打包工具 (APT) 源。To install the SDK and associated runtime package via the apt-get command-line tool, you must first update your Advanced Packaging Tool (APT) sources.


  1. 打开终端。Open a terminal.

  2. dotnet 存储库添加到与发行版相对应的源列表。Add the dotnet repo to your sources list corresponding to your distribution.

    wget -q https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb
    sudo dpkg -i packages-microsoft-prod.deb
  3. 向 APT Keyring 添加新的 MS Open Tech Gnu 隐私防护(GnuPG 或 GPG)密钥。Add the new MS Open Tech Gnu Privacy Guard (GnuPG or GPG) key to your APT keyring.

    sudo curl -fsSL https://packages.microsoft.com/keys/msopentech.asc | sudo apt-key add -
  4. 向 APT Keyring 添加官方的 Docker GPG 密钥。Add the official Docker GPG key to your APT keyring.

    sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  5. 设置 Docker 存储库。Set up the Docker repository.

    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  6. 将 Azul JDK 密钥添加到 APT Keyring 并设置其存储库。Add Azul JDK Key to your APT keyring and setup its repository.

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0xB1998361219BD9C9
    sudo apt-add-repository "deb http://repos.azul.com/azure-only/zulu/apt stable main"
  7. 根据新添加的存储库刷新包列表。Refresh your package lists based on the newly added repositories.

    sudo apt-get update

Red Hat Enterprise Linux 7.4(Service Fabric 预览版支持)Red Hat Enterprise Linux 7.4 (Service Fabric preview support)

  1. 打开终端。Open a terminal.

  2. 下载并安装 Extra Packages for Enterprise Linux(EPEL)。Download and install Extra Packages for Enterprise Linux (EPEL).

    wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    sudo yum install epel-release-latest-7.noarch.rpm
  3. 将 EfficiOS RHEL7 包存储库添加到系统。Add the EfficiOS RHEL7 package repository to your system.

    sudo wget -P /etc/yum.repos.d/ https://packages.efficios.com/repo.files/EfficiOS-RHEL7-x86-64.repo
  4. 将 EfficiOS 包签名密钥导入到本地 GPG keyring。Import the EfficiOS package signing key to the local GPG keyring.

    sudo rpmkeys --import https://packages.efficios.com/rhel/repo.key
  5. 将 Azure RHEL 存储库添加到系统。Add the Azure RHEL repository to your system.

    curl https://packages.microsoft.com/config/rhel/7.4/prod.repo > ./microsoft-prod.repo
    sudo cp ./microsoft-prod.repo /etc/yum.repos.d/
  6. 安装 .NET SDK。Install the .NET SDK.

    yum install rh-dotnet20 -y

为本地群集安装并设置 Service Fabric SDKInstall and set up the Service Fabric SDK for a local cluster

更新源后,可安装 SDK。After you update your sources, you can install the SDK. 安装 Service Fabric SDK 包,确认安装,并同意许可协议。Install the Service Fabric SDK package, confirm the installation, and accept the license agreement.


sudo apt-get install servicefabricsdkcommon


以下命令自动接受 Service Fabric 包的许可证:The following commands automate accepting the license for Service Fabric packages:

echo "servicefabric servicefabric/accepted-eula-ga select true" | sudo debconf-set-selections
echo "servicefabricsdkcommon servicefabricsdkcommon/accepted-eula-ga select true" | sudo debconf-set-selections

Red Hat Enterprise Linux 7.4(Service Fabric 预览版支持)Red Hat Enterprise Linux 7.4 (Service Fabric preview support)

sudo yum install servicefabricsdkcommon

SDK 安装随附的 Service Fabric 运行时包含下表中所述的包。The Service Fabric runtime that comes with the SDK installation includes the packages in the following table.

DotNetCoreDotNetCore JavaJava PythonPython NodeJSNodeJS
UbuntuUbuntu AzulJDK 1.8AzulJDK 1.8 Implicit from npmImplicit from npm 最新latest
RHELRHEL - OpenJDK 1.8OpenJDK 1.8 Implicit from npmImplicit from npm 最新latest

设置本地群集Set up a local cluster

安装完成后,启动本地群集。Start a local cluster after the installation finishes.

  1. 运行群集安装程序脚本。Run the cluster setup script.

    sudo /opt/microsoft/sdk/servicefabric/common/clustersetup/devclustersetup.sh
  2. 打开 Web 浏览器,转到 Service Fabric Explorer (http://localhost:19080/Explorer)。Open a web browser and go to Service Fabric Explorer (http://localhost:19080/Explorer). 群集启动后,可以看到 Service Fabric Explorer 仪表板。When the cluster starts, you see the Service Fabric Explorer dashboard. 群集完全设置可能需要几分钟时间。It might take several minutes for the cluster to be completely set up. 如果浏览器无法打开该 URL 或者 Service Fabric Explorer 未显示系统已准备就绪,请等待几分钟,然后重试。If your browser fails to open the URL or if Service Fabric Explorer doesn't show that the system is ready, wait a few minutes and try again.

    Linux 上的 Service Fabric Explorer

    此时,能够部署预生成的 Service Fabric 应用程序包或基于来宾容器或来宾可执行文件的新应用程序包。Now you can deploy prebuilt Service Fabric application packages or new ones based on guest containers or guest executables. 若要使用 Java 或 .NET Core SDK 生成新服务,请遵循以下部分中的可选设置步骤操作。To build new services by using the Java or .NET Core SDKs, follow the optional setup steps that are provided in the next sections.


Linux 不支持独立的群集。Standalone clusters aren't supported in Linux.


如果有可用的 SSD 磁盘,建议配合使用 --clusterdataroot 与 devclustersetup.sh 来传递 SSD 文件夹路径,实现优异的性能。If you have an SSD disk available, we recommend to pass an SSD folder path by using --clusterdataroot with devclustersetup.sh for superior performance.

设置 Service Fabric CLISet up the Service Fabric CLI

Service Fabric CLI 包含用来与 Service Fabric 实体(包括群集和应用程序)交互的命令。The Service Fabric CLI has commands for interacting with Service Fabric entities, including clusters and applications. 若要安装 CLI,请按照 Service Fabric CLI 中的说明进行操作。To install the CLI, follow the instructions at Service Fabric CLI.

为容器和来宾可执行文件安装 Yeoman 生成器Set up Yeoman generators for containers and guest executables

Service Fabric 提供基架工具,可以借助此类工具,使用 Yeoman 模板生成器从终端创建 Service Fabric 应用程序。Service Fabric provides scaffolding tools that help you create Service Fabric applications from a terminal by using Yeoman template generators. 遵循以下步骤安装 Service Fabric Yeoman 模板生成器:Follow these steps to set up the Service Fabric Yeoman template generators:

  1. 在计算机上安装 Node.js 和 npm。Install Node.js and npm on your machine.

    sudo add-apt-repository "deb https://deb.nodesource.com/node_8.x $(lsb_release -s -c) main"
    sudo apt-get update
    sudo apt-get install nodejs
  2. 通过 npm 在计算机上安装 Yeoman 模板生成器。Install the Yeoman template generator from npm on your machine.

    sudo npm install -g yo
  3. 通过 npm 安装 Service Fabric Yeo 容器生成器和来宾可执行文件生成器。Install the Service Fabric Yeo container generator and guest executable generator from npm.

    sudo npm install -g generator-azuresfcontainer  # for Service Fabric container application
    sudo npm install -g generator-azuresfguest      # for Service Fabric guest executable application

安装生成器后,可通过运行 yo azuresfguestyo azuresfcontainer 分别创建来宾可执行文件或容器服务。After you install the generators, create guest executable or container services by running yo azuresfguest or yo azuresfcontainer, respectively.

设置 .NET Core 2.0 开发Set up .NET Core 2.0 development

安装用于 Ubuntu 的 .NET Core 2.0 SDK,开始创建 C# Service Fabric 应用程序Install the .NET Core 2.0 SDK for Ubuntu to start creating C# Service Fabric applications. NuGet.org 可为 .NET Core 2.0 Service Fabric 应用程序托管包,目前提供预览版。NuGet.org hosts packages for .NET Core 2.0 Service Fabric applications, currently in preview.

设置 Java 开发Set up Java development

若要使用 Java 生成 Service Fabric 服务,请安装 Gradle 以运行生成任务。To build Service Fabric services using Java, install Gradle to run build tasks. 运行以下命令来安装 Gradle。Run the below command to install Gradle. Service Fabric Java 库是从 Maven 拉取的。The Service Fabric Java libraries are pulled from Maven.

  • UbuntuUbuntu

    curl -s https://get.sdkman.io | bash
    sdk install gradle 5.1
  • Red Hat Enterprise Linux 7.4(Service Fabric 预览版支持)Red Hat Enterprise Linux 7.4 (Service Fabric preview support)

    sudo yum install java-1.8.0-openjdk-devel
    curl -s https://get.sdkman.io | bash
    sdk install gradle

还需要为 Java 可执行文件安装 Service Fabric Yeo 生成器。You also need to install the Service Fabric Yeo generator for Java executables. 确保已安装 Yeoman,然后运行以下命令:Make sure you have Yeoman installed, and then run the following command:

npm install -g generator-azuresfjava

安装 Eclipse 插件(可选)Install the Eclipse plug-in (optional)

可以在面向 Java 开发人员或 Java EE 开发人员的 Eclipse IDE 中安装用于 Service Fabric 的 Eclipse 插件。You can install the Eclipse plug-in for Service Fabric from within the Eclipse IDE for Java Developers or Java EE Developers. 可以使用 Eclipse,在 Service Fabric Java 应用程序的基础上创建 Service Fabric 来宾可执行应用程序和容器应用程序。You can use Eclipse to create Service Fabric guest executable applications and container applications in addition to Service Fabric Java applications.


Service Fabric 插件需要 Eclipse Neon 或更高版本。The Service Fabric plug-in requires Eclipse Neon or a later version. 请参阅此注意事项后面的说明,了解如何查看 Eclipse 的版本。See the instructions that follow this note for how to check your version of Eclipse. 如果安装的是较旧版本的 Eclipse,可以从 Eclipse 站点下载较新的版本。If you have an earlier version of Eclipse installed, you can download more recent versions from the Eclipse site. 建议不要在现有 Eclipse 安装版本的基础上进行安装(覆盖)。We recommend that you do not install on top of (overwrite) an existing installation of Eclipse. 可以先删除现有版本,然后再运行安装程序,也可以在另一目录中安装较新的版本。Either remove it before running the installer, or install the newer version in a different directory.

在 Ubuntu 上,建议直接从 Eclipse 站点进行安装,而不是使用包安装程序(aptapt-get)。On Ubuntu, we recommend installing directly from the Eclipse site rather than using a package installer (apt or apt-get). 这样做可确保获取最新版 Eclipse。Doing so ensures that you get the most current version of Eclipse. 可以安装面向 Java 开发人员或 Java EE 开发人员的 Eclipse IDE。You can install the Eclipse IDE for Java Developers or for Java EE Developers.

  1. 在 Eclipse 中,请确保已安装 Eclipse Neon 或更高版本,以及 Buildship 2.2.1 版或更高版本。In Eclipse, make sure that you have installed Eclipse Neon or later and Buildship version 2.2.1 or later. 可以通过选择“帮助” > “关于 Eclipse” > “安装详细信息”查看已安装组件的版本 。Check the versions of installed components by selecting Help > About Eclipse > Installation Details. 可以按 Eclipse Buildship:适用于 Gradle 的 Eclipse 插件中的说明更新 Buildship。You can update Buildship by using the instructions at Eclipse Buildship: Eclipse Plug-ins for Gradle.

  2. 若要安装 Service Fabric 插件,请选择“帮助” > “安装新软件” 。To install the Service Fabric plug-in, select Help > Install New Software.

  3. 在“使用”框中,输入 https://dl.microsoft.com/eclipse 。In the Work with box, enter https://dl.microsoft.com/eclipse.

  4. 选择“添加” 。Select Add.


  5. 选择 ServiceFabric 插件,然后选择“下一步” 。Select the ServiceFabric plug-in, and then select Next.

  6. 执行安装步骤。Perform the installation steps. 然后接受最终用户许可协议。Then accept the end-user license agreement.

如果已安装 Service Fabric Eclipse 插件,请确保使用最新版本。If you already have the Service Fabric Eclipse plug-in installed, make sure that you have the latest version. 通过选择“帮助” > “关于 Eclipse” > “安装详细信息”查看 。Check by selecting Help > About Eclipse > Installation Details. 然后,在已安装插件的列表中搜索 Service Fabric。如果可以使用更新的版本,请选择“更新”。Then search for Service Fabric in the list of installed plug-ins. Select Update if a newer version is available.

有关详细信息,请参阅使用适用于 Eclipse 的 Service Fabric 插件开发 Java 应用程序For more information, see Service Fabric plug-in for Eclipse Java application development.

更新 SDK 和运行时Update the SDK and runtime

若要更新到最新版本的 SDK 和运行时,请运行以下命令。To update to the latest version of the SDK and runtime, run the following commands.

sudo apt-get update
sudo apt-get install servicefabric servicefabricsdkcommon

若要从 Maven 更新 Java SDK 二进制文件,需在 build.gradle 文件中更新相应的二进制文件的版本详细信息,使之指向最新 版本。To update the Java SDK binaries from Maven, you need to update the version details of the corresponding binary in the build.gradle file to point to the latest version. 若要确切地了解需要在何处更新版本,请参阅 Service Fabric 入门示例中的任何 build.gradle 文件。To know exactly where you need to update the version, refer to any build.gradle file in the Service Fabric getting-started samples.


更新这些包可能导致本地开发群集停止运行。Updating the packages might cause your local development cluster to stop running. 按本文中的说明操作,在升级后重启本地群集。Restart your local cluster after an upgrade by following the instructions in this article.

删除 SDKRemove the SDK

若要删除 Service Fabric SDK,请运行以下命令。To remove the Service Fabric SDKs, run the following commands.

  • UbuntuUbuntu

    sudo apt-get remove servicefabric servicefabicsdkcommon
    npm uninstall -g generator-azuresfcontainer
    npm uninstall -g generator-azuresfguest
    sudo apt-get install -f
  • Red Hat Enterprise Linux 7.4(Service Fabric 预览版支持)Red Hat Enterprise Linux 7.4 (Service Fabric preview support)

    sudo yum remove servicefabric servicefabicsdkcommon
    npm uninstall -g generator-azuresfcontainer
    npm uninstall -g generator-azuresfguest

后续步骤Next steps