Friday 25 October 2019

Configure the Search Service Application - SharePoint 2013


This post describes how to configure the SharePoint Server 2013 Search Service Application using PowerShell.  

In this example, there is one Database Server (SERVER01), one Web Server (SERVER03), and one Application Server (SERVER04).


Solution

This solution is for a small farm environment that has one Database Server, one Web Server, and one Application Server.  The steps below will result in a complete Search Topology. 

The steps provided do not represent an automated script that you would copy and paste into a window and run all at once.  Instead, the steps are intended to be run manually, one at a time, in the PowerShell window. The post is written this way on purpose and provides a way to step through each cmdlet one at a time.

If you have a different server topology or if you would prefer a fully automated script to provision the Search Service Application, then I recommend that you look at the References section and possibly utilize one of the more sophisticated examples that exist in the community knowledge base.



Before Starting...

Ensure that the Service Account to be used for the Service Application Pool exists and has been registered in Central Administration as a Managed Account

Ensure that the Host Controller Service in Central Administration is registered under a Service Account that has adequate permissions to activate the Search Topology (e.g. Farm Account)


1.  Prepare the PowerShell Session
 
Open the PowerShell window as Administrator.

Clear-Host

Set-ExecutionPolicy unrestricted
Respond Y to confirm

Get-PSSnapin -name Microsoft.SharePoint.PowerShell -EA SilentlyContinue


2.  Determine Naming Convention and Set Initial Variables

Set the Variables

$Svr01 = "SERVER01"
$Svr03 = "SERVER03"
$Svr04 = "SERVER04"
$SvcAppPl03 = "SvcApp_SPServiceApplicationPool_03"
$SvcAppSrch = "SvcApp_SPEnterpriseSearchServiceApplication_01"
$SvcAppSrchPrxy = "SvcApp_SPEnterpriseSearchServiceApplication_01_Proxy_01"
$SvcAppDBSvr = "SERVER01"
$SvcAppDB = "SvcApp_SPEnterpriseSearchServiceApplication_01_DB_01"
$SvcAppSrchAdmnCmp = $SvcAppSrch | Get-SPEnterpriseSearchAdministrationComponent
$ESSI03 = Get-SPEnterpriseSearchServiceInstance -Identity "SERVER03"
$ESSI04  = Get-SPEnterpriseSearchServiceInstance -Identity "SERVER04"
$QSSN03 = Get-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance -Identity "SERVERN03"
$QSSN04 = Get-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance -Identity "SERVERN04"
$IndexLocP = "I:\IndexPrimary"
$IndexLocR = "I:\IndexReplica"


3.  Start the Search Service Instances

Start-SPEnterpriseSearchServiceInstance -Identity $Svr03

Start-SPEnterpriseSearchServiceInstance -Identity $Svr04


4.  Start the Query and Site Settings Service Instances

Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance -identity $QSSN03

Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance -identity $QSSN04


5.  Create the Search Service Application

New-SPEnterpriseSearchServiceApplication -Name $SvcAppSrch -ApplicationPool $SvcAppPl03 -AdminApplicationPool $SvcAppPl03 -DatabaseName $SvcAppDB -DatabaseServer $SvcAppDBSvr


6.  Set the Search Admin Component

Set-SPEnterpriseSearchAdministrationComponent -SearchServiceInstance $Svr04


7.  Create and Configure Search Topology 02

$SrchTop01 = Get-SPEnterpriseSearchTopology -SearchApplication $SvcAppSrch

$SrchTop02 = New-SPEnterpriseSearchTopology -SearchApplication $SvcAppSrch -Clone -SearchTopology $SrchTop01


8.  Create the Search Admin Component

New-SPEnterpriseSearchAdminComponent –SearchTopology $SrchTop02 -SearchServiceInstance $Svr04


9.  Create Search Content Processing Components

New-SPEnterpriseSearchContentProcessingComponent –SearchTopology $SrchTop02 -SearchServiceInstance $Svr04

New-SPEnterpriseSearchContentProcessingComponent –SearchTopology $SrchTop02 -SearchServiceInstance $Svr03


10.  Create Analytics Processing Components

New-SPEnterpriseSearchAnalyticsProcessingComponent –SearchTopology $SrchTop02 -SearchServiceInstance $Svr04

New-SPEnterpriseSearchAnalyticsProcessingComponent –SearchTopology $SrchTop02 -SearchServiceInstance $Svr03


11.  Create Search Crawl Components

New-SPEnterpriseSearchCrawlComponent –SearchTopology $SrchTop02 -SearchServiceInstance $Svr04

New-SPEnterpriseSearchCrawlComponent –SearchTopology $SrchTop02 -SearchServiceInstance $Svr03


12.  Create Search Query Processing Components

New-SPEnterpriseSearchQueryProcessingComponent –SearchTopology $SrchTop02 -SearchServiceInstance $Svr04

New-SPEnterpriseSearchQueryProcessingComponent –SearchTopology $SrchTop02 -SearchServiceInstance $Svr03


13.  Create and Assign Index Partitions

New-SPEnterpriseSearchIndexComponent –SearchTopology $SrchTop02 -SearchServiceInstance $Svr04 -RootDirectory $IndexLocP -IndexPartition 0

New-SPEnterpriseSearchIndexComponent –SearchTopology $SrchTop02 -SearchServiceInstance $Svr03 -RootDirectory $IndexLocR -IndexPartition 0

New-SPEnterpriseSearchIndexComponent –SearchTopology $SrchTop02 -SearchServiceInstance $Svr03 -RootDirectory $IndexLocP -IndexPartition 1

New-SPEnterpriseSearchIndexComponent –SearchTopology $SrchTop02 -SearchServiceInstance $Svr04 -RootDirectory $IndexLocR -IndexPartition 1


14.  Activate Search Topology 02

Set-SPEnterpriseSearchTopology -Identity $SrchTop02


15.  Remove Search Topology 01

$SrchTop01 = Get-SPEnterpriseSearchTopology -SearchApplication $SvcAppSrch | where {($_.State) -eq "Inactive"}

Remove-SPEnterpriseSearchTopology -Identity $SrchTop01 -Confirm:$false


16.  Create Search Service Application Proxy

$SvcAppSrchPrxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "SvcApp_SPEnterpriseSearchServiceApplication_01_Proxy_01" -SearchApplication $SvcAppSrch



Key Words
Search Service, Search Service Application, Search Topology.



References

ChandrasekarN (February, 2013).  SharePoint 2013 - Configuring Search Service Application and Topology using PowerShell.  Retrieved January 29, 2014 from http://blogs.msdn.com/b/chandru/archive/2013/02/19/sharepoint-2013-configuring-search-service-application-and-topology-using-powershell.aspx

Earp, S. (September, 2013).  Configuring SharePoint 2013 Search with PowerShell.  Retrieved January 27, 2014 from http://blogs.technet.com/b/ptsblog/archive/2013/09/19/configuring-sharepoint-2013-search-with-powershell.aspx

Harbar, S. (July, 2012).  Multi Tenancy with SharePoint 2013: What’s new and changed.  Retrieved January 29, 2014 from http://www.harbar.net/articles/sp2013mt.aspx

Klindt, T. (December, 2012).  Create SharePoint 2013 Search service application with PowerShell.  Retrieved January 29, 2014 from http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=378

Microsoft TechNet (2013).  Create and configure a Search service application in SharePoint Server 2013.  Retrieved January 27, 2014 from http://technet.microsoft.com/en-us/library/gg502597.aspx

Microsoft TechNet (2013).  Get-SPSearchService.  Retrieved January 27, 2014 from http://technet.microsoft.com/en-us/library/ee620539(v=office.14).aspx

Microsoft TechNet (2013).  Get-SPEnterpriseSearchServiceApplication.  Retrieved January 27, 2014 from http://technet.microsoft.com/en-us/library/ff608050.aspx

Microsoft TechNet (2013).  Get-SPEnterpriseSearchServiceInstance.  Retrieved January 27, 2014 from http://technet.microsoft.com/en-us/library/ff607740.aspx

Microsoft TechNet (2013).  Get-SPEnterpriseSearchTopology.  Retrieved January 27, 2014 from http://technet.microsoft.com/en-us/library/jj219578.aspx

Microsoft TechNet (2013).  Get-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance.  Retrieved January 27, 2014 from http://technet.microsoft.com/en-us/library/ff608115.aspx

Microsoft TechNet (2013).  New-SPEnterpriseSearchServiceApplication.  Retrieved January 27, 2014 from http://technet.microsoft.com/en-us/library/ff607751.aspx

Microsoft TechNet (2013).  New-SPEnterpriseSearchServiceApplicationProxy.  Retrieved January 27, 2014 from http://technet.microsoft.com/en-us/library/ff607722.aspx

Microsoft TechNet (2013).  Set-SPEnterpriseSearchServiceApplication.  Retrieved January 27, 2014 from http://technet.microsoft.com/en-us/library/ff607974.aspx

Microsoft TechNet (2013).  Set-SPEnterpriseSearchTopology.  Retrieved January 27, 2014 from http://technet.microsoft.com/en-us/library/jj219653.aspx

Microsoft TechNet (2013).  Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance.   Retrieved January 27, 2014 from http://technet.microsoft.com/en-us/library/ff607759.aspx

Microsoft TechNet (2013).  Start-SPEnterpriseSearchServiceInstance.  Retrieved January 27, 2014 from http://technet.microsoft.com/en-us/library/ff607852.aspx

Microsoft TechNet (2013).  Remove-SPEnterpriseSearchTopology.  Retrieved January 27, 2014 from http://technet.microsoft.com/en-us/library/jj219505.aspx

Ravikanth (April, 2013).  Creating and configuring a SharePoint 2013 search service application.  Retrieved January 29, 2014 from http://www.powershellmagazine.com/2013/04/29/creating-and-configuring-a-sharepoint-2013-search-service-application/


Moving Central Administration to another server

The following simple procedure enables you to move a SharePoint farm's Central Administration web application to another farm server, while also updating the URL shortcut.  There is no need to modify registry entries to accomplish this.  The SharePoint Products Configuration Wizard does everything for you.




  1. Repeat the following steps on each farm server hosting the Central Administration web application:
    1. As the farm setup user administrator account (eg, spAdmin), remote into the farm server currently hosting the Central Administration web application.
    2. Run the SharePoint Products Configuration Wizard as administrator.
    3. At the Modify server farm Settings page of the wizard, verify that the option Do not disconnect from this server farm is selected, and then click Next.
    4. At the Modify SharePoint Central Administration Web Application Settings page of the wizard, select the option Yes, I want to remove this web site from this machine, and then click Next.
    5. Click Next again.
    6. Once the wizard has finished the configuration, exit the wizard.
    7. Log out of the machine.  At this point, your farm does not have a Central Administration web application.  That's OK.  Don't fret.  You'll be re-installing it momentarily.
  2. Repeat the following steps on each farm server on which you want to host the Central Administration web application:
    1. As the farm setup user administrator account (eg, spAdmin), remote into a farm server on which you want to host the Central Administration web application.
    2. Run the SharePoint Products Configuration Wizard as administrator.
    3. At the Modify server farm Settings page of the wizard, verify that the option Do not disconnect from this server farm is selected, and then click Next.
      • If this is the first time that you are running the wizard to install CA, you will be presented with the Configure SharePoint Central Administration Web Application page, where you can specify a port and authentication provider for the CA web application.  Enter this information, and then click Next.
      • If you are installing CA to yet another farm server (ie, to have two or more instances of CA available), you will be presented with the Completing the SharePoint Productions Configuration Wizard page, but having the Advanced Settings button enabled:
        1. Click the Advanced Settings button.  The Advanced Settings page is displayed.
        2. Select the option, Use this machine to host the web site, and then click OK.  This will not remove the other instance of CA already installed.  It only installs another instance.
    4. Click Next again.
    5. Once the wizard has finished the configuration, exit the wizard.
References
Notes
  • It is imperative that you engage in this procedure while logged in as the farm setup user administrator account.  Only this account (if you installed your farm as this account) has the appropriate permissions necessary to access required folders and registry keys to make the necessary changes.
  • There is absolutely no need to edit the registry in order to move the CA web application and have URLs updated, such as discussed here and here.  While this registry entry is effectively how individual instances of SharePoint Server actually track the URL for CA, editing this key will not update the farm's configuration database and will cause the farm configuration database to be out-of-sync with farm servers with respect to this parameter.  You can see this more clearly by examining the actual syntax of the Central Administration URL: the URL points to psconfigui with a command specified.
  • I was not able to find any specific Microsoft documentation that describes how to do this.  If any reviewer of this posting happens to know, please leave note and URL.
  • After running the SharePoint Products Configuration Wizard, you may see the Missing server side dependencies issue appear again in the farm's Health Report.  I have experienced this every time I run the configuration wizard or psconfig.

OWA Installation SharePoint 2013


Preview of Office Documents (this includes PDF) is a huge benefit when you are searching for information – you can quickly identify if the document is the one you are looking for or skimming/scanning a document efficiently. To get the preview up and running you have to install Office Web Apps 2013 – PDF preview was added in March Public Update 2013 – that’s great, many clients have asked me why there is no support in the 2010 stack. But its 2013 – so let’s install Office Web Apps 2013 for SharePoint 2013!

Overview
I did the following steps on my SharePoint 2013 DEV environment. The SP2013 environment was already on March PU because of the awesome AutoSPInstaller/AutoSPSourceBuilder combo. As host I used a virtualized (Hyper-V) Windows Server 2012 with 4 cores and 5gb RAM on my Notebook (Lenovo W520).

Requirements
You can’t install Office Web Apps on a SharePoint or SQL Server. Additionally the SharePoint Server has to use claims-based authentication. Read all the requirements here.

7 easy steps!
  1. Install the PreRequisites
  2. Restart the computer
  3. Download and install Office Web Apps 2013
  4. Download and install March Public Update for OWA 2013
  5. Create the OWA Farm
  6. Configure the binding on the SharePoint side
  7. Do a full crawl
PreRequisites for Server 2012

Note: For PreRequisites of Server 2008 R2 read the technet article. If you can not install KB2592525 read this blog post by Markus Nöbauer.
The installer of the Office Web Apps 2013 is a little bit limited – other than the SharePoint 2013 it does not configure the host. But at least you can automate the whole process. Run PowerShell as admin on the OWA server:
Import-Module servermanager
Add-WindowsFeature Web-Server, Web-WebServer, Web-Common-Http, Web-Static-Content, Web-App-Dev, Web-Asp-Net, Web-Net-Ext, Web-ISAPI-Ext, Web-ISAPI-Filter, Web-Includes, Web-Security, Web-Windows-Auth, Web-Filtering, Web-Stat-Compression, Web-Dyn-Compression, Web-Mgmt-Console, InkAndHandwritingServices, Web-Net-Ext45, Web-Asp-Net45
Restart the computer afterwards.
https://melcher.it/wp-content/uploads/192.168.137.50-Remote-Desktop-Connection_2013-05-17_18-02-33_thumb1.png
PowerShell addicted - starting to automate the PreRequisites installation.

Download and install Office Web Apps 2013
The installation is quite simple, hit next several times – nothing magic here.
https://melcher.it/wp-content/uploads/192.168.137.50-Remote-Desktop-Connection_2013-05-17_18-09-18_thumb1.png
OWA installation folder
OWA installation in progress
OWA installation in progress

Download and install the March Public Update

After the installation just copy the OWA March 2013 PU on the box and install it. Again, an easy task.
https://melcher.it/wp-content/uploads/192.168.137.50-Remote-Desktop-Connection_2013-05-17_19-02-56_thumb1.png


Create the OWA Farm
After installation and patching, we have to use PowerShell again:
New-OfficeWebAppsFarm -InternalURL http://owa2013.demo.com -AllowHttp –EditingEnabled
With New-OfficeWebAppsFarm – you have certainly guessed it - we created the first node of our OWA farm, just replace the internal url with your hostname/FQDN. Because I have a simple DEV environment I did not use https and allowed editing – for editing you need Office licenses, view-only is free (awesome, thanks!). Add the OWA binding on the SharePoint machine, run this in a SharePoint Powershell:
New-SPWOPIBinding -ServerName owa2013.demo.com –AllowHTTP
Set-SPWopiZone -zone "internal-http"
Two commands and the two are coupled - great.


Enable PDF Preview in Search results
Wictor wrote a nice article about how to enable the PDF-Preview - if you followed my guide you do not need to enable it, it’s already set. The only part that is missing is the Display Template.
The quick and dirty Powershell approach to enable PDF Previews in search results:
$tenantOwner = Get-SPEnterpriseSearchOwner -Level SSA
$ssa = "Search Service Application" #adjust if you renamed the service application

$rule = get-SPEnterpriseSearchPropertyRule -PropertyName "FileType" -Operator "IsEqual"
$rule.AddValue( "pdf" )
$ruleCollection = Get-SPEnterpriseSearchPropertyRuleCollection
$ruleCollection.Add($rule)

$item = new-SPEnterpriseSearchResultItemType -Owner $tenantOwner -SearchApplication $ssa -Name "PDF with Preview" -Rules $ruleCollection -RulePriority 1 -DisplayProperties "Title,Author,Size,Path,Description,EditorOWSUSER,LastModifiedTime,CollapsingStatus,DocId,HitHighlightedSummary,HitHighlightedProperties,FileExtension,ViewsLifeTime,P
arentLink,ViewsRecent,FileType,IsContainer,SecondaryFileExtension,DisplayAuthor,docaclmeta,ServerRedirectedURL,SectionNames,SectionIndexes,ServerRedirectedEmbedURL,S
erverRedirectedPreviewURL" -DisplayTemplateUrl "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Word.js" -OptimizeForFrequentUse $true

Do a full crawl
There is one managed property containing the link how to embed the preview of the document - this one is built during a crawl. So just do a full crawl and everything should be set.

References:
Office Web Apps Powershell cmdlets: http://technet.microsoft.com/en-us/library/jj219457.aspx


SharePoint Distributed Cache

Distributed Cache Service in SharePoint 2013

What is Distributed Cache in SharePoint 2013:  The SharePoint Distributed Cache service is an additional caching mechanism introduced in SharePoint 2013 to support beyond the options that already exist (such as Object Cache, BLOB Cache, and Page Output Cache) from the earlier versions of SharePoint. Distributed cache enables to quickly retrieve data without any dependency on SQL databases, as everything is stored in memory.  The Distributed Cache service provides caching services for several features in SharePoint Server 2013. Some of the features that use the Distributed Cache service include:   
  • News feed 
  • Authentication 
  • OneNote client access 
  • Security Trimming 
  • Page load performance 
How to Install SharePoint Distributed Cache?  The good news is: You don't have to do anything to get distributed cache service features! When you install SharePoint 2013, distributed cache gets installed and configured automatically! The Distributed Cache service is built on Windows Server AppFabric, which is a required component for SharePoint 2013 and is installed as part of the SharePoint 2013 prerequisite installer.  Distributed Cache service - Hosts - Cluster and Modes: Any server in the farm running the Distributed Cache service is known as a cache host. A cache cluster is the group of all cache hosts in a SharePoint Server 2013 farm. A cache host joins a cache cluster when a new application server running the Distributed Cache service is added to the farm. When using a cache cluster, the Distributed Cache spans all application servers and creates one cache in the server farm. Distributed Cache service can be deployed in two modes:   
  • Dedicated mode 
  • Collocated mode. 
When running in dedicated mode, the Distributed Cache service is started and all other services are stopped on the server. In collocated mode, the Distributed Cache service is running along with other services on the server. For large-scale production use, the recommendation is to have dedicated servers hosting your cache.  If you have over 10000 users, you should look into a dedicated server (dedicated mode) Distributed Cache.   Should I Start Distributed Cache Service in All Servers of the Farm? The Distributed Cache is started and run on all WFE and APP servers by default. Running distributed cache on an already overtaxed server, such as SQL Server, Search services, Excel Services, or Project Services, negates any benefit you may garner out of distributed cache. As per Microsoft: When the Distributed Cache service runs on a server together with other services and the server's memory resources near 95% utilization, the Distributed Cache will start throttling requests. This means that the Distributed Cache service will no longer accept read and write requests until the server utilization reduces to approximately 70% utilization    If your farm is having four or more servers, starting distributed cache service in all servers results performance degrade, as per this Technet article https://technet.microsoft.com/en-us/library/jj891124.aspx  Get Distributed Cache Cluster-Servers: Use this cmdlets to retrieve current cache setup:   
1 
2 
Use-CacheCluster 
Get-CacheHost 
This gets you the cache hosts, their ports, service status and version info.  How to Add Distributed Cache on a new server: You can add a server to distributed cache host by running the cmdlet:   
1 
Add-SPDistributedCacheServiceInstance 
Verify the distributed cache Service:   
  • Go to: Central Administration >> Services on server >> Pick the relevant server >> Check Distributed cache service must be in Started state. 
  • Open Windows Services console (services.msc) > Locate "AppFabric Caching service">> Make sure its Started. 

