当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 在 SharePoint 2016 多服务器场中创建搜索服务应用程序

作者:精品下载站 日期:2024-12-14 14:45:14 浏览:13 分类:玩电脑

使用 PowerShell 在 SharePoint 2016 多服务器场中创建搜索服务应用程序


顾名思义,SharePoint 中的搜索服务应用程序提供搜索功能。从 SharePoint 2013 开始,我们必须使用 PowerShell 脚本来配置搜索服务应用程序。尽管我们可以创建新的搜索服务应用程序实例,但没有用于从 SharePoint Central Admin 配置搜索拓扑的用户界面。

为多服务器场配置 SharePoint 2016 搜索服务应用程序:

虽然我之前的文章介绍了如何在 SharePoint 2013 中创建搜索服务应用程序 - 单服务器场,用于独立的 SharePoint 2013 或 SharePoint 2016 安装,但在生产环境中,我们可能必须将搜索组件分发到多服务器中的不同服务器并进行负载平衡。 -服务器群。

以下是建议的高级场搜索拓扑:

[玩转系统] 使用 PowerShell 在 SharePoint 2016 多服务器场中创建搜索服务应用程序

我的 SharePoint 2016 环境中有以下使用共享 MinRoles 的服务器:

  • Web 前端 + 分布式缓存服务器 - 2
  • 应用程序 + 搜索服务器 - 2

由于我们将在 SharePoint 场中使用多个服务器,因此我们可以通过拆分六个搜索组件(管理、爬网、内容处理、索引、分析和查询处理)来向搜索应用程序添加冗余、性能和可靠性。此外,我们将配置两个索引分区,以确保两台服务器都有搜索索引的副本。

在 SharePoint 2016 中配置搜索服务应用程序的 PowerShell:

对搜索拓扑的修改需要对 SharePoint 搜索拓扑和 PowerShell 有深入的了解。以下是用于在多服务器 SharePoint 2016 环境中创建搜索服务应用程序的 PowerShell 脚本。您可以根据您的环境添加或修改拓扑组件。让我们举个例子。就我而言,我们有两个 SharePoint 搜索应用服务器来托管所有搜索组件。为 SharePoint 2016 创建搜索服务应用程序涉及以下高级步骤:

  1. 为搜索服务应用程序创建托管帐户和应用程序池。
  2. 创建 SharePoint 搜索服务应用程序和代理
  3. 在参与搜索拓扑的所有服务器上启动搜索服务实例
  4. 创建搜索拓扑并添加搜索组件,然后激活搜索拓扑

使用 PowerShell 创建搜索服务应用程序:

以下是用于创建 SharePoint 2016 搜索服务应用程序的 PowerShell 脚本。

将此脚本复制粘贴到 PowerShell ISE 或任何其他 PowerShell 编辑器(PowerGUI?),根据您的环境设置配置参数并一次运行一步!

在运行主脚本之前,在托管搜索拓扑索引组件的所有服务器上为索引位置和副本位置创建文件夹(如变量:$PrimaryIndexLocation 和 $ReplicaIndexLocation)!


#Set the primary and replica index locations
$PrimaryIndexLocation = "D:\SearchIndex"
$ReplicaIndexLocation = "E:\SearchIndexReplica"

#Prepare Index Locations
Remove-Item -Recurse -Force -LiteralPath $PrimaryIndexLocation -ErrorAction SilentlyContinue
MKDIR -Path $PrimaryIndexLocation -Force
Remove-Item -Recurse -Force -LiteralPath $ReplicaIndexLocation -ErrorAction SilentlyContinue
MKDIR -Path $ReplicaIndexLocation -Force

用于在 SharePoint 2016 中配置搜索服务应用程序的 PowerShell 脚本:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Region Config_Parameters
#Settings for Search Service Application
$SearchServiceApplicationName = "Search Service Application"
$SearchServiceApplicationProxyName = "Search Service Application Proxy"
$SearchAppPoolAccount = "Crescent\SP16_Services"
$SearchDatabaseServer = "SP16_SQL"
$SearchServiceApplicationDatabase = "Crescent_Search_ServiceApp"
$SearchAppPoolName = "Service Application App Pool"

#Farm Server topology: App with Search role: 2
$SearchAppServer1 = "SP16-APPSrv01"
$SearchAppServer2 = "SP16-APPSrv02"

#Set the primary and replica index locations
$PrimaryIndexLocation = "D:\SearchIndex"
$ReplicaIndexLocation = "E:\SearchIndexReplica"
#EndRegion


