Wednesday 18 September 2013

SharePoint Search Configuration

I have three servers for SharePoint FARM setup: (For single FARM (Standalone) please scroll down ..)

1- mySPDb-SRV -> Database Server
2- mySPAP-SRV  -> Application server as well as WFE1
3- mySPWFE-SRV -> WFE2

I need to configure the search on the above FARM topology. My central admin is on my Application server.
So I have decided to configure Search on Application server and attach the instance WFE2.
For this we have only PowerShell cmdlet available.

So I have done it as follows(Please make sure search service must be started on both WFEs):

1- Created Search Service Application 1st on Application server (Where central admin available)

$SearchAppPoolName = "SearchServiceAppPool"
$SearchAppPoolAccountName = "Domain\DomainUser" #(Make sure user should have permissions to                                                    #create it as well user should be in managed                                                  #account)
$SearchServiceName = "SharePoint Search Service"
$SearchServiceProxyName = "SharePoint Search Service Proxy"

$DatabaseServer = "(IP/MachineName)\DatabaseInstance Name"
$DatabaseName = "SP_Search_AdminDB"

Write-Host -ForegroundColor Red "Checking if Search Application Pool exists"
$spAppPool = Get-SPServiceApplicationPool -Identity $SearchAppPoolName -ErrorAction SilentlyContinue
if (!$spAppPool)
{
    Write-Host -ForegroundColor Cyan "Creating Search Application Pool"
    $spAppPool = New-SPServiceApplicationPool -Name $SearchAppPoolName -Account $SearchAppPoolAccountName -Verbose
}

Write-Host -ForegroundColor Green "Checking if Search Service Application exists"
$ServiceApplication = Get-SPEnterpriseSearchServiceApplication -Identity $SearchServiceName -ErrorAction SilentlyContinue
if (!$ServiceApplication)
{
    Write-Host -ForegroundColor Yellow "Creating Search Service Application"
    $ServiceApplication = New-SPEnterpriseSearchServiceApplication -Name $SearchServiceName -ApplicationPool $spAppPool.Name -DatabaseServer  $DatabaseServer -DatabaseName $DatabaseName
}

Write-Host -ForegroundColor Cyan "Checking if Search Service Application Proxy exists"
$Proxy = Get-SPEnterpriseSearchServiceApplicationProxy -Identity $SearchServiceProxyName -ErrorAction SilentlyContinue
if (!$Proxy)
{
    Write-Host -ForegroundColor Yellow "Creating Search Service Application Proxy"
    New-SPEnterpriseSearchServiceApplicationProxy -Name $SearchServiceProxyName -SearchApplication $SearchServiceName

}

Now We have Search Service application and proxy is created. We can find it from Central Admin

2-Configure Search service instances:

#Prepare the topology variables
$hostApp1 = Get-SPEnterpriseSearchServiceInstance -Identity "mySPAP-SRV"
$hostWF1 = Get-SPEnterpriseSearchServiceInstance -Identity "mySPWFE-SRV"

Start-SPEnterpriseSearchServiceInstance -Identity $hostApp1
Start-SPEnterpriseSearchServiceInstance -Identity $hostWF1 

#Get services status
Get-SPEnterpriseSearchServiceInstance -Identity $hostApp1
Get-SPEnterpriseSearchServiceInstance -Identity $hostWF1

(#Wait till SPEnterpriseSearchServiceInstance be online and then execute the below code)


#Setting up the topology
$ssa = Get-SPEnterpriseSearchServiceApplication
$newTopology = New-SPEnterpriseSearchTopology -SearchApplication $ssa

#mySPAP-SRV

#Enterprise Search Admin Component
New-SPEnterpriseSearchAdminComponent -SearchTopology $newTopology -SearchServiceInstance $hostApp1

 #Enterprise Search Crawl Component
New-SPEnterpriseSearchCrawlComponent -SearchTopology $newTopology -SearchServiceInstance $hostApp1

#Enterprise Search Content Prosessing Conmponent
New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $hostApp1

#Enterprise Search AnalyticsProcessing Component
New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $hostApp1

#Enterprise Search Query Processing Component (As I declared that it will also work as WFE so this needs to be configured. It is not essential to configure on Application server)
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $hostApp1


#Enterprise Search Index Component
New-SPEnterpriseSearchIndexComponent -SearchTopology $newTopology -SearchServiceInstance $hostApp1 -IndexPartition 0

#mySPWFE-SRV
#Enterprise Search Query Processing Component
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $hostWF1

Set-SPEnterpriseSearchTopology -Identity $newTopology

# Verify the Topology
Get-SPEnterpriseSearchTopology -SearchApplication $ssa

Now here is a catch. topology will throw following error:
Could not connect to the Host Controller service on server. Topology Activation could not be started........

I have googled almost 5-6 Hrs and tried each and every solutions. But the answer I found only Christoph Distefano's Post
Actually issue was with firewall settings on SharePoint servers.
1st I tried with firewall off mode on both SharePoint servers. 
WOW..... Its working fine.
Then I have created Inbound rule in both SharePoint servers firewall for the above servers port so that they can by pass the servers firewall.

And Its done. Working like a charm. Thanks to Christoph.
Now this post can save your 4-5 hrs :)

One more issue always we face while configuring SharePoint Search in SharePoint 2013
"Unable to retrieve topology component health states. This may be because the admin component is not up and running."

For this I used the below PowerShell cmdLet

$AP = Get-SPServiceApplicationProxy | where {$_.TypeName -like "Usage*"} 
$AP.Provision() 


and then Activated the search topology. And its working for me.

For single FARM (STAND ALONE) please use below PowerShell cmdLet to configure SharePoint Search

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$IndexLocation = "D:\SP2013Search"  #Location must be empty, will be deleted during the process!
$SearchAppPoolName = "Search App Pool"
$SearchAppPoolAccountName = "Domain\sp_admin"
$SearchServiceName = "Search SA"
$SearchServiceProxyName = "Search SA Proxy"
$DatabaseServer = "Server"
$DatabaseName = "SP2013_Search"

Write-Host -ForegroundColor Yellow "Checking if Search Application Pool exists"
$spAppPool = Get-SPServiceApplicationPool -Identity $SearchAppPoolName -ErrorAction SilentlyContinue

if (!$spAppPool)
{
    Write-Host -ForegroundColor Green "Creating Search Application Pool"
    $spAppPool = New-SPServiceApplicationPool -Name $SearchAppPoolName -Account $SearchAppPoolAccountName -Verbose
}

Write-Host -ForegroundColor Yellow "Checking if Search Service Application exists"
$ServiceApplication = Get-SPEnterpriseSearchServiceApplication -Identity $SearchServiceName -ErrorAction SilentlyContinue
if (!$ServiceApplication)
{
    Write-Host -ForegroundColor Green "Creating Search Service Application"
    $ServiceApplication = New-SPEnterpriseSearchServiceApplication -Name $SearchServiceName -ApplicationPool $spAppPool.Name -DatabaseServer  $DatabaseServer -DatabaseName $DatabaseName
}

Write-Host -ForegroundColor Yellow "Checking if Search Service Application Proxy exists"
$Proxy = Get-SPEnterpriseSearchServiceApplicationProxy -Identity $SearchServiceProxyName -ErrorAction SilentlyContinue
if (!$Proxy)
{
    Write-Host -ForegroundColor Green "Creating Search Service Application Proxy"
    New-SPEnterpriseSearchServiceApplicationProxy -Name $SearchServiceProxyName -SearchApplication $SearchServiceName
}

$searchInstance = Get-SPEnterpriseSearchServiceInstance -local
Write-Host -ForegroundColor DarkGray "Checking if SSI is Online on local server"
 if($searchInstance.Status -ne "Online")
 {
   Write-Host -ForegroundColor Yellow "Starting Search Service Instance"
   Start-SPEnterpriseSearchServiceInstance -Identity $searchInstance
   While ($searchInstance.Status -ne "Online")
   {
       Start-Sleep -s 5
   }
   Write-Host -ForegroundColor Yellow "SSI on local Server is started"
 }


$InitialSearchTopology = $ServiceApplication | Get-SPEnterpriseSearchTopology -Active
$SearchTopology = $ServiceApplication | New-SPEnterpriseSearchTopology

New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance
New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance
New-SPEnterpriseSearchCrawlComponent -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance
New-SPEnterpriseSearchAdminComponent -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance

set-SPEnterpriseSearchAdministrationComponent -SearchApplication $ServiceApplication -SearchServiceInstance  $searchInstance

Remove-Item -Recurse -Force -LiteralPath $IndexLocation -ErrorAction SilentlyContinue
mkdir -Path $IndexLocation -Force

New-SPEnterpriseSearchIndexComponent -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance -RootDirectory $IndexLocation

Write-Host -ForegroundColor Green "Activating new topology"
$SearchTopology.Activate()

Write-Host -ForegroundColor Yellow "Next call will provoke an error but after that the old topology can be deleted - just ignore it!"
$InitialSearchTopology.Synchronize()

Write-Host -ForegroundColor Yellow "Deleting old topology"
Remove-SPEnterpriseSearchTopology -Identity $InitialSearchTopology -Confirm:$false
Write-Host -ForegroundColor Green "Old topology deleted"
Write-Host -ForegroundColor Green "Done - start a full crawl and you are good to go (search)."

If you are getting the following error:
Unable to retrieve topology component health states. This may be because the admin component is not up and running.

Solution is (Using PowerShell):
Set-SPEnterpriseSearchService -PerformanceLevel Reduced

3 comments :

  1. Good consolidated Post for configuring search.
    It helped me a lot. Thanks Ajeet. Keep posting

    ReplyDelete
  2. Nice Post for search configuration.
    Keep Posting

    ReplyDelete
  3. Good one. Thanks for this post.

    ReplyDelete