Wednesday, May 28, 2014

SharePoint 2013: How to deploy a search service application using PowerShell

Introduction
SharePoint 2013 Deployment Series
How to setup a database server alias
How to configure cache
How to deploy a search service application using PowerShell
You have deployed a new SharePoint Server 2013 farm.  You now wish to provision the farm's Search Service Application and to do so via PowerShell so as to be able to define simple custom search database names.  This posting shows you how.  This posting assumes a five-server farm, including: one database server, one application server, two web front end servers and one Office Web Apps server. All servers are VMs hosted on Microsoft Hyper-V.  And it assumes two service accounts will be used: a content access account and an account used to run the Admin and query services.  The search topology that will be deployed will be the following:
SSL is not used to connect to the primary web application content source.

Procedure
  1. Remove Existing Search
    1. Remove the existing Search Service Application (if it exists):
      1. In Central Administration, navigate to Manage Service Applications.
      2. Select the row corresponding to the search service application.
      3. Select the SERVICE APPLICATIONS tab, and then click the Delete button.
      4. At the prompt, enable the option to remove all data as well.
      5. Check the Manage Service Applications page to verify that all three of these have been removed:
        1. Search Administration Web Service for Search Service
        2. Search Service
        3. Search Service Application Proxy
      6. Check SQL Server to verify that all the search content and associated transaction log databases have been removed.
    2. Remove Search Application Pools
      1. In the SharePoint Management Shell, execute Get-SPServiceApplicationPool.
      2. Verify that no search application pools are listed.
      3. If any are, remove them using Remove-SPServiceApplicationPool.
  2. Preparation
    1. Verify setup user administrator account (eg, spAdmin) is member of local Administrator group on all farm servers.
    2. Identify service accounts and passwords:
      1. Content Access service account
      2. Administration and query service account
    3. Map the Admin service account to diagnostic logging database as dbo.
    4. Identify the web front end server names
      1. WFE1
      2. WFE2
    5. Identify the drive on the servers where you want to store indexes.  This drive must be the same on all farm servers hosting SharePoint.
      1. (eg) D:\SPIndex
    6. Verify that any application pools created for previous installations (if any) of the Search Service Application have been removed.
      1. (eg) Search Service AppPool
  3. Execution
    1. Instantiate Search Services
      1. Remote into the application server as the setup user administrator account.
      2. Open the SharePoint 2013 Management Shell as administrator.
      3. Download this script: Enterprise Search Deployment Script.
      4. Edit variable as appropriate to your farm.
      5. Run the script.
      6. After completion of the script, navigate to the Search Service Administration page and verify that the search service topology is similar to what is presented above.
      7. Verify that the default content access service account is set as the crawl account.
    2. Configure Content Sources
      1. In CA, navigate to Content Sources, and then click on Local SharePoint sites (it will be the only item in the list at present).
      2. Note the sources (URLs) present.
      3. Create individual content sources for each of these URLs so that they can be crawl scheduled individually.  So, for example, configure the following entries:
        1. Local SharePoint sites: point it to your primary web application.  If your farm has more than one web application supporting user websites, creating individual entries for each.
        2. My Sites Content: point this to your farm's My Site web application.
        3. User Profile Content: point this to the URL for crawling user profiles.  It will have the form like: sps3://MySites.com (non-SSL).
      4. Configure crawl schedules for each content source as appropriate.  Create full and incremental schedules.
    3. Configure Global Search Center
      1. Create a Search Center.  Deploy this within the primary web application or in a new web application as appropriate to your needs.  I recommend adding it to your existing primary web application.
      2. In CA, navigate to the Search Service Administration page, and then set the Global Search Center URL to the Search Center you have created for your web application.
    4. Configure SSL Content sources
      1. If your search service needs to use SSL to crawl certain content sources, you will need to configure the service to ignore SSL warnings.
      2. In CA, go to: General Application Settings > Search > Farm Search Administration.
      3. In the Farm-Level Search Settings group, look for Ignore SSL warnings.
      4. Click No.
      5. Enable Ignore SSL certificate name warnings.
      6. Click OK.
  4. Miscellaneous
    1. If you plan to perform farm backups through Central Administration or PowerShell, be sure to grant the Search service account read and write permissions to the backup folder.  Otherwise, farm backups will fail on backup of the Search service configuration and data.  This is new from 2010.
References
Notes
  • Farm topology: This procedure was executed on a five-server farm (including OWA and SQL), Windows Server 2012 VMs.
  • Deleting the Search Service Application through Central Administration does not remove the application pools that were created for the Search Service Application.  Thus, to completely remove all artifacts associated with the Search Service Application, and thus be able to start over from scratch, you must also manually remove those application pools that were created for it.
  • Default Content Sources: After deploying the Search Service Application, you will need to configure content sources. Your farm content sources (aside from CA) will automatically have their URLs added to the Local SharePoint sites group - including My Sites.  I recommend separating content sources, so as to be able to implement separate crawl schedules for them.  Not all content sources require as frequent crawling as your primary web applications.
  • User profile content: if you want to enable searches of user profiles, you will need to add the URL for this manually.
  • Search Service Account access to backup folder: I don't know how or why, but in SharePoint 2013, the Search Service Account plays a role in the farm backup process when it comes to backup of Search. This was not the case in SharePoint 2010, where I only had to grant the farm and sql server service accounts this access.  I discovered this new wrinkle while actually trying to perform a full farm backup for the first time and then troubleshooting and resolving its initial failure.
  • Removing Search via PowerShell.  First, get the Identity of the application.  Then run the command to remove:
    Get-SPServiceApplication | ?{$_.name -like "*Search*"}
    $spapp = Get-SPServiceApplication -identity [
    Remove-SPServiceApplication $spapp -RemoveData
    If you don't use the "-RemoveData" switch parameter, the search databases and their associated transaction logs will remain; and then you'll see "A databases exception occurred..." error appear in the shell window when you try to execute New-SPEnterpriseSearchServiceApplication.  

No comments: