Thursday, December 04, 2014

Cachehost is null

We're getting error Cachehost is null when trying to start Distributed Cache or removing the service with remove-spdistributedcacheserviceinstance

First of all verify these settings
- Windows Firewall have AppFabric Caching Service (TCP-Out) enabled on servers running DistributedCache
- Verify DistributedCache ports open between servers running Distributed Cache : 22233-22236 and Ping/Echo
- Verify following ports for AppFabric to talk sufficiently: 445, 139,135
- Can’t start Distributed Cache from the Central Admin
- Verify server and Active Directory talking ok.
- Verify DNS working

Verify status of Cachecluster. Is AppFabric and Sharepoint Server talking ok?
- Script : compareDCvsAppFabric-------
Add-PSSnapin microsoft.sharepoint.powershell


$instancename = "SPDistributedCacheService name=AppFabricCachingService"
$DC = get-spserviceinstance |where-object {($_.service.tostring()) -eq $instancename }
write-host "Sharepoint says..."
$DC |select typename, status,id,server |format-table

Use-CacheCluster
write-host "AppFabric says...."
Get-CacheHost |format-table

Result: Something is not ok. Sharepoint says fours servers and AppFabric says two. If same servers are reporting on both DC and AF then the problem is elsewehere.
image

Solution:
Remove the serviceinstance from the missing servers and add them again.
Script below removes serviceinstance from the computer the script runs from!
---------script: forceremovedistcache.ps1 --------------
Add-PSSnapin microsoft.sharepoint.powershell

$instanceName ="SPDistributedCacheService Name=AppFabricCachingService"
$serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName –and ($_.server.name) -eq $env:computername}
$serviceInstance
write-host "Deleting instance $serviceinstance.id"
$serviceInstance.Delete()

write-host "Adding distributed cache..."
Add-SPDistributedCacheServiceInstance
write-host "Done"

Scenario 2: The other way around. AppFabric says other stuff than sharepoint.
Solution:  Remove the host from the cluster.
----script: remove host from cluster ----
Add-PSSnapin microsoft.sharepoint.powershell
$cachehost =  $env:computername

Use-CacheCluster
Get-CacheHost
Unregister-CacheHost -hostname $cachehost -ProviderType SPDistributedCacheClusterProvider -connectionstring "<INSERTREGVALUE1>"
Add-SPDistributedCacheServiceInstance

Where regvalue1 is found : HKLM\SOFTWARE\Microsoft\AppFabric\V1.0\Configuration\ConnectionString  (remove “;enlist=false” from the string)

And then try to add distributed cache again.

Lessons learned:
- In a locked down environment make sure all relevant Distributed Cache ports are open before adding the service to server.
- AppFabric and Distributed Cache is not the same thing! Appfabric is a windows service while Distributed Cache is a sharepoint service instance. They don’t always agree! Make sure they’re talking!

References:

No comments: