Managing the Distributed Cache Service in SharePoint 2013 using PowerShell
Greetings SharePoint Campers!
This time I will just offer a brief cheat sheet for Distributed Cache operations using powershell, which is pretty much the only way you can configure and manage the service.
For some reason, the Distributed Cache seems to offer a lot of people grief, all from no functionality at all to extremely slow responsetimes on all pages loaded (see SharePoint 2013 page loads takes a very long time).
My best tip, the often working quick fix with a malfunctioning cache service, is to first try and stop and start it, then if its still failing, delete the service and add it back again. You should also from the start change the default service account from the farm account to a separate, maybe dedicated managed account.
Quick fix
1.
Stop the service
Start the service
2.
Delete the service
Create a new service
3.
Start checking the logfiles and do a proper t-shooting.
Remember that in a multiserver farm, the PowerShell commands will affect the server where the command has been executed, so make sure to be on the correct server Before runing the CMDlets. |
Distributed Cache tasks listed in the following order:
Change the service account running the Distributed Cache
Graceful stop and deattach local server (No lost cache data)
Dettach local server from a cache cluster (Multiple Distributed Cache servers)
Reattach local server to a cache cluster (Multiple Distributed Cache servers)
Delete the service
Create a new service
Start the service on a server
Stop the service on a server
Check current Cache memory allocation
Change the Cache memory allocation
References
Change the service account running the Distributed Cache
It is recommended to use a SharePoint managed account for this service.
$spfarm = Get-SPFarm
$spcacheService = $spfarm.Services | where {$_.Name -eq “AppFabricCachingService”}
$spaccount = Get-SPManagedAccount -Identity domain\spdistcache
$spcacheService.ProcessIdentity.CurrentIdentityType = “SpecificUser”
$spcacheService.ProcessIdentity.ManagedAccount = $spaccount
$spcacheService.ProcessIdentity.Update()
$spcacheService.ProcessIdentity.Deploy()
CurrentIdentityType = “SpecificUser” should be just that and nothing else, do not replace this value |
Verify by going to Central administration, Security, Configure Service accounts, Select ‘Windows Service – Distributed Chache’ i dropdown, that the service account has been replaced.
Graceful stop and deattach local server (No lost cache data)
Stop-SPDistributedCacheServiceInstance -Graceful
Remove-SPDistributedCacheServiceInstance
Deattach local server from a cache cluster (Multiple Distributed Cache servers)
Remove-SPDistributedCacheServiceInstance
Reattach local server to a cache cluster (Multiple Distributed Cache servers)
Add-SPDistributedCacheServiceInstance
Delete the service
$instanceName =”SPDistributedCacheService Name=AppFabricCachingService”
$serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
$serviceInstance.delete()
Verify in Central Admin, System Settings, Manage Services on Server. It should be gone from this list when it has been completely deleted.
In a multi server farm, you will have to select which server to show the services from in the top-right dropdown.
Create a new service
Add-SPDistributedCacheServiceInstance
Verify in Central Admin, System Settings, Manage Services on Server. It should appear in this list when it has been created. In a multi server farm, you will have to select which server to show the services from in the top-right dropdown.
Start the service on a server
$instanceName =”SPDistributedCacheService Name=AppFabricCachingService”
$serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
$serviceInstance.Provision()
Stop the service on a server
$instanceName =”SPDistributedCacheService Name=AppFabricCachingService” $serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
$serviceInstance.Unprovision()
Check current Cache memory allocation
Use-CacheCluster Get-AFCacheHostConfiguration -ComputerName $env:computername -CachePort “22233”
Change the Cache memory allocation
On all Cache servers in the farm stop the service
$instanceName =”SPDistributedCacheService Name=AppFabricCachingService” $serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
$serviceInstance.Unprovision()
Update the memory allocation
Update-SPDistributedCacheSize -CacheSizeInMB CacheSize
Start the service on all Cache servers
$instanceName =”SPDistributedCacheService Name=AppFabricCachingService” $serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
$serviceInstance.Provision()
CacheSize is the cache size’s memory allocation assignment in MB |
‘
Note: Beware of the signle and double quotes if you copy the code…![]() |
‘
References
Manage the Distributed Cache service in SharePoint Server 2013
http://technet.microsoft.com/en-us/library/jj219613.aspx
Plan and use the Distributed Cache service in SharePoint Server 2013 (Poster)
http://www.microsoft.com/en-us/download/confirmation.aspx?id=35557
_________________________________________________________
Enjoy!
Regards
One thought on “Managing the Distributed Cache Service in SharePoint 2013”