#*** Step 1: Create Managed Account, Service Application Pool for Search Service Application **** 
#Check if Managed account is registered already
Write-Host -ForegroundColor Yellow "Checking if the Managed Accounts already exists..."
$SearchAppPoolAccount = Get-SPManagedAccount -Identity $SearchAppPoolAccount -ErrorAction SilentlyContinue
If ($SearchAppPoolAccount -eq $null)
{
    Write-Host "Please Enter the password for the Service Account..."
    $AppPoolCredentials = Get-Credential $SearchAppPoolAccount
    $SearchAppPoolAccount = New-SPManagedAccount -Credential $AppPoolCredentials
    write-host "Managed Account has been Created!" -ForegroundColor Green
}

#Try to Get the existing Application Pool
Write-Host -ForegroundColor Yellow "Checking if the App Pool already exists..."
$SearchServiceAppPool = Get-SPServiceApplicationPool -Identity $SearchAppPoolName -ErrorAction SilentlyContinue
#If Application pool Doesn't exists, Create it
if ($SearchServiceAppPool -eq $Null)
{ 
    $SearchServiceAppPool = New-SPServiceApplicationPool -Name $SearchAppPoolName -Account $SearchAppPoolAccount 
    write-host "Created New Service Application Pool!" -ForegroundColor Green
}

#*** Step 2: Start Search Service Instances on required servers ***
Write-host "Starting Service Instances..." -ForegroundColor Green
#Search App Server 1
$SearchAppInstance1 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer1
if(-not($SearchAppInstance1.Status -eq "Online"))
{
    Write-Host -ForegroundColor Yellow "Starting Search Service instance on $SearchAppServer1..." -NoNewline
    $SearchAppInstance1 | Start-SPEnterpriseSearchServiceInstance
    while ($SearchAppInstance1.Status -ne "Online")
    {
        Write-Host -ForegroundColor Green "." -NoNewline
        Start-Sleep -Seconds 5
        $SearchAppInstance1 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer1
    }
    Write-Host -ForegroundColor Green "Started Search Service instance on $SearchAppServer1"
}
Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $SearchAppServer1 -ErrorAction SilentlyContinue

#Search App Server 2
$SearchAppInstance2 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer2
if(-not($SearchAppInstance2.Status -eq "Online"))
{
    Write-Host -ForegroundColor Yellow "Starting Search Service instance on $SearchAppServer2..." -NoNewline
    $SearchAppInstance2 | Start-SPEnterpriseSearchServiceInstance
    while ($SearchAppInstance2.Status -ne "Online")
    {
        Write-Host -ForegroundColor Green "." -NoNewline
        Start-Sleep -Seconds 5
        $SearchAppInstance2 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer2
    }
    Write-Host -ForegroundColor Green "Started Search Service instance on $SearchAppServer2"
}
Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $SearchAppServer2 -ErrorAction SilentlyContinue

#*** Step 3: Create Search Service Application and proxy**** 
Write-host "Creating Search Service Application..." -ForegroundColor Yellow
# Get the Search Service Application
$SearchServiceApplication = Get-SPEnterpriseSearchServiceApplication -Identity $SearchServiceApplicationName -ErrorAction SilentlyContinue
# Create the Search Service Application, If it doesn't exist! 
if(!$SearchServiceApplication)
{
    $SearchServiceApplication = New-SPEnterpriseSearchServiceApplication -Name $SearchServiceApplicationName -ApplicationPool $SearchServiceAppPool -DatabaseServer $SearchDatabaseServer -DatabaseName $SearchServiceApplicationDatabase
    write-host "Created New Search Service Application" -ForegroundColor Green
}

#Get the Search Service Application Proxy
$SearchServiceAppProxy = Get-SPEnterpriseSearchServiceApplicationProxy -Identity $SearchServiceApplicationProxyName -ErrorAction SilentlyContinue
# Create the Proxy If it doesn't exist! 
if(!$SearchServiceAppProxy)
{
    $SearchServiceAppProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name $SearchServiceApplicationProxyName -SearchApplication $SearchServiceApplication 
    write-host "Created New Search Service Application Proxy" -ForegroundColor Green
}

#*** Step 4: Create New Search Topology and add components to it
Write-Host -ForegroundColor Yellow "Creating Search Service Topology..."
# Create New Search Topology 
$SearchTopology =  New-SPEnterpriseSearchTopology -SearchApplication $SearchServiceApplication

#Admin Component: App 01 and 02
New-SPEnterpriseSearchAdminComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance1
New-SPEnterpriseSearchAdminComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance2

#Content Processing: App 01 and 02
New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance1
New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance2

#Analytics processing: App01 and 02
New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance1
New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance2

#Crawl components: App 01 and 02
New-SPEnterpriseSearchCrawlComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance1
New-SPEnterpriseSearchCrawlComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance2

