能否在本地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 - 安装基础依赖工具:
启动并设置Docker开机自启:sudo apt install curl apt-transport-https docker.io -ysudo systemctl start docker sudo systemctl enable docker
二、安装Service Fabric SDK和CLI
- 添加微软的软件源:
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" - 安装Service Fabric SDK:
sudo apt install service-fabric-sdk -y - 安装Service Fabric CLI(
sfctl,管理集群的核心工具):sudo apt install service-fabric-cli -y
三、创建本地开发集群
- 执行以下命令创建单节点本地集群(适合开发测试):
如果你需要多节点集群,把sudo sfctl cluster create --local --cluster-size 1--cluster-size改成3或5即可(注意多节点需要更多系统资源)。 - 验证集群是否正常运行:
- 打开浏览器访问
http://localhost:19080,就能看到Service Fabric Explorer界面,查看集群状态。 - 或者在终端执行命令检查健康状况:
sfctl cluster health
- 打开浏览器访问
四、部署你的.NET Core Service Fabric应用
- 打包应用:如果你是在Windows上开发的应用,可以用Visual Studio的“打包”功能生成应用包;如果是在Linux上开发,直接用Service Fabric SDK的命令打包:
(注意替换成你的应用路径和.NET版本)dotnet publish --configuration Release sfpkg create --package-path ./bin/Release/net6.0/publish --output-path ./myapp.sfpkg - 部署到本地集群:
- 上传应用包到集群:
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
- 上传应用包到集群:
小贴士
- 本地Linux集群仅用于开发测试,不要部署到生产环境。
- 如果遇到权限问题,操作
sfctl时记得加sudo。 - 确保集群需要的端口(19080、19000、8080等)没有被其他程序占用。
- .NET Core应用要确保编译为跨平台版本,或者针对Linux目标编译,避免运行时错误。
内容的提问来源于stack exchange,提问作者takayoshi
相关产品推荐
相关产品推荐