Memory Allocation for Distributed Cache: A minimum of 8 GB and maximum of 16 GB can be allocated to the Cache. On a server that has more than 16 GB of total physical memory, allocate a maximum of 16 GB of memory to the Distributed Cache service. By default, the Distributed memory allocation size defaults to a value of 10 percent of total physical memory when SharePoint Server 2013 installs. You can change the memory allocation with the Update-SPDistributedCacheSize cmdlet. This allocation significantly affects the performance of the Distributed Cache service. Ensure that the memory allocation assigned to the Distributed Cache service is the same on all servers that are running the Distributed Cache service  How to Stop or Restart Distributed Cache Service: The Distributed Cache service can be stopped via the Central Administration. To stop (not remove) the Distributed Cache service by using Central Administration: 
In Central Administration, click Application Management. In Service Applications 
  • Click Manage Services on Server. On the Services on Server page, locate the Distributed Cache service.  
  • If the Distributed Cache service is started and you want to stop the service, under Action, click Stop or restart. 
Firewall configuration considerations 
The Distributed Cache service uses the following communication ports:   
  • 22233 
  • 22234 
  • 22235 
  • 22236  

Cache Port The cache port is used for transmitting data between the cache hosts and your cache-enabled application. The default is 22233. 

Cluster Port The cache hosts use the cluster port to communicate availability to each of their neighbors in the cluster. The default is 22234. 

Arbitration Port If a cache host fails, the arbitration port is used to make certain that the cache host is unavailable. The default is 22235. 

Replication Port The replication port is used to move data between hosts in the cache cluster. This supports features such as high availability and load balancing. The default is 22236. 

How to Remove Distributed Cache Service: To remove distributed Cache service from the server, use PowerShell. Going to Services on Server from SharePoint Central Administration site and clicking "Stop" next to distributed just stops the service but doesn't remove it from the cache cluster. You have to actually remove the service from the servers instead of stopping it to remove it! Use this PowerShell cmdlet:When you remove a server from the cache cluster, you must first perform a graceful shutdown on the server that you want to remove. This graceful shutdown transfers all cached data on the server to other servers within the cache cluster.   
1 
2 
Stop-SPDistributedCacheServiceInstance -Graceful 
Remove-SPDistributedCacheServiceInstance 
Run this cmdlet on server(s) that doesn't need to run the Distributed Cache service. This simply removes the current server from cache host and Services on Server for the selected server! Removing the Distributed cache service instance and this will stop the app fabric caching service in service.msc, as well.  
  
Network Connectivity 

If you plan to have more than one Cache Host, the first server added should be configured to allow inbound ICMPv4 traffic. If you are using Windows Firewall, you can enable this in PowerShell with the Set-NetFirewallRule cmdlet. The name of the rule is “File and Printer SharePoint (Echo request – ICMPv4-In)”. Notice also that it doesn’t take a Boolean ($true), but rather the string “True” as an argument to the -Enabled parameter. Don’t forget to Import-Module NetSecurity first, though! 

Starting and Stopping the Service 

Once the Distributed Cache service instance is started on any server in your farm, it will become part of your Cache Cluster. 
The right way to start the service is with the
 Add-SPDistributedCacheServiceInstance PowerShell cmdlet. 

You run this on a SharePoint server you would like to add to your Cache Cluster, which makes the current server a Cache Host. Simply stopping the service instance would cause the contents of the cache on that server to go missing, degrading performance.  

If you need to remove a server from the Cache Cluster, the safe way to do this is first to use 
Stop-SPDistributedCacheServiceInstance with the –Graceful parameter. 
This transfers any cached data to another server, and can therefore take some time to perform. Afterwards you can safely run
Remove-SPDistributedCacheServiceInstance to make the current server a non-Cache Host.