#Query processing: App 01 and 02
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance1
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance2

#Create Index Components: App 01 and 02
#Two index partitions and replicas for each partition
New-SPEnterpriseSearchIndexComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance1 -RootDirectory $PrimaryIndexLocation -IndexPartition 0
New-SPEnterpriseSearchIndexComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance2 -RootDirectory $ReplicaIndexLocation -IndexPartition 0
New-SPEnterpriseSearchIndexComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance2 -RootDirectory $PrimaryIndexLocation -IndexPartition 1
New-SPEnterpriseSearchIndexComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance1 -RootDirectory $ReplicaIndexLocation -IndexPartition 1

#Activate the Topology for Search Service
$SearchTopology.Activate() # Or Use: Set-SPEnterpriseSearchTopology -Identity $SearchTopology

#Remove all inactive topologies
$InactiveTopologies = Get-SPEnterpriseSearchTopology -SearchApplication $SearchServiceApplication | Where {$_.State -ne "Active"}
$InactiveTopologies | Remove-SPEnterpriseSearchTopology -Confirm:$false

Write-Host -ForegroundColor Green "Search Service Application has been created. Please start a Full Crawl!"

一切设置完毕后,您可以从 SharePoint 管理中心站点直观地看到搜索拓扑。

[玩转系统] 使用 PowerShell 在 SharePoint 2016 多服务器场中创建搜索服务应用程序

将 SharePoint 2016 搜索横向扩展至多个服务器:

上述脚本适用于具有两个“带搜索的应用程序”服务器的 SharePoint 场。如果您的 SharePoint 场有两个以上的应用程序服务器(例如四个)怎么办?

最佳实践:将查询和索引组件一起分配到同一服务器中,并将其余组件放置到其他搜索应用程序服务器上。

[玩转系统] 使用 PowerShell 在 SharePoint 2016 多服务器场中创建搜索服务应用程序

另外,在脚本中,进行以下更改: Farm Topology 部分,包括另外两个服务器:Say,App03 和 App04


#Farm Server topology: App+Search: 4
$SearchAppServer1 = "Cre-SP16App01"
$SearchAppServer2 = "Cre-SP16App02"
$SearchAppServer3 = "Cre-SP16App03"
$SearchAppServer4 = "Cre-SP16App04"

在应用程序服务器 3 和 4 上启动服务实例:


#Search App Server 3
$SearchAppInstance3 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer3
if(-not($SearchAppInstance3.Status -eq "Online"))
{
    Write-Host -ForegroundColor Yellow "Starting Search Service instance on $SearchAppServer3..." -NoNewline
    $SearchAppInstance3 | Start-SPEnterpriseSearchServiceInstance
    while ($SearchAppInstance3.Status -ne "Online")
    {
        Write-Host -ForegroundColor Green "." -NoNewline
        Start-Sleep -Seconds 5
        $SearchAppInstance3 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer3
    }
    Write-Host -ForegroundColor Green "Started Search Service instance on $SearchAppServer3"
}
Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $SearchAppServer3 -ErrorAction SilentlyContinue

#Search App Server 4
$SearchAppInstance4 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer4
if(-not($SearchAppInstance4.Status -eq "Online"))
{
    Write-Host -ForegroundColor Yellow "Starting Search Service instance on $SearchAppServer4..." -NoNewline
    $SearchAppInstance4 | Start-SPEnterpriseSearchServiceInstance
    while ($SearchAppInstance4.Status -ne "Online")
    {
        Write-Host -ForegroundColor Green "." -NoNewline
        Start-Sleep -Seconds 5
        $SearchAppInstance4 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer4
    }
    Write-Host -ForegroundColor Green "Started Search Service instance on $SearchAppServer4"
}
Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $SearchAppServer4 -ErrorAction SilentlyContinue 

创建搜索拓扑时:将查询和索引角色分配给应用程序服务器 3 和 4


#Query processing: App 03 and 04
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance3
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance4

#Create Index Components: App 03 and 04
#Two index partitions and replicas for each partition
New-SPEnterpriseSearchIndexComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance3 -RootDirectory $PrimaryIndexLocation -IndexPartition 0
New-SPEnterpriseSearchIndexComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance4 -RootDirectory $ReplicaIndexLocation -IndexPartition 0
New-SPEnterpriseSearchIndexComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance4 -RootDirectory $PrimaryIndexLocation -IndexPartition 1
New-SPEnterpriseSearchIndexComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance3 -RootDirectory $ReplicaIndexLocation -IndexPartition 1

后续步骤:

  • 创建内容源和时间表
  • 创建搜索中心网站
  • 为搜索服务应用程序配置抓取帐户和搜索中心 URL。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