问题描述
1) 当成功的在Service Fabric集群中部署了应用后,如何来访问呢?如果是一个Web服务,它的URL又是什么呢?
2) 当Service Fabric集群中,服务之间如需要相互访问?如何来设置反向代理的端口呢?如果在创建Service Fabric时没有设定方向代理端口,如何来添加呢?
问题解释
问题一:默认情况下,访问应用的URL通过Service Fabric的集群endpoint + 在发布应用时候,所设定的端口号。 如http://sfdnstest01.chinanorth2.cloudapp.chinacloudapi.cn:8080
Service Fabric集群的Endpoint可以从Azure门户中获取:
应用的端口号:则由发布文件ServiceManifest.xml中设定。如果已经发布后,可以在Service Fabric Explorer中查看Application的Minifest文件中发现
<Resources> <Endpoints> <!-- This endpoint is used by the communication listener to obtain the port on which to listen. Please note that if your service is partitioned, this port is shared with replicas of different partitions that are placed in your code. --> <Endpoint Protocol="http" Name="ServiceEndpoint" Type="Input" Port="8080" /> </Endpoints> </Resources>
还有非常重要的一步:在SF的Load Balance中开启访问此端口的规则。否则,通过浏览器访问时,就会得到“This site can’t be reached”的错误。在LB中配置规则非常简单。
进入Load Balance的Azure 门户页面,导航到“Load balancing rules” 一栏,添加对应的端口规则即可,如下图:
以上,及可以设定完成SF集群中应用的外部访问端口。
问题二:如何查看反向代理端口是否已经配置,使用Service Fabric Explorer,查看Cluster节点中的Minifest。如截图中的红色框中是否有HttpApplicationGatewayEndpoint
节点。如图中配置的反向代理端口为19081
如果查看到当前的Service Fabric集群中没有配置反向代理端口,那如何来开启呢?
Service Fabric反向代理端口开启步骤
1) 找到部署Service Fabric的模板。如没有,则可以到Azure 门户中改Service Fabric的资源组中,查看部署历史记录,选择正确的部署模板(此模板中包含SF集群所有配置和参数)
- 导航路径 (Azure Home -> Service Fabric Clusters -> Resource Group -> Deployment -> Template)
2) 在模板文件中查找nodeTypes节点并在其内添加 "reverseProxyEndpointPort":"19081" (可以根据自己需要调整端口号)
3) 重新部署,可以使用第一步中下载模板是自带的Powershell命令,也可以使用以下命令
az login az account set --subscription "your subscription id" az deployment group create --name deployment --resource-group "your resource group " --template-file .\exsitsf.json
4)部署完成后,通过Service Fabric Explorer工具查看结果。
参考资料
使用 ASP.NET Core Web API 前端服务和有状态后端服务创建并部署应用程序: https://docs.azure.cn/zh-cn/service-fabric/service-fabric-tutorial-create-dotnet-app#connect-the-services