在 SharePoint Server 中管理分布式缓存服务

适用于:yes-img-132013 yes-img-162016 yes-img-192019 yes-img-seSubscription Edition no-img-sopSharePoint in Microsoft 365

若要在 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 列表

以下 PowerShell cmdlet 现已在 SharePoint Server PowerShell 中提供。

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 或 7,168 MB。 此数值是分布式缓存服务的缓存大小。

    4. 使用以下过程可相应地更新内存分配。

更改分布式缓存的内存分配

使用此过程重新配置分布式缓存服务的缓存大小的内存分配。

  1. (可选)要检查服务器上分布式缓存服务的现有内存分配,请在 SharePoint 命令行管理程序 命令提示符处运行以下命令:

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

    其中:

    • 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
    

    其中:

    • Cachesize 是缓存大小的内存分配(以 MB 为单位)。 在之前的示例中,对于总内存为 16 GB 的服务器,计算出的缓存大小为 7,168 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

    注意

    可以使用其他文件名,但必须将该文件另存为扩展名 .ps1为 的 ANSI 编码文本文件。

    ## 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. 总缓存未命中数/秒 - 此处的高值可能表示应用程序性能可能会受到影响,因为它无法从缓存中提取数据。 导致这种情况的可能原因包括逐出和/或缓存中的项过期。

  4. 对象总数 - 了解缓存中的项数。 对象计数的显著下降可能意味着逐出或即将到期。

  5. 总客户端请求数/秒 - 此计数器有助于了解应用程序在缓存服务器上生成的负载量。 此处的低值通常意味着缓存服务器之外的某种瓶颈 (可能在应用程序或网络) ,因此缓存服务器上放置的负载很少。

  6. 已逐出对象总数 - 如果缓存服务器不断逐出项,以便为缓存中的较新对象腾出空间,这通常表明缓存服务器上需要更多内存来保存应用程序的数据集。

  7. 总失败异常数/秒和总重试异常数/秒。

MaxConnectionsToServer 的分布式缓存服务设置通常会根据主机计算机中使用的 CPU 数量进行调整。 例如,如果使用多个核心,然后将 MaxConnectionsToServer 设置设置为相同数量的 CPU,则计算机通常会使用过多的内存并冻结。 在调整 DistributedLogonTokenCacheDistributedViewStateCache 设置时,会出现类似的问题。 默认设置为 20 毫秒,但在 20 毫秒设置中未发生令牌缓存时,通常会发现异常。 使用以下 PowerShell 脚本更改 SharePoint Server 2016 和 SharePoint Server 2013 中最大连接数和超时的设置。

使用 PowerShell 脚本微调分布式缓存服务的具体步骤

  1. 确认您满足以下最低要求:

  2. 复制以下变量声明并粘贴到文本编辑器(如记事本)中。 设置特定于您的组织的参数值。 保存文件,并将其命名为 MaxConnections.ps1

    注意

    可以使用其他文件名,但必须将该文件另存为扩展名 .ps1为 的 ANSI 编码文本文件。

    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 Caching) 。 有关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 中规划源和分布式缓存服务