在 SharePoint Server 中管理分散式快取服務Manage the Distributed Cache service in SharePoint Server

摘要: 了解如何在 SharePoint Server 2013 和 SharePoint Server 2016 中設定及管理分散式快取服務。Summary: Learn how to configure and manage the Distributed Cache service in SharePoint Server 2013 and SharePoint Server 2016.

若要在 SharePoint Server 的分散式快取服務上執行管理和操作工作,管理員必須執行特定、順序化的程序。本文說明如何在分散式快取服務上處理數項管理和操作工作。To perform management and operational tasks on the Distributed Cache service in SharePoint Server, an administrator must perform specific, ordered procedures. This article describes how to conduct several management and operational tasks on the Distributed Cache service.

重要

分散式快取服務可以最後 nonfunctioning 或無法復原狀態如果您未依照本文所列的程序。在極端情況下,您可能必須重新建立伺服器陣列。分散式快取,取決於 Windows Server AppFabric 必要條件。執行動作無法管理AppFabric 快取服務[控制台] 中的系統管理工具] 中的 [服務] 視窗。在 [開始] 功能表上名為AppFabric for Windows Server資料夾中不使用應用程式。不支援新增安全性與 SharePoint appfabric 分散式快取。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. The Distributed Cache depends on Windows Server AppFabric as a prerequisite. 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. Adding security for AppFabric with SharePoint distributed cache is not supported.

重要

請不要使用含有符號 $ 的服務帳戶名稱。Do not use service account names that contain the symbol $.

啟動及停止分散式快取服務Start and stop the Distributed Cache service

執行維護和操作工作的管理員可能會需要啟動及停止分散式快取服務。其中包括下列工作:An administrator that performs maintenance and operational tasks might need to start and stop the Distributed Cache service. Some of these tasks include the following:

  • 在安裝時變更伺服器陣列的預設設定。安裝時,會在所有 SharePoint 伺服器上啟動分散式快取服務。管理員可能會想要停止伺服器陣列中某些伺服器的分散式快取服務。Changing the default configuration of the server farm at installation time. The Distributed Cache service is started on all SharePoint servers at installation time. An administrator might want to stop the Distributed Cache service on some servers in the farm.

  • 更新伺服器,而且 SharePoint Server 伺服器陣列中只有一部分散式快取伺服器。Updating the server and there is only one Distributed Cache server in the SharePoint Server farm.

停止快取會導致部分資料遺失。摘要快取相依於分散式快取服務。標記和文件活動只會儲存至摘要快取。標記和文件活動不會留存在內容資料庫中。當分散式快取服務停止時,標記和文件活動即遺失。當分散式快取服務啟動,就會在摘要快取重新填入計時器工作執行時,進行重新填入。維護標記和文件活動的方法之一,就是使用本文稍後的使用 PowerShell 指令碼執行分散式快取服務的正常關機所說明的方法。使用分散式快取服務的正常關機方法時,會先將所有快取資料從一部伺服器移到另一部伺服器,然後才停止分散式快取服務。Stopping the cache results in partial data loss. The Feed Cache depends on the Distributed Cache service. Tags and document activities are saved only to the Feed Cache. Tags and document activities are not persisted to content databases. When the Distributed Cache service is stopped, tags and document activities are lost. When the Distributed Cache service is started, repopulation occurs when the feed cache repopulation timer job runs. One way to maintain the tags and document activities is to use the method described in Perform a graceful shutdown of the Distributed Cache service by using a PowerShell script later in this article. When the graceful shutdown of the Distributed Cache service method is used, all cache data is moved from one server to another server before the Distributed Cache service is stopped.

注意

[!附註] 如果您的快取主機隸屬於快取叢集,請勿以此處說明的方法啟動或停止分散式快取服務。請改為參閱本文稍後的在分散式快取叢集中新增或移除伺服器If your cache hosts are part of a cache cluster, do not start or stop the Distributed Cache service as described here. Instead, see Add or remove a server in a Distributed Cache cluster later in this article.

使用管理中心來啟動及停止分散式快取服務To start and stop the Distributed Cache service by using Central Administration

  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 2016 管理命令介面 來啟動分散式快取服務To start the Distributed Cache service by using SharePoint 2016 Management Shell

在 SharePoint 管理命令介面 命令提示字元中執行下列命令:At the SharePoint Management Shell command prompt, run the following command:

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

使用 SharePoint 2016 管理命令介面 來停止分散式快取服務To stop the Distributed Cache service by using SharePoint 2016 Management Shell

