You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否在本地Linux环境部署Azure Service Fabric集群及.NET Core应用?

在本地Linux环境运行Azure Service Fabric并创建集群的方案

当然可以!Azure Service Fabric完全支持在本地Linux环境搭建开发用的单节点或多节点集群,非常适合你测试.NET Core的Service Fabric应用。下面是具体的步骤和注意事项:

一、前置准备

首先确保你的Ubuntu系统满足官方要求(推荐18.04 LTS或20.04 LTS),然后安装必要的依赖:

  • 打开终端,先更新包列表:
    sudo apt update && sudo apt upgrade -y
    
  • 安装基础依赖工具:
    sudo apt install curl apt-transport-https docker.io -y
    
    启动并设置Docker开机自启:
    sudo systemctl start docker
    sudo systemctl enable docker
    

二、安装Service Fabric SDK和CLI

  1. 添加微软的软件源:
    curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
    sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/ubuntu/$(lsb_release -rs)/prod $(lsb_release -cs) main"
    
  2. 安装Service Fabric SDK:
    sudo apt install service-fabric-sdk -y
    
  3. 安装Service Fabric CLI(sfctl,管理集群的核心工具):
    sudo apt install service-fabric-cli -y
    

三、创建本地开发集群

  1. 执行以下命令创建单节点本地集群(适合开发测试):
    sudo sfctl cluster create --local --cluster-size 1
    
    如果你需要多节点集群,把--cluster-size改成3或5即可(注意多节点需要更多系统资源)。
  2. 验证集群是否正常运行:
    • 打开浏览器访问http://localhost:19080,就能看到Service Fabric Explorer界面,查看集群状态。
    • 或者在终端执行命令检查健康状况:
      sfctl cluster health
      

四、部署你的.NET Core Service Fabric应用

  1. 打包应用:如果你是在Windows上开发的应用,可以用Visual Studio的“打包”功能生成应用包;如果是在Linux上开发,直接用Service Fabric SDK的命令打包:
    dotnet publish --configuration Release
    sfpkg create --package-path ./bin/Release/net6.0/publish --output-path ./myapp.sfpkg
    
    (注意替换成你的应用路径和.NET版本)
  2. 部署到本地集群:
    • 上传应用包到集群:
      sfctl application package copy --path ./myapp.sfpkg --image-store-connection-string "file:///var/lib/servicefabric/images"
      
    • 注册应用类型:
      sfctl application provision --application-type-build-path myapp
      
    • 创建应用实例:
      sfctl application create --app-name fabric:/MyApp --app-type MyAppType --app-version 1.0.0
      
    你也可以用Visual Studio Code的Azure Service Fabric插件来完成这些操作,界面化操作更直观。

小贴士

  • 本地Linux集群仅用于开发测试,不要部署到生产环境。
  • 如果遇到权限问题,操作sfctl时记得加sudo。
  • 确保集群需要的端口(19080、19000、8080等)没有被其他程序占用。
  • .NET Core应用要确保编译为跨平台版本,或者针对Linux目标编译,避免运行时错误。

内容的提问来源于stack exchange,提问作者takayoshi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:04:06