問題描述
Azure Service Fabric提供了PowerShell的指令來進行創建,管理資源,如Get-ServiceFabricClusterHealth 獲取當前集群的健康狀態,但這些命令都需要使用Connect-ServiceFabricCluster 先連接到集群。而在使用連接命令時候,始終連接不成功。本且是運行PowerShell命令的機器上已經安裝了SF的主要證書。通過添加 -debug命令查看輸出結果,不能連接成功的原因為認證失敗。[System.Fabric.FabricServerAuthenticationFailedException: FABRIC_E_SERVER_AUTHENTICATION_FAILED: 0x800b0109]
解決辦法
在Service Fabric證書頁面中,發現有安裝主要證書,和次要證書,當主要證書認證失敗時,嘗試通過次要證書連接SF集群。發現通過次要證書成功連接。
根據次要證書可以登錄成功,主要證書確不可以的情況,進一步的調研和測試,得出Azure Service Fabrics SDK 的默認證書加載行為是部署和使用過期日期最遠的已定義證書,而不管其主要或次要配置定義如何。以下的測試為兩個證書到期時間一樣,使用PowerShell連接的時候也是會選擇次要證書進行連接。如果需要讓Service Fabrics使用主要證書,則可以在創建證書的時候,讓主要證書的過期時間長一些。
主次證書信息(注意:過期時間一樣)
主要證書連接失敗
次要證書連接成功
附錄一: 錯誤消息
警告: Failed to contact Failover Manager Service, Attempting to contact FMM... False 詳細信息: System.Fabric.FabricServerAuthenticationFailedException: FABRIC_E_SERVER_AUTHENTICATION_FAILED: 0x800b0109 ---> System.Runtime.InteropServices.COMException: 異常來自 HRESULT:0x80071C44 在 System.Fabric.Interop.NativeClient.IFabricQueryClient11.EndGetPartitionList2(IFabricAsyncOperationContext context) 在 System.Fabric.FabricClient.QueryClient.GetPartitionListAsyncEndWrapper(IFabricAsyncOperationContext context) 在 System.Fabric.Interop.AsyncCallOutAdapter2`1.Finish(IFabricAsyncOperationContext context, Boolean expectedCompletedSynchronously) --- 內部異常堆棧跟蹤的結尾 ---
附錄二:Connect-ServiceFabricCluster完整命令
Connect-ServiceFabricCluster -ConnectionEndpoint 'sf-test.chinaeast2.cloudapp.chinacloudapi.cn:19000' ` >> -KeepAliveIntervalInSec 10 ` >> -X509Credential -ServerCertThumbprint 'your thumbprint' ` >> -FindType FindByThumbprint -FindValue 'your thumbprint' ` >> -StoreLocation CurrentUser -StoreName My -debug
參考資料
The Connect-ServiceFabricCluster cmdlet creates a connection to a Service Fabric cluster that allows you to run management actions for that cluster. After you connect to a cluster, you can view the settings of the connection by using the Get-ServiceFabricClusterConnection cmdlet.
To manage Service Fabric clusters, start Windows PowerShell by using the Run as administrator option.