1) 當成功的在Service Fabric集羣中部署了應用後,如何來訪問呢?若是是一個Web服務,它的URL又是什麼呢?前端
2) 當Service Fabric集羣中,服務之間如須要相互訪問?如何來設置反向代理的端口呢?若是在建立Service Fabric時沒有設定方向代理端口,如何來添加呢?node
問題一:默認狀況下,訪問應用的URL經過Service Fabric的集羣endpoint + 在發佈應用時候,所設定的端口號。 如http://sfdnstest01.chinanorth2.cloudapp.chinacloudapi.cn:8080shell
Service Fabric集羣的Endpoint能夠從Azure門戶中獲取:json
應用的端口號:則由發佈文件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中配置規則很是簡單。api
進入Load Balance的Azure 門戶頁面,導航到「Load balancing rules」 一欄,添加對應的端口規則便可,以下圖:瀏覽器
以上,及能夠設定完成SF集羣中應用的外部訪問端口。app
Azure Service Fabric的參考文檔部分:https://docs.azure.cn/zh-cn/service-fabric/service-fabric-tutorial-create-dotnet-app#configure-the-listening-port工具
建立 VotingWeb 前端服務後,Visual Studio 會隨機選擇服務偵聽的端口。 VotingWeb 服務充當此應用程序的前端並接受外部流量,所以讓咱們將此服務綁定到已知的固定端口。 服務清單聲明服務終結點。this
在解決方案資源管理器中,打開「VotingWeb/PackageRoot/ServiceManifest.xml」。 在「Resources」部分中查找「Endpoint」元素,並將「Port」值更改成 8080。 若要在本地部署和運行應用程序,應用程序偵聽端口必須爲打開狀態且在你的計算機上可用。
<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>
此外,更新投票項目中的應用程序 URL 屬性值,使 Web 瀏覽器在調試應用程序時打開到正確的端口。 在解決方案資源管理器中,選擇「Voting」項目並將「應用程序 URL」屬性更新爲 8080 。
問題二:如何查看反向代理端口是否已經配置,使用Service Fabric Explorer,查看Cluster節點中的Minifest。如截圖中的紅色框中是否有HttpApplicationGatewayEndpoint
節點。如圖中配置的反向代理端口爲19081
若是查看到當前的Service Fabric集羣中沒有配置反向代理端口,那如何來開啓呢?
1) 找到部署Service Fabric的模板。如沒有,則能夠到Azure 門戶中改Service Fabric的資源組中,查看部署歷史記錄,選擇正確的部署模板(此模板中包含SF集羣全部配置和參數)
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工具查看結果。
Service Fabric中反向代理端口設置參考文檔:https://docs.azure.cn/zh-cn/service-fabric/service-fabric-tutorial-create-dotnet-app#connect-the-services
下一步是鏈接這兩個服務,使前端 Web 應用程序獲取並設置來自後端服務的投票信息。
在如何與 Reliable Services 通訊方面,Service Fabric 是十分靈活的。 在單個應用程序中,可能會有經過 TCP 訪問的服務。 其餘服務也許能夠經過 HTTP REST API 訪問,以及可經過 Web 套接字訪問。 有關可用選項和相關權衡取捨的背景信息,請參閱與服務通訊。
本教程使用 ASP.NET Core Web API 和 Service Fabric 反向代理,以便 VotingWeb 前端 Web 服務可以與後端 VotingData 服務通訊。 反向代理默認配置爲使用端口 19081,應適用於本教程。 反向代理端口是在用於設置羣集的 Azure 資源管理器模板中設置的。 若要肯定使用哪一個端口,請在 Microsoft.ServiceFabric/clusters 資源中搜索羣集模板:
"nodeTypes": [ { ... "httpGatewayEndpointPort": "[variables('nt0fabricHttpGatewayPort')]", "isPrimary": true, "vmInstanceCount": "[parameters('nt0InstanceCount')]", "reverseProxyEndpointPort": "[parameters('SFReverseProxyPort')]" } ],
若要查找在本地開發羣集中使用的反向代理端口,請查看本地 Service Fabric 羣集清單中的 HttpApplicationGatewayEndpoint 元素:
- 打開一個瀏覽器窗口,並導航到 http://localhost:19080 以打開 Service Fabric Explorer 工具。
- 選擇「羣集」->「清單」。
- 記下 HttpApplicationGatewayEndpoint 元素端口。 默認狀況下,此端口應是 19081。 若是不是 19081,則須要更改如下 VotesController.cs 代碼的 GetProxyAddress 方法中的端口。
使用 ASP.NET Core Web API 前端服務和有狀態後端服務建立並部署應用程序: https://docs.azure.cn/zh-cn/service-fabric/service-fabric-tutorial-create-dotnet-app#connect-the-services