在 SharePoint Server 中管理分散式快取服務

適用于:yes-img-132013 yes-img-16 2016yes-img-192019 yes-img-se訂閱版本 no-img-sopMicrosoft 365 中的 SharePoint

若要在 SharePoint Server 的分散式快取服務上執行管理和操作工作,管理員必須執行特定、順序化的程序。 本文說明如何在分散式快取服務上處理數項管理和操作工作。

重要事項

The Distributed Cache service can end up in a nonfunctioning or unrecoverable state if you do not follow the procedures that are listed in this article. In extreme scenarios, you might have to rebuild the server farm. 針對 SharePoint Server 2019、2016 和 2013,分散式快取會依 Windows Server AppFabric 作為必要條件。 Do not administer the AppFabric Caching Service from the Services window in Administrative Tools in Control Panel. Do not use the applications in the folder named AppFabric for Windows Server on the Start menu. 不支援使用 SharePoint 分散式快取新增 AppFabric 的安全性。 針對SharePoint Server 訂閱版本,個別的 Windows Server AppFabric 產品已被取代,而該技術現在已在 SharePoint 內部整合。

重要事項

請不要使用含有符號 $ 的服務帳戶名稱。

分散式快取服務的 PowerShell Cmdlet 清單

SharePoint Server PowerShell 現已提供下列 PowerShell Cmdlet。

SharePoint Server 訂閱版本 Cmdlet APP Fabric Cmdlet 描述
New-SPCache New-Cache 在叢集執行時建立新的具名快取。
Get-SPCache Get-Cache 列出叢集中的所有快取和區域,以及每個區域所在的快取主機。 若沒有任何參數,則會傳回所有叢集快取及其主機區域詳細資料。 提供 Hostname 和 CachePort 參數時,只會針對指定的主機傳回快取和區域詳細資料。
Get-SPCacheStatistics Get-CacheStatistics 傳回快取或快取主機的統計資料。
Get-SPCacheHost Get-CacheHost 列出屬於快取叢集成員的所有快取主機服務。
Start-SPCacheCluster Start-CacheCluster 在叢集中的所有快取主機上啟動快取服務。 會先啟動潛在客戶主機。
Stop-SPCacheCluster Stop-CacheCluster 停止叢集中所有快取主機上的快取服務。
Import-SPCacheClusterConfig Import-CacheClusterConfig 從 XML 檔案匯入快取叢集組態詳細資料。
Export-SPCacheClusterConfig Export-CacheClusterConfig 將快取叢集組態匯出至 XML 檔案。
Get-SPCacheClusterHealth Get-CacheClusterHealth 傳回快取叢集中所有具名快取的健康情況統計資料。 這包括尚未配置的專案。
Use-SPCacheCluster Use-CacheCluster 將 PowerShell 會話的內容設定為特定快取叢集。
Get-SPCacheHostConfig Get-CacheHostConfig 取得快取叢集中的快取主機組態資訊。
Get-SPCacheClusterInfo Get-CacheClusterInfo 取得伺服器陣列中的快取叢集資訊。
Set-SPCacheClusterSecurity Set-CacheClusterSecurity 設定快取叢集安全性屬性。

啟動及停止分散式快取服務

執行維護和操作工作的管理員可能會需要啟動及停止分散式快取服務。 其中包括下列工作:

  • 在安裝時變更伺服器陣列的預設設定。 安裝時,會在所有 SharePoint 伺服器上啟動分散式快取服務。 管理員可能會想要停止伺服器陣列中某些伺服器的分散式快取服務。

  • 更新伺服器,而且 SharePoint Server 伺服器陣列中只有一部分散式快取伺服器。

停止快取會導致部分資料遺失。 摘要快取相依於分散式快取服務。 標記和文件活動只會儲存至摘要快取。 標記和文件活動不會留存在內容資料庫中。 當分散式快取服務停止時,標記和文件活動即遺失。 當分散式快取服務啟動,就會在摘要快取重新填入計時器工作執行時,進行重新填入。 維護標記和文件活動的方法之一,就是使用本文稍後的使用 PowerShell 指令碼執行分散式快取服務的正常關機所說明的方法。 使用分散式快取服務的正常關機方法時,會先將所有快取資料從一部伺服器移到另一部伺服器,然後才停止分散式快取服務。

注意事項

[!附註] 如果您的快取主機隸屬於快取叢集,請勿以此處說明的方法啟動或停止分散式快取服務。 請改為參閱本文稍後的在分散式快取叢集中新增或移除伺服器

使用管理中心來啟動及停止分散式快取服務

  1. In Central Administration, click Application Management.

  2. In Service Applications, click Manage Services on Server.

  3. On the Services on Server page, locate the Distributed Cache service.

  4. If the Distributed Cache service is started and you want to stop the service, under Action, click Stop. If the Distributed Cache service is stopped and you want to start the service, under Action, click Start.

使用 SharePoint 管理命令介面啟動分散式快取服務

在 SharePoint 管理命令介面 命令提示字元中執行下列命令:

$instanceName ="SPDistributedCacheService Name=SPCache"
$serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
$serviceInstance.Provision()

使用 SharePoint 管理命令介面停止分散式快取服務

在 SharePoint 管理命令介面 命令提示字元中執行下列命令:

$instanceName ="SPDistributedCacheService Name=SPCache"
$serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
$serviceInstance.Unprovision()

變更分散式快取服務的記憶體配置

SharePoint Server 安裝之後,會將伺服器上百分之 10 的總實體記憶體分派給分散式快取服務。 分散式快取服務會將一半的記憶體配置用於資料儲存 (又稱為快取大小),將另一半的記憶體配置用於記憶體管理額外負荷。 當快取的資料成長時,分散式快取服務就會使用完整百分之 10 的配置記憶體。

您應該在下列狀況增加分散式快取服務的記憶體配置:

  • 當您新增實體記憶體至伺服器時。 分散式快取服務不會自動重新計算那百分之 10 的記憶體配置,因此要增加伺服器上的總實體記憶體時,必須手動增加分散式快取服務的記憶體配置。

  • 當您的伺服器陣列有專用分散式快取伺服器時。 請使用下列方法來計算可以將多少記憶體分派給分散式快取服務:

    1. 判斷伺服器上的總實體記憶體。 就此例而言,我們會使用 16 GB 作為伺服器上可用的總實體記憶體。

    2. 保留 2 GB 記憶體給在快取主機上執行的其他程序和服務。 例如,16 GB - 2 GB = 14 GB。 這些剩餘的記憶體會配置給分散式快取服務。

    3. 將一半的剩餘記憶體轉換成 MB。 例如,14 GB/2 = 7 GB 或 7168 MB。 這就是分散式快取服務的快取大小。

    4. 依據情況,使用下列程序來更新記憶體配置。

變更分散式快取服務的記憶體配置

使用此程序來重新設定分散式快取服務快取大小的記憶體配置。

  1. (選用) 若要查看伺服器上分散式快取服務的現有記憶體配置,請在 SharePoint 管理命令介面 命令提示字元中執行下列命令:

    Use-SPCacheCluster
    Get-SPCacheHostConfig -HostName $Env:ComputerName
    

    其中:

    • 電腦名稱 為執行 SharePoint 管理命令介面 Cmdlet 的伺服器上電腦名稱。
  2. Stop the Distributed Cache service on all cache hosts. To stop the Distributed Cache service, go to Services on Server in Central Administration, and Stop the Distributed Cache service on all cache hosts in the farm.

  3. 若要重新設定分散式快取服務的快取大小,請僅在任何快取主機上於 SharePoint 管理命令介面 命令提示字元中執行下列命令一次:

    Update-SPDistributedCacheSize -CacheSizeInMB CacheSize
    

    其中:

    • 快取大小 是所分派的快取大小記憶體配置 (MB)。 在前面的範例中,針對總記憶體為 16 GB 的伺服器,計算出來的快取大小為 7168 MB。
  4. Restart the Distributed Cache service on all cache hosts. 若要重新啟動分散式快取服務,請前往管理中心的 [伺服器上的服務],然後 [啟動] 伺服器陣列所有快取主機上的分散式快取服務。

在分散式快取叢集中新增或移除伺服器

管理員可以在快取叢集中新增或移除伺服器,或者可能會想要將伺服器從快取叢集中移除、在伺服器上執行一些操作或維護工作,然後再將伺服器重新加入或新增至快取叢集。 When removing the server, the Distributed Cache service is stopped, then unregistered from the server. Unregistering the Distributed Cache service means that an administrator will not see the Distributed Cache service listed on the Services on Server page in Central Administration. Similarly, when a server is added, the Distributed Cache service is registered and then is started on the server. Registering the Distributed Cache service means that an administrator will see the Distributed Cache service listed on the Services on Server page in Central Administration.

使用下列程序可在快取叢集中新增和移除伺服器。 這些 SharePoint 管理命令介面 Cmdlet 會在所要新增或移除的伺服器上執行。

注意事項

[!附註] 執行下列程序之前,請先確保防火牆允許輸入 ICMP (ICMPv4) 流量通過。 如需詳細資訊,請參閱<防火牆設定考量>。

使用 SharePoint 管理命令介面將伺服器新增至快取叢集並啟動分散式快取服務

在 SharePoint 管理命令介面 命令提示字元中執行下列命令:

Add-SPDistributedCacheServiceInstance

使用 SharePoint 管理命令介面從快取叢集移除伺服器

在 SharePoint 管理命令介面 命令提示字元中執行下列命令:

Remove-SPDistributedCacheServiceInstance

重要事項

[!重要事項] 此程序會停止快取服務,而非保存的快取資料將會遺失。 如果您想要保存快取資料,請使用下一節說明的正常關機程序。

使用 PowerShell 指令碼執行分散式快取服務的正常關機

在 SharePoint Server 伺服器陣列中,當一或多個快取主機執行分散式快取服務時,就會存在快取叢集。 在 SharePoint Server 伺服器陣列中,有一個快取存在,而快取會跨越快取叢集。 將更新套用至伺服器時,系統管理員可能需要將快取的內容移到另一部快取主機。 若要避免與移動快取內容相關聯的資料遺失,您必須在下列程式中使用 PowerShell 腳本執行伺服器正常關機。 正常關機程序會將所有快取的資料,從執行正常關機程序的快取主機,傳輸至伺服器陣列中的另一部快取主機。 視快取中存在多少個項目而定,傳輸程序需要 15 分鐘或更多時間執行。

使用 PowerShell 指令碼執行分散式快取的正常關機

使用下列 PowerShell 指令碼來執行分散式快取伺服器的正常關閉,以便將快取的內容移到另一部快取主機。 請確定您指定正確的節點來關閉,並視需要變更腳本,為您的組織命名正確的參數。

注意事項

[!附註] 如果您在下列程序中使用 PowerShell 指令碼來執行正常關機,則不需要從快取叢集中移除快取主機。

注意事項

在SharePoint Server 訂閱版本中,請勿 ps 執行腳本以進行正常關機。 請改為使用 參數執行 Stop-SPDistributedCacheServiceInstance-Graceful 來執行它。

  1. 確認您是否符合下列基本需求:

  2. 複製下列變數宣告,並將它們貼到文字編輯器 (例如 [記事本]) 中。 請設定您組織特有的參數值。 儲存檔案,並將它命名為 GracefulShutdown.ps1

    注意事項

    您可以使用不同的檔案名,但必須將檔案儲存為副檔名為 的 ANSI 編碼文字檔 .ps1

    ## Settings you may want to change for your scenario ##
    $startTime = Get-Date
    $currentTime = $startTime
    $elapsedTime = $currentTime - $startTime
    $timeOut = 900
    Use-CacheCluster
    try
    {
        Write-Host "Shutting down distributed cache host."
     $hostInfo = Stop-CacheHost -Graceful -CachePort 22233 -ComputerName sp2016App.contoso.com
     while($elapsedTime.TotalSeconds -le $timeOut-and $hostInfo.Status -ne 'Down')
     {
         Write-Host "Host Status : [$($hostInfo.Status)]"
         Start-Sleep(5)
         $currentTime = Get-Date
         $elapsedTime = $currentTime - $startTime
         $hostInfo = Get-CacheHost -HostName SP2016app.contoso.com -CachePort 22233
     }
     Write-Host "Stopping distributed cache host was successful. Updating Service status in SharePoint."
     Stop-SPDistributedCacheServiceInstance
     Write-Host "To start service, please use Central Administration site."
    }
    catch [System.Exception]
    {
     Write-Host "Unable to stop cache host within 15 minutes." 
    }
    

    其中 sp2016App.contoso.com 是您所使用分散式快取伺服器的電腦功能變數名稱。

  3. 開啟 SharePoint 管理命令介面。

  4. 變更至您儲存檔案的目錄。

  5. 在 PowerShell 命令提示字元中,輸入下列命令:

    ./GracefulShutdown.ps1
    

    如需 PowerShell 腳本和 .ps1 檔案的詳細資訊,請參閱執行Windows PowerShell腳本

變更服務帳戶

第一次設定伺服器陣列時,伺服器陣列帳戶會設定為 AppFabric 快取服務/SharePoint 快取服務的服務帳戶。 分散式快取服務取決於AppFabric 快取服務/SharePoint 快取服務。 若要將 AppFabric 快取服務/SharePoint 快取服務的服務帳戶變更為受控帳戶:

選取要變更服務帳戶的服務。

  1. 建立受管理的帳戶。

  2. 將受控帳戶設定為 SharePoint 快取服務上的服務帳戶。 在 SharePoint 管理命令介面 命令提示字元中執行下列命令:

    $farm = Get-SPFarm
    $cacheService = $farm.Services | where {$_.Name -eq "SPCache"}
    $accnt = Get-SPManagedAccount -Identity domain_name\user_name
    $cacheService.ProcessIdentity.CurrentIdentityType = "SpecificUser"
    $cacheService.ProcessIdentity.ManagedAccount = $accnt
    $cacheService.ProcessIdentity.Update() 
    $cacheService.ProcessIdentity.Deploy()
    

    其中 Domain_name\user_name 是 SharePoint 受管理帳戶的功能變數名稱和使用者名稱。

使用 PowerShell 指令碼來微調分散式快取服務

監視

您可以監視分散式快取伺服器上的效能計數器,以進一步瞭解快取效能問題。 一些通常有助於針對問題進行疑難排解 的計數器 包括:

  1. 快取服務已用到 %cpu。

  2. 快取服務在 GC 中花費的 %時間。

  3. Total cache misses/sec - 此處的高值可能表示您的應用程式效能可能會受到影響,因為它無法從快取擷取資料。 可能的原因包括從快取收回和/或到期專案。

  4. 物件總數 - 讓您瞭解快取中有多少專案。 物件計數的顯著下降可能表示正在收回或到期。

  5. Total client reqs/sec - 此計數器有助於讓您瞭解從應用程式在快取伺服器上產生多少負載。 此處的低值通常表示快取伺服器外部的某種瓶頸 (可能在應用程式或網路) 中,因此快取伺服器上的負載很少。

  6. 已收回的物件總數 - 如果快取伺服器不斷收回專案,以在快取中為較新的物件騰出空間,通常表示您在快取伺服器上需要更多記憶體來保存應用程式的資料集。

  7. Total failure exceptions/sec and Total Retry exceptions/sec.

MaxConnectionsToServer 的分散式快取服務設定通常會根據主機電腦中使用的 CPU 數目調整。 例如,如果您使用多個核心,然後將 MaxConnectionsToServer 設定設為相同數目的 CPU,則電腦通常會使用太多記憶體並凍結。 調整 DistributedLogonTokenCacheDistributedViewStateCache 設定時會發生類似的問題。 預設設定為 20 毫秒,但在 20 毫秒設定中未發生權杖快取時,通常會發現例外狀況。 使用下列 PowerShell 腳本來變更 SharePoint Server 2016 和 SharePoint Server 2013 中最大連線和逾時的設定。

使用 PowerShell 指令碼來微調分散式快取服務

  1. 確認您是否符合下列基本需求:

  2. 複製下列變數宣告,並將它們貼到文字編輯器 (例如 [記事本]) 中。 請設定您組織特有的參數值。 儲存檔案,並將它命名為 MaxConnections.ps1

    注意事項

    您可以使用不同的檔案名,但必須將檔案儲存為副檔名為 的 ANSI 編碼文字檔 .ps1

    SharePoint Server 訂閱版本和SharePoint Server 2019 PowerShell 腳本

    Add-PSSnapin Microsoft.Sharepoint.Powershell -ea 0
    
    #DistributedLogonTokenCache
    $DLTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache
    $DLTC.MaxConnectionsToServer = 1
    $DLTC.requestTimeout = "3000"
    $DLTC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache $DLTC
    
    #DistributedViewStateCache
    $DVSC = Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache
    $DVSC.MaxConnectionsToServer = 1
    $DVSC.requestTimeout = "3000"
    $DVSC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache $DVSC
    
    #DistributedAccessCache
    $DAC = Get-SPDistributedCacheClientSetting -ContainerType DistributedAccessCache
    $DAC.MaxConnectionsToServer = 1
    $DAC.requestTimeout = "3000"
    $DAC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedAccessCache $DAC
    
    #DistributedActivityFeedCache
    $DAF = Get-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedCache
    $DAF.MaxConnectionsToServer = 1
    $DAF.requestTimeout = "3000"
    $DAF.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedCache $DAF
    
    #DistributedActivityFeedLMTCache
    $DAFC = Get-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedLMTCache
    $DAFC.MaxConnectionsToServer = 1
    $DAFC.requestTimeout = "3000"
    $DAFC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedLMTCache $DAFC
    
    #DistributedBouncerCache
    $DBC = Get-SPDistributedCacheClientSetting -ContainerType DistributedBouncerCache
    $DBC.MaxConnectionsToServer = 1
    $DBC.requestTimeout = "3000"
    $DBC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedBouncerCache $DBC
    
    #DistributedDefaultCache
    $DDC = Get-SPDistributedCacheClientSetting -ContainerType DistributedDefaultCache
    $DDC.MaxConnectionsToServer = 1
    $DDC.requestTimeout = "3000"
    $DDC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedDefaultCache $DDC
    
    #DistributedSearchCache
    $DSC = Get-SPDistributedCacheClientSetting -ContainerType DistributedSearchCache
    $DSC.MaxConnectionsToServer = 1
    $DSC.requestTimeout = "3000"
    $DSC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedSearchCache $DSC
    
    #DistributedSecurityTrimmingCache
    $DTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedSecurityTrimmingCache
    $DTC.MaxConnectionsToServer = 1
    $DTC.requestTimeout = "3000"
    $DTC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedSecurityTrimmingCache $DTC
    
    #DistributedServerToAppServerAccessTokenCache
    $DSTAC = Get-SPDistributedCacheClientSetting -ContainerType DistributedServerToAppServerAccessTokenCache
    $DSTAC.MaxConnectionsToServer = 1
    $DSTAC.requestTimeout = "3000"
    $DSTAC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedServerToAppServerAccessTokenCache $DSTAC
    
    #DistributedFileLockThrottlerCache
    $DFLTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedFileLockThrottlerCache
    $DFLTC.MaxConnectionsToServer = 1
    $DFLTC.requestTimeout = "3000"
    $DFLTC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedFileLockThrottlerCache $DFLTC
    
    #DistributedSharedWithUserCache
    $DSWUC = Get-SPDistributedCacheClientSetting -ContainerType DistributedSharedWithUserCache
    $DSWUC.MaxConnectionsToServer = 1
    $DSWUC.requestTimeout = "3000"
    $DSWUC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedSharedWithUserCache $DSWUC
    
    #DistributedUnifiedGroupsCache
    $DUGC = Get-SPDistributedCacheClientSetting -ContainerType DistributedUnifiedGroupsCache
    $DUGC.MaxConnectionsToServer = 1
    $DUGC.requestTimeout = "3000"
    $DUGC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedUnifiedGroupsCache $DUGC 
    
    #DistributedResourceTallyCache
    $DRTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedResourceTallyCache
    $DRTC.MaxConnectionsToServer = 1
    $DRTC.requestTimeout = "3000"
    $DRTC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedResourceTallyCache $DRTC
    
    #DistributedHealthScoreCache
    $DHSC = Get-SPDistributedCacheClientSetting -ContainerType DistributedHealthScoreCache
    $DHSC.MaxConnectionsToServer = 1
    $DHSC.requestTimeout = "3000"
    $DHSC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedHealthScoreCache $DHSC  
    
    #DistributedDbLevelFailoverCache
    $DDBFC = Get-SPDistributedCacheClientSetting -ContainerType DistributedDbLevelFailoverCache
    $DDBFC.MaxConnectionsToServer = 1
    $DDBFC.requestTimeout = "3000"
    $DDBFC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedDbLevelFailoverCache $DDBFC
    
    #DistributedEdgeHeaderCache
    $DEHC = Get-SPDistributedCacheClientSetting -ContainerType DistributedEdgeHeaderCache
    $DEHC.MaxConnectionsToServer = 1
    $DEHC.requestTimeout = "3000"
    $DEHC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedEdgeHeaderCache $DEHC
    
    #DistributedFileStorePerformanceTraceCache
    $DFSPTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedFileStorePerformanceTraceCache
    $DFSPTC.MaxConnectionsToServer = 1
    $DFSPTC.requestTimeout = "3000"
    $DFSPTC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedFileStorePerformanceTraceCache $DFSPTC
    
    #DistributedSPAbsBlobCache
    $DSPABSC = Get-SPDistributedCacheClientSetting -ContainerType DistributedSPAbsBlobCache
    $DSPABSC.MaxConnectionsToServer = 1
    $DSPABSC.requestTimeout = "3000"
    $DSPABSC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedSPAbsBlobCache $DSPABSC
    
    #DistributedSPCertificateValidatorCache
    $DSPCVC = Get-SPDistributedCacheClientSetting -ContainerType DistributedSPCertificateValidatorCache
    $DSPCVC.MaxConnectionsToServer = 1
    $DSPCVC.requestTimeout = "3000"
    $DSPCVC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedSPCertificateValidatorCache $DSPCVC
    
    #DistributedSPOAuthTokenCache
    $DSPOATC = Get-SPDistributedCacheClientSetting -ContainerType DistributedSPOAuthTokenCache
    $DSPOATC.MaxConnectionsToServer = 1
    $DSPOATC.requestTimeout = "3000"
    $DSPOATC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedSPOAuthTokenCache $DSPOATC
    
    #DistributedStopgapCache
    $DSGC = Get-SPDistributedCacheClientSetting -ContainerType DistributedStopgapCache
    $DSGC.MaxConnectionsToServer = 1
    $DSGC.requestTimeout = "3000"
    $DSGC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedStopgapCache $DSGC
    
    #DistributedUnifiedAppsCache
    $DUAC = Get-SPDistributedCacheClientSetting -ContainerType DistributedUnifiedAppsCache
    $DUAC.MaxConnectionsToServer = 1
    $DUAC.requestTimeout = "3000"
    $DUAC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedUnifiedAppsCache $DUAC
    
    #DistributedUnifiedAuditCache
    $DUAuC = Get-SPDistributedCacheClientSetting -ContainerType DistributedUnifiedAuditCache
    $DUAuC.MaxConnectionsToServer = 1
    $DUAuC.requestTimeout = "3000"
    $DUAuC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedUnifiedAuditCache $DUAuC
    

    SharePoint Server 2016 PowerShell 腳本

    Add-PSSnapin Microsoft.Sharepoint.Powershell -ea 0
    
    #DistributedLogonTokenCache
    $DLTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache
    $DLTC.MaxConnectionsToServer = 1
    $DLTC.requestTimeout = "3000"
    $DLTC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache $DLTC
    
    #DistributedViewStateCache
    $DVSC = Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache
    $DVSC.MaxConnectionsToServer = 1
    $DVSC.requestTimeout = "3000"
    $DVSC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache $DVSC
    
    #DistributedAccessCache
    $DAC = Get-SPDistributedCacheClientSetting -ContainerType DistributedAccessCache
    $DAC.MaxConnectionsToServer = 1
    $DAC.requestTimeout = "3000"
    $DAC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedAccessCache $DAC
    
    #DistributedActivityFeedCache
    $DAF = Get-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedCache
    $DAF.MaxConnectionsToServer = 1
    $DAF.requestTimeout = "3000"
    $DAF.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedCache $DAF
    
    #DistributedActivityFeedLMTCache
    $DAFC = Get-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedLMTCache
    $DAFC.MaxConnectionsToServer = 1
    $DAFC.requestTimeout = "3000"
    $DAFC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedLMTCache $DAFC
    
    #DistributedBouncerCache
    $DBC = Get-SPDistributedCacheClientSetting -ContainerType DistributedBouncerCache
    $DBC.MaxConnectionsToServer = 1
    $DBC.requestTimeout = "3000"
    $DBC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedBouncerCache $DBC
    
    #DistributedDefaultCache
    $DDC = Get-SPDistributedCacheClientSetting -ContainerType DistributedDefaultCache
    $DDC.MaxConnectionsToServer = 1
    $DDC.requestTimeout = "3000"
    $DDC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedDefaultCache $DDC
    
    #DistributedSearchCache
    $DSC = Get-SPDistributedCacheClientSetting -ContainerType DistributedSearchCache
    $DSC.MaxConnectionsToServer = 1
    $DSC.requestTimeout = "3000"
    $DSC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedSearchCache $DSC
    
    #DistributedSecurityTrimmingCache
    $DTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedSecurityTrimmingCache
    $DTC.MaxConnectionsToServer = 1
    $DTC.requestTimeout = "3000"
    $DTC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedSecurityTrimmingCache $DTC
    
    #DistributedServerToAppServerAccessTokenCache
    $DSTAC = Get-SPDistributedCacheClientSetting -ContainerType DistributedServerToAppServerAccessTokenCache
    $DSTAC.MaxConnectionsToServer = 1
    $DSTAC.requestTimeout = "3000"
    $DSTAC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedServerToAppServerAccessTokenCache $DSTAC
    
    #DistributedFileLockThrottlerCache
    $DFLTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedFileLockThrottlerCache
    $DFLTC.MaxConnectionsToServer = 1
    $DFLTC.requestTimeout = "3000"
    $DFLTC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedFileLockThrottlerCache $DFLTC
    
    #DistributedSharedWithUserCache
    $DSWUC = Get-SPDistributedCacheClientSetting -ContainerType DistributedSharedWithUserCache
    $DSWUC.MaxConnectionsToServer = 1
    $DSWUC.requestTimeout = "3000"
    $DSWUC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedSharedWithUserCache $DSWUC
    
    #DistributedUnifiedGroupsCache
    $DUGC = Get-SPDistributedCacheClientSetting -ContainerType DistributedUnifiedGroupsCache
    $DUGC.MaxConnectionsToServer = 1
    $DUGC.requestTimeout = "3000"
    $DUGC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedUnifiedGroupsCache $DUGC 
    
    #DistributedResourceTallyCache
    $DRTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedResourceTallyCache
    $DRTC.MaxConnectionsToServer = 1
    $DRTC.requestTimeout = "3000"
    $DRTC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedResourceTallyCache $DRTC
    
    #DistributedHealthScoreCache
    $DHSC = Get-SPDistributedCacheClientSetting -ContainerType DistributedHealthScoreCache
    $DHSC.MaxConnectionsToServer = 1
    $DHSC.requestTimeout = "3000"
    $DHSC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedHealthScoreCache $DHSC  
    

    SharePoint Server 2013 PowerShell 腳本

    Add-PSSnapin Microsoft.Sharepoint.Powershell -ea 0
    
    #DistributedLogonTokenCache
    $DLTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache
    $DLTC.MaxConnectionsToServer = 1
    $DLTC.requestTimeout = "3000"
    $DLTC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache $DLTC
    
    #DistributedViewStateCache
    $DVSC = Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache
    $DVSC.MaxConnectionsToServer = 1
    $DVSC.requestTimeout = "3000"
    $DVSC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache $DVSC
    
    #DistributedAccessCache
    $DAC = Get-SPDistributedCacheClientSetting -ContainerType DistributedAccessCache
    $DAC.MaxConnectionsToServer = 1
    $DAC.requestTimeout = "3000"
    $DAC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedAccessCache $DAC
    
    #DistributedActivityFeedCache
    $DAF = Get-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedCache
    $DAF.MaxConnectionsToServer = 1
    $DAF.requestTimeout = "3000"
    $DAF.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedCache $DAF
    
    #DistributedActivityFeedLMTCache
    $DAFC = Get-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedLMTCache
    $DAFC.MaxConnectionsToServer = 1
    $DAFC.requestTimeout = "3000"
    $DAFC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedLMTCache $DAFC
    
    #DistributedBouncerCache
    $DBC = Get-SPDistributedCacheClientSetting -ContainerType DistributedBouncerCache
    $DBC.MaxConnectionsToServer = 1
    $DBC.requestTimeout = "3000"
    $DBC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedBouncerCache $DBC
    
    #DistributedDefaultCache
    $DDC = Get-SPDistributedCacheClientSetting -ContainerType DistributedDefaultCache
    $DDC.MaxConnectionsToServer = 1
    $DDC.requestTimeout = "3000"
    $DDC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedDefaultCache $DDC
    
    #DistributedSearchCache
    $DSC = Get-SPDistributedCacheClientSetting -ContainerType DistributedSearchCache
    $DSC.MaxConnectionsToServer = 1
    $DSC.requestTimeout = "3000"
    $DSC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedSearchCache $DSC
    
    #DistributedSecurityTrimmingCache
    $DTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedSecurityTrimmingCache
    $DTC.MaxConnectionsToServer = 1
    $DTC.requestTimeout = "3000"
    $DTC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedSecurityTrimmingCache $DTC
    
    #DistributedServerToAppServerAccessTokenCache
    $DSTAC = Get-SPDistributedCacheClientSetting -ContainerType DistributedServerToAppServerAccessTokenCache
    $DSTAC.MaxConnectionsToServer = 1
    $DSTAC.requestTimeout = "3000"
    $DSTAC.channelOpenTimeOut = "3000"
    Set-SPDistributedCacheClientSetting -ContainerType DistributedServerToAppServerAccessTokenCache $DSTAC
    
  3. 開啟 SharePoint 管理命令介面。

  4. 變更至您儲存檔案的目錄。

  5. 在 PowerShell 命令提示字元中,輸入下列命令:

    ./MaxConnections.ps1
    

如需詳細資訊,請 參閱 Windows Server AppFabric 快取 (應用程式組態設定) 。 如需Windows PowerShell腳本和 .ps1 檔案的詳細資訊,請參閱執行Windows PowerShell腳本

修復快取主機

安裝、設定或維護活動期間,分散式快取服務可能會進入非運作狀態。 分散式快取服務非運作的證據會顯示在管理中心的狀況規則中,或是當使用者使用仰賴分散式快取的 SharePoint Server 功能時。 例如使用者「我的網站」上的新聞摘要會開始報告錯誤。 另外,管理員在執行 SharePoint 管理命令介面 Cmdlet 管理分散式快取服務時,可能會收到「cacheHostInfo 為 null 」的錯誤訊息。

修復快取主機有兩個步驟。

在非運作的分散式快取主機上,使用下列程序來還原分散式快取主機。

  1. 在 SharePoint 管理命令介面 命令提示字元中,執行 Remove-SPDistributedCacheServiceInstance Cmdlet。

  2. 在 SharePoint 管理命令介面 命令提示字元中,執行 Add-SPDistributedCacheServiceInstance Cmdlet。

    注意事項

    [!附註] 如果步驟 1 失敗,請以手動方式移除分散式快取服務,使用下列步驟。

    • 在 SharePoint 管理命令介面 命令提示字元中,輸入下列語法。

      $instanceName ="SPDistributedCacheService Name=SPCache"
      
      $serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
      
      If($serviceInstance -ne $null)
      {
      $serviceInstance.Delete()
      }
      
      
    • 手動刪除分散式快取服務之後,請再次執行步驟 2。

另請參閱

概念

規劃 SharePoint Server 中的摘要和分散式快取服務