在 SharePoint 管理命令介面 命令提示字元中執行下列命令:At the SharePoint Management Shell command prompt, run the following command:

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

變更分散式快取服務的記憶體配置Change the memory allocation of the Distributed Cache service

SharePoint Server 安裝之後,會將伺服器上百分之 10 的總實體記憶體分派給分散式快取服務。分散式快取服務會將一半的記憶體配置用於資料儲存 (又稱為快取大小),將另一半的記憶體配置用於記憶體管理額外負荷。當快取的資料成長時,分散式快取服務就會使用完整百分之 10 的配置記憶體。When SharePoint Server is installed, it assigns the Distributed Cache service 10 percent of the total physical memory on the server. The Distributed Cache service uses half of that memory allocation for data storage (also known as cache size), and the other half of that memory allocation is used for memory management overhead. When the cached data grows, the Distributed Cache service uses the entire 10 percent of the allocated memory.

您應該在下列狀況增加分散式快取服務的記憶體配置:You should increase the memory allocation of the Distributed Cache service in these scenarios:

  • 當您新增實體記憶體至伺服器時。分散式快取服務不會自動重新計算那百分之 10 的記憶體配置,因此要增加伺服器上的總實體記憶體時,必須手動增加分散式快取服務的記憶體配置。When you add physical memory to the server. The Distributed Cache service does not automatically recalculate the 10% memory allocation, so when you increase the total physical memory on the server, you have to manually increase the Distributed Cache service's memory allocation.

  • 當您的伺服器陣列有專用分散式快取伺服器時。請使用下列方法來計算可以將多少記憶體分派給分散式快取服務:When your server farm has a dedicated Distributed Cache server. Use the following method to calculate how much memory can be assigned to the Distributed Cache service:

  1. 判斷伺服器上的總實體記憶體。就此例而言,我們會使用 16 GB 作為伺服器上可用的總實體記憶體。Determine the total physical memory on the server. For this example, we will use 16 GB as the total physical memory available on the server.

  2. 保留 2 GB 記憶體給在快取主機上執行的其他程序和服務。例如,16 GB - 2 GB = 14 GB。這些剩餘的記憶體會配置給分散式快取服務。Reserve 2 GB of memory for other processes and services that are running on the cache host. For example, 16 GB - 2 GB = 14 GB. This remaining memory is allocated to the Distributed Cache service.

  3. 將一半的剩餘記憶體轉換成 MB。例如,14 GB/2 = 7 GB 或 7168 MB。這就是分散式快取服務的快取大小。Take half of the remaining memory, and convert it to MB. For example, 14 GB/2 = 7 GB or 7168 MB. This is the cache size of the Distributed Cache service.

  4. 依據情況,使用下列程序來更新記憶體配置。Use the following procedure to update the memory allocation accordingly.

變更分散式快取服務的記憶體配置Change the memory allocation of the Distributed Cache

使用此程序來重新設定分散式快取服務快取大小的記憶體配置。Use this procedure to reconfigure the memory allocation of the cache size of the Distributed Cache service.

  1. (選用) 若要查看伺服器上分散式快取服務的現有記憶體配置,請在 SharePoint 管理命令介面 命令提示字元中執行下列命令:(Optional) To check the existing memory allocation for the Distributed Cache service on a server, run the following command at the SharePoint Management Shell command prompt:

    Use-CacheCluster
    Get-AFCacheHostConfiguration -ComputerName $Env:ComputerName -CachePort "22233"
    

    其中:Where:

    • 電腦名稱 為執行 SharePoint 管理命令介面 Cmdlet 的伺服器上電腦名稱。ComputerName is the computer name of the server that you are running the SharePoint Management Shell cmdlet on.
  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 管理命令介面 命令提示字元中執行下列命令一次:To reconfigure the cache size of the Distributed Cache service, run the following command one time only on any cache host at the SharePoint Management Shell command prompt:

    Update-SPDistributedCacheSize -CacheSizeInMB CacheSize
    

    其中:Where:

    • 快取大小 是所分派的快取大小記憶體配置 (MB)。在前面的範例中,針對總記憶體為 16 GB 的伺服器,計算出來的快取大小為 7168 MB。CacheSize is the cache size's memory allocation assignment in MB. In the previous example, the cache size was calculated at 7168 MB for a server with 16 GB of total memory.
  4. 重新啟動所有快取主機上的分散式快取服務。若要重新啟動分散式快取服務,請前往管理中心的 [伺服器上的服務]*,然後 [啟動]* 伺服器陣列所有快取主機上的分散式快取服務。Restart the Distributed Cache service on all cache hosts. To restart the Distributed Cache service, go to Services on Server in Central Administration, and Start the Distributed Cache service on all cache hosts in the farm.

在分散式快取叢集中新增或移除伺服器Add or remove a server in a Distributed Cache cluster

系統管理員可以新增或移除伺服器至快取叢集或可能想要將伺服器從快取叢集移除,請執行一些作業或維護工作的伺服器上,然後重新加入或新增伺服器至快取叢集。時移除伺服器,分散式快取服務已停止,然後從伺服器取消註冊。註冊以系統管理員會在管理中心的 [伺服器上的服務] 頁面沒看到列出分散式快取服務的分散式快取服務方法。同樣地,當新增伺服器,分散式快取服務註冊,然後在伺服器上啟動。註冊的分散式快取服務表示系統管理員會看到列在管理中心的 [伺服器上的服務] 頁面上的分散式快取服務。An administrator can add or remove a server to a cache cluster, or might want to remove a server from the cache cluster, perform some operational or maintenance tasks on the server, and then rejoin or add the server to the cache cluster. 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 會在所要新增或移除的伺服器上執行。Use the following procedures to add and remove a server from a cache cluster. These SharePoint Management Shell cmdlets are run on the server being added or removed.

注意

[!附註] 執行下列程序之前,請先確保防火牆允許輸入 ICMP (ICMPv4) 流量通過。如需詳細資訊,請參閱<防火牆設定考量>。Before performing the following procedures, ensure the firewall allows Inbound ICMP (ICMPv4) traffic through it. For more information, see Firewall configuration considerations.

使用 SharePoint 2016 管理命令介面 來新增伺服器至快取叢集,並啟動分散式快取服務Add a server to the cache cluster and starting the Distributed Cache service by using SharePoint 2016 Management Shell

在 SharePoint 管理命令介面 命令提示字元中執行下列命令:At the SharePoint Management Shell command prompt, run the following command:

Add-SPDistributedCacheServiceInstance

使用 SharePoint 2016 管理命令介面 將伺服器從快取叢集移除Remove a server from the cache cluster by using SharePoint 2016 Management Shell

在 SharePoint 管理命令介面 命令提示字元中執行下列命令:At the SharePoint Management Shell command prompt, run the following command:

Remove-SPDistributedCacheServiceInstance

重要

[!重要事項] 此程序會停止快取服務,而非保存的快取資料將會遺失。如果您想要保存快取資料,請使用下一節說明的正常關機程序。This procedure will stop the cache service and nonpersisted cached data will be lost. If you want to keep the cached data, use the graceful shutdown procedure that is described in the next section.

使用 PowerShell 指令碼執行分散式快取服務的正常關機Perform a graceful shutdown of the Distributed Cache service by using a PowerShell script

在 SharePoint Server 2016 伺服器陣列中,當一或多個快取主機執行分散式快取服務時,就會存在快取叢集。SharePoint Server 2016 伺服器陣列中存在一個快取,而此快取橫跨快取叢集。將更新套用至伺服器時,系統管理員可能需要將快取的內容移到另一部快取主機。若要避免與移動快取內容相關聯的資料遺失,您必須在下列程序中使用 PowerShell 指令碼,以執行伺服器的正常關機。正常關機程序會將所有快取的資料,從執行正常關機程序的快取主機,傳輸至伺服器陣列中的另一部快取主機。視快取中存在多少個項目而定,傳輸程序需要 15 分鐘或更多時間執行。In a SharePoint Server 2016 farm, a cache cluster exists when one or more cache hosts run the Distributed Cache service. In a SharePoint Server 2016 farm, one cache exists, and the cache spans the cache cluster. An administrator may need to move the cached contents to another cache host when applying updates to the server. To prevent data loss associated with moving the cached contents you need to perform a graceful shutdown of the server using the PowerShell script in the following procedure. The graceful shutdown procedure transfers all cached data from the cache host on which the graceful shutdown procedure is being run on to another cache host in the farm. The transfer process takes 15 minutes or more to run depending on how many items exist in the cache.

使用 PowerShell 指令碼執行分散式快取的正常關機To perform a graceful shutdown of the Distributed Cache by using a PowerShell script

使用下列 PowerShell 指令碼來執行分散式快取伺服器的正常關閉,以便將快取的內容移到另一部快取主機。確保您指定要關閉正確的節點並視需要變更指令碼,為您的組織指定正確的參數。Use the following PowerShell script to perform a graceful shutdown of the Distributed Cache server in order to move the cached contents to another cache host. Ensure that you specify the correct node to shutdown and change the script as needed to name the correct parameters for your organization.

注意

[!附註] 如果您在下列程序中使用 PowerShell 指令碼來執行正常關機,則不需要從快取叢集中移除快取主機。There is no need to remove the cache host from a cache cluster if you use the PowerShell script in the following procedure to perform a graceful shutdown.

  1. 確認您是否符合下列基本需求:Verify that you meet the following minimum requirements:

  2. 複製下列變數宣告,並將它們貼到文字編輯器 (例如 [記事本]) 中。請設定您組織特有的參數值。在步驟 3 中儲存檔案,並將它命名為 Audiences.ps1。Copy the following variable declarations, and paste them into a text editor such as Notepad. Set parameter values specific to your organization. Save the file, and name it GracefulShutdown.ps1.

    注意

    您可以使用不同的檔案名稱,但是必須將檔案儲存為副檔名為 .ps1 的 ANSI 編碼文字檔。You can use a different file name, but you must save the file as an ANSI-encoded text file with the extension .ps1.

    ## Settings you may want to change for your scenario ##
    $startTime = Get-Date
    $currentTime = $startTime
    $elapsedTime = $currentTime - $startTime
    $timeOut = 900
    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 是您使用之分散式快取伺服器的電腦網域名稱。Where sp2016App.contoso.com is the computer domain name of Distributed Cache server you use.

  3. 開啟 [SharePoint 管理命令介面]Open the SharePoint Management Shell

  4. 變更至您儲存檔案的目錄。Change to the directory to which you saved the file.

  5. 在 PowerShell 命令提示字元中,輸入下列命令:At the PowerShell command prompt, type the following command:

    ./GracefulShutdown.ps1
    

    如需 PowerShell 指令碼和 .ps1 檔案的其他資訊,請參閱執行 Windows PowerShell 指令碼For additional information about PowerShell scripts and .ps1 files, see Running Windows PowerShell Scripts.

變更服務帳戶Change the service account

第一次設定伺服器陣列時,會將伺服器陣列帳戶設為 AppFabric 快取服務的服務帳戶。分散式快取服務相依於 AppFabric 快取服務。若要將 AppFabric 快取服務的服務帳戶變更為受管理帳戶,請執行下列操作:When the server farm is first configured, the server farm account is set as the service account of the AppFabric Caching service. The Distributed Cache service depends on the AppFabric Caching service. To change the service account of the AppFabric Caching service to a managed account:

  1. 建立受管理的帳戶。Create a managed account.

  2. 將受管理帳戶設為 AppFabric 快取服務的服務帳戶。在 SharePoint 管理命令介面 命令提示字元中執行下列命令:Set the Managed account as the service account on the AppFabric Caching service. At the SharePoint Management Shell command prompt, run the following command:

    $farm = Get-SPFarm
    $cacheService = $farm.Services | where {$_.Name -eq "AppFabricCachingService"}
    $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 是受管理帳戶的網域名稱和使用者名稱。Where Domain_name\user_name is the domain name and user name of the managed account.

使用 PowerShell 指令碼來微調分散式快取服務Fine-tune the Distributed Cache service by using a PowerShell script

MaxConnectionsToServer的分散式快取服務設定通常是根據可用在主機電腦上的 Cpu 數目而調整。如果使用多個核心與再將MaxConnectionsToServer設定設為相同的 Cpu 數目的執行個體之電腦通常會使用太多記憶體,和凍結。類似問題發生時調整DistributedLogonTokenCacheDistributedViewStateCache設定。預設值是 20ms年但時的權杖快取不會發生 20ms年設定中所找到通常例外狀況。使用下列 PowerShell 指令碼來變更的最大的連線和 SharePoint Server 2016 和 SharePoint Server 2013 中的逾時設定。The Distributed Cache service setting for MaxConnectionsToServer is often tuned based on the number of CPUs that are used in the host computer. If, for instance you use multiple cores and then set the MaxConnectionsToServer setting to the same number of CPUs then the computer often uses too much memory and freezes. Similar issues happen when tuning the DistributedLogonTokenCache and DistributedViewStateCache settings. The default setting is 20ms but often exceptions are found when the token caching doesn't happen in the 20ms setting. Use the following PowerShell scripts to change the settings for max connections and timeouts in SharePoint Server 2016 and SharePoint Server 2013.

使用 PowerShell 指令碼來微調分散式快取服務To fine-tune the Distributed Cache service by using a PowerShell script

  1. 確認您是否符合下列基本需求:Verify that you meet the following minimum requirements:

  2. 複製下列變數宣告,並將它們貼到文字編輯器 (例如 [記事本]) 中。請設定您組織特有的參數值。在步驟 3 中儲存檔案,並將它命名為 MaxConnections.ps1。Copy the following variable declarations, and paste them into a text editor such as Notepad. Set parameter values specific to your organization. Save the file, and name it MaxConnections.ps1.

    注意

    您可以使用不同的檔案名稱,但是必須將檔案儲存為副檔名為 .ps1 的 ANSI 編碼文字檔。You can use a different file name, but you must save the file as an ANSI-encoded text file with the extension .ps1.

    SharePoint Server 2016 PowerShell 指令碼SharePoint Server 2016 PowerShell script

    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 指令碼SharePoint Server 2013 PowerShell script

    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 管理命令介面]Open the SharePoint Management Shell

  4. 變更至您儲存檔案的目錄。Change to the directory to which you saved the file.

  5. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    ./MaxConnections.ps1
    

    如需詳細資訊,請參閱使用 Windows Azure Cache/Windows Server Appfabric Cache 的最佳做法應用程式組態設定 (Windows Server AppFabric Caching)。如需 Windows PowerShell 指令碼和 .ps1 檔案的其他資訊,請參閱執行 Windows PowerShell 指令碼For more information, see Best Practices for using Windows Azure Cache/Windows Server Appfabric Cache and Application Configuration Settings (Windows Server AppFabric Caching). For additional information about Windows PowerShell scripts and .ps1 files, see Running Windows PowerShell Scripts.

修復快取主機Repair a cache host

安裝、設定或維護活動期間,分散式快取服務可能會進入非運作狀態。分散式快取服務非運作的證據會顯示在管理中心的狀況規則中,或是當使用者使用仰賴分散式快取的 SharePoint Server 功能時。例如使用者「我的網站」上的新聞摘要會開始報告錯誤。另外,管理員在執行 SharePoint 管理命令介面 Cmdlet 管理分散式快取服務時,可能會收到「cacheHostInfo 為 null 」的錯誤訊息。During installation, configuration, or maintenance activities, the Distributed Cache service might enter a non-functioning state. Evidence of a malfunctioning Distributed Cache service will appear in Health Rules in Central Administration, or when users use features in SharePoint Server that rely on the Distributed Cache. For example, the Newsfeed on a user's My Site will start reporting errors. Also, administrators might receive the error message "cacheHostInfo is null " when they run SharePoint Management Shell cmdlets to manage the Distributed Cache service.

修復快取主機有兩個步驟。There are two steps to repair a cache host.

在非運作的分散式快取主機上,使用下列程序來還原分散式快取主機。On the non-functioning Distributed Cache host, use the following procedures to restore the Distributed Cache host.

  1. 在 SharePoint 管理命令介面 命令提示字元中,執行 Remove-SPDistributedCacheServiceInstance Cmdlet。At the SharePoint Management Shell command prompt, run the Remove-SPDistributedCacheServiceInstance cmdlet.

  2. 在 SharePoint 管理命令介面 命令提示字元中,執行 Add-SPDistributedCacheServiceInstance Cmdlet。At the SharePoint Management Shell command prompt, run the Add-SPDistributedCacheServiceInstance cmdlet.

    注意

    [!附註] 如果步驟 1 失敗,請以手動方式移除分散式快取服務,使用下列步驟。If step 1 fails, manually remove the Distributed Cache service, use the following steps.

    • 在 SharePoint 管理命令介面 命令提示字元中,輸入下列語法。At the SharePoint Management Shell command prompt, type the following syntax.
    $instanceName ="SPDistributedCacheService Name=AppFabricCachingService"
    
    $serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
    
    If($serviceInstance -ne $null)
    {
    $serviceInstance.Delete()
    }
    
    • 手動刪除分散式快取服務之後,請再次執行步驟 2。After the Distributed Cache Service has been manually deleted, run step 2 again.

另請參閱See also

概念Concepts

規劃 SharePoint Server 中的摘要和分散式快取服務Plan for feeds and the Distributed Cache service in SharePoint Server