SharePoint 2013 : How I fixed my corrupted AppFabric Cache Service

sharepoint2013 I have faced some troubles with Ditributed Cache… (again ?)
Especially when I tried to change the service account of the AppFabric Caching service, as explained here.
Then, my services seemed corrupted, it was impossible to restart them properly (Restart-CacheCluster command).
Their status was stuck on STARTING for a few minutes, and then went DOWN :

PS C:Userssp_admin> Use-CacheCluster
PS C:Userssp_admin> Get-CacheHost
HostName : CachePort Service Name Service Status
-------------------- ------------ --------------
Server1:22233 AppFabricCachingService DOWN
Server2:22233 AppFabricCachingService STARTING

And I had this error in the Windows Event logs (Event ID 1000 and 1001) – Seeing a failing KERNELBASE.dll module is not very reassuring !
cache_21
This is what I have done to fix it. BEWARE that a corrupted distributed cache can result in resinstalling SharePoint from scratch ! So please be careful.
1- Stop all the SharePoint Distributed Cache service instances (on each WFE) :

Use-CacheCluster
Stop-SPDistributedCacheServiceInstance -Graceful
Remove-SPDistributedCacheServiceInstance

Use this code to force the uninstall :

Get-SPServiceInstance | ? {($_.service.tostring()) -eq "SPDistributedCacheService Name=AppFabricCachingService"} | % { $_.Server; $_.Status; $_.Id }
$s = Get-SPServiceInstance <GUID>
$s.Delete()

2- Unregister all hosts (on each WFE) :

Unregister-CacheHost

3- Register all hosts :

Register-CacheHost -Provider "SPDistributedCacheClusterProvider" -ConnectionString "Data Source=DBAlias;Initial Catalog=SPServer2013_Config;Integrated Security=True;Enlist=False" -Account "DOMAINSP_DistributedCache" -CachePort 22233 -ClusterPort 22234 -ArbitrationPort 22235 -ReplicationPort 22236 -HostName Server1

  • The parameter « Account » must be the managed account that run the service (as displayed in the central administration).
  • The parameters « Provider » and « ConnectionString » must be copied from the following file « C:Program FilesAppFabric 1.1 for Windows ServerDistributedCacheService.exe.config »
  • The parameter « HostName » must be changed as well.

4- Start each cache host (on each WFE) :

Start-CacheHost -ComputerName Server1 -CachePort 22233

5- Restart all the servers
6- Create the SharePoint Service Instances (on each WFE) :

Add-SPDistributedCacheServiceInstance

Everything went well then. These 2 commands showed me that the services were Online, and the AppFabric Services were marked as UP :

Get-SPServiceInstance | ? {($_.service.tostring()) -eq "SPDistributedCacheService Name=AppFabricCachingService"} | % { $_.Server; $_.Status; $_.Id }
Use-CacheCluster
Get-CacheHost

SharePoint 2013 : Réparer un cluster de cache distribué défectueux

sharepoint2013 Quand on rencontre des difficultés avec le cache distribué de SharePoint, il faut suivre les instructions données sur cette page : Manage the Distributed Cache service in SharePoint Server 2013.
Cependant, on peut se retrouver avec une ferme plutôt têtue qui refuse de créer correctement un cluster de cache, notamment avec des hôtes qui restent en statut « Provisioning » :/
Voici comment j’ai réussi à m’en sortir :
1.Pré-requis
Premièrement, je pars avec des services de mise en cache AppFabric correctement configurés et lancés.
On vérifie cela avec cette commande :

Use-CacheCluster
Get-CacheHost

Si tous les serveurs sont à UP, on peut continuer.
cache1
Sinon, j’ai écris un autre article sur le sauvetage d’une installation AppFabric qui tournait de l’oeil : SharePoint 2013 : How I fixed my corrupted AppFabric Cache Service
2.Etat des services
Avec cette commandes, on vérifie l’état des services de cache distribué :

Get-SPServiceInstance | ? {($_.service.tostring()) -eq "SPDistributedCacheService Name=AppFabricCachingService"}

Mon problème était là : l’un des hôte restait sur « Provisioning », malgré toutes mes manipulations pour détruire et recréer cet hôte.
cache2
Solution : Recréer complètement le cluster.
3.Recréer un cluster de cache distribué
3.1.Supprimer toutes les instances de cache
Passer ces commandes sur tous les hôtes du cluster. On se retrouvera donc avec un cluster vide :

Use-CacheCluster
Stop-SPDistributedCacheServiceInstance -Graceful
Remove-SPDistributedCacheServiceInstance

3.2.Redémarrer les serveurs
Cela peut paraitre un peu brutal, mais dans mon cas c’était indispensable.
3.3.Recréer les instances de service
Sur tous les serveurs qui devront héberger le cluster, passer cette commande :

Add-SPDistributedCacheServiceInstance

4.Vérifications
Passer de nouveau cette commande :

Get-SPServiceInstance | ? {($_.service.tostring()) -eq "SPDistributedCacheService Name=AppFabricCachingService"}

L’ensemble de serveurs devrait être à « Online ».
En passant par l’administration centrale, et aller dans « Paramètres Système » > « Gérer les services sur le serveur ».
Les services de « Cache distribué » doivent être démarré (« Started ») sur tous les serveurs.
cache3
Hourra, les fonctionnalités portées par le cache distribuées marcheront avec grâce et célérité.