Azure Service Fabric提供了PowerShell的指令來進行建立,管理資源,如Get-ServiceFabricClusterHealth 獲取當前集羣的健康狀態,但這些命令都須要使用Connect-ServiceFabricCluster 先鏈接到集羣。而在使用鏈接命令時候,始終鏈接不成功。本且是運行PowerShell命令的機器上已經安裝了SF的主要證書。經過添加 -debug命令查看輸出結果,不能鏈接成功的緣由爲認證失敗。[System.Fabric.FabricServerAuthenticationFailedException: FABRIC_E_SERVER_AUTHENTICATION_FAILED: 0x800b0109]shell
在Service Fabric證書頁面中,發現有安裝主要證書,和次要證書,當主要證書認證失敗時,嘗試經過次要證書鏈接SF集羣。發現經過次要證書成功鏈接。api
根據次要證書能夠登陸成功,主要證書確不能夠的狀況,進一步的調研和測試,得出Azure Service Fabrics SDK 的默認證書加載行爲是部署和使用過時日期最遠的已定義證書,而無論其主要或次要配置定義如何。如下的測試爲兩個證書到期時間同樣,使用PowerShell鏈接的時候也是會選擇次要證書進行鏈接。若是須要讓Service Fabrics使用主要證書,則能夠在建立證書的時候,讓主要證書的過時時間長一些。app
主次證書信息(注意:過時時間同樣)測試
主要證書鏈接失敗spa
次要證書鏈接成功debug
警告: 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 -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.code
To manage Service Fabric clusters, start Windows PowerShell by using the Run as administrator option.blog