高度な概念

SQL Serverの高可用性ソリューションを使用する場合のデータベース接続文字列の更新

Citrixは、Always OnやミラーリングなどのSQL Server高可用性データベースソリューションを使用している場合に、XenAppおよびXenDesktop®データベース接続文字列を更新するいくつかのPowerShellスクリプトを提供しています。

XenApp®およびXenDesktop PowerShell APIを使用するスクリプトは次のとおりです。

  • DBConnectionStringFuncs.ps1: 実際の作業を行うコアスクリプトです。このスクリプトには、他のスクリプトが使用する共通関数が含まれています。
  • Change_XD_Failover_Partner_v1.ps1: フェールオーバーパートナーを更新(追加、変更、または削除)します。このスクリプトは、各データベースのフェールオーバーパートナーの場所(FQDN)を要求します。(空のフェールオーバーパートナーを指定すると、フェールオーバーパートナーが削除されます。ClearPartnerオプションを使用してパートナーを削除することもできます。)フェールオーバーパートナーをプライマリデータベースサーバーと同じ場所に設定しないでください。
  • Change_XD_To_ConnectionString.ps1: 提供された接続文字列を使用して、データベースへの接続文字列を更新します。このスクリプトは、特定のCitrixサービスが稼働していることを確認し、サイト内のすべてのControllerでそれらのサービスを正しい順序で更新します。各データベースの接続文字列情報は引用符で囲んでください。
  • Change_XD_To_MultiSubnetFailover.ps1: MultiSubnetFailover=true の追加と削除を切り替えます。Always On可用性グループを使用している場合、Microsoftは接続文字列にMultiSubnetFailover=trueを含めることを推奨しています。このオプションは、高可用性イベントが発生した際の復旧を高速化し、シングルサブネット環境とマルチサブネット環境の両方で推奨されます。このオプションを追加するには、このスクリプトを一度実行します。オプションを削除する必要がある場合は、Change_XD_To_ConnectionString.ps1 を使用してスクリプトを再度実行し、設定なしの文字列を指定してください。
  • Change_XD_To_Null.ps1: 何らかの問題が発生したため、localhost上のすべての接続文字列をリセットします。接続文字列をnullにリセットすることで、このスクリプトはControllerを「初期」状態にします。このスクリプトを実行した後にStudioを実行すると、サイトを作成するか、既存のサイトに参加するかを尋ねられます。これは、何らかの問題が発生してリセットが必要な場合に役立ちます。リセット後、Change_XD_To_ConnectionString.ps1を使用して接続文字列を再度設定できます。

データベース接続文字列は手動で更新することもできます。手動で文字列を更新する を参照してください。PowerShellスクリプトをダウンロードするには、手順 セクションを参照してください。

重要:

この記事はXenDesktop 7.6で作成され、スクリプトもXenDesktop 7.6でテストされました。このドキュメントは、Citrix Virtual Apps and Desktopsの以降のバージョンでは保守またはテストされていません。

要件と考慮すべき点

  • スクリプトを実行するには、フルサイト管理者である必要があります。
  • いずれかのControllerのPowerShellウィンドウでスクリプトを実行します。PowerShell v3が必要です。
  • XenAppおよびXenDesktopのコアコンポーネントがインストールされ、サイトが稼働している必要があります。
  • スクリプトを実行する前に、必須の構成ログを無効にしてください。
  • MultiSubnetFailover オプションは .NET 4.5 以降でサポートされています。ただし、Studio が Windows 7 または 2008 R2 マシンで使用する MMC には以前の .NET バージョンが含まれているため、Studio ナビゲーションペインで Configuration を選択すると、「Keyword not supported: multisubnetfailover」というエラーが表示される場合があります。そのような場合は、次のようにパッチを適用または更新してください。

  • .NET 3.5 SP1 の場合は、http://support.microsoft.com/kb/2654347 でパッチを適用してください。
  • .NET 4.0 の場合は、最低 4.0.2 に更新してください。4.0.3 が推奨されます: http://support.microsoft.com/kb/2600211

次に、Change_XD_To_MultiSubnetFailover.ps1 スクリプトを使用して、このオプションでデータベース接続文字列を更新します。

操作手順

  1. スクリプトを含む zip ファイルを Citrix ShareFile からダウンロードします。
  2. ファイルを解凍します。
  3. 実行するスクリプトは DBConnectionStringFuncs.ps1 の関数を使用するため、DBConnectionStringFuncs.ps1 が実行するスクリプトと同じフォルダーにあることを確認してください。
  4. Controller でスクリプトを実行します。

サイトをマルチサブネットフェールオーバーに設定したい場合は、Change_XD_To_MultiSubnetFailover.ps1 スクリプトを実行するだけで済みます。(注意:DBConnectionStringFuncs.ps1 スクリプトが同じフォルダーにあることを確認してください。)

ヒント:

  • 接続文字列が更新されているとき、「Server=SQLxxx\\CITRIX\\...」が「Data Source=SQLxxx\\CITRIX\\...」に変更されていることを示すメッセージが表示されるのは正常です。Server と Data Source は同義語です。
  • 接続文字列を操作したい場合は、Change\_XD\_ スクリプトが DBConnectionStringFuncs.ps1 の関数をどのように使用しているかを確認してください。

文字列を手動で更新する

文字列を手動で更新するには、XenAppおよびXenDesktop PowerShellコマンドレットを実行します。

手順 1. SQLデータベースを別のSQLサーバーに移動し、適切な権限を割り当てます

  1. 元のSQLサーバー上のデータベースをバックアップし、新しいSQLサーバーに復元します。
  2. SQL Management Studio > Security > Logins のパスにおいて、Delivery Controller のコンピューターアカウントを追加してください。例えば、CORP\DDC01$ のように指定します。
  3. SQLログインを追加するときは、ユーザーマッピングページで、3つのCitrixデータベース(Siteデータベース、Monitoringデータベース、Loggingデータベース)をクリックします。
  4. 3つのCitrixデータベースのそれぞれについて、Delivery Controller™コンピューターアカウントをさまざまなデータベースロールに追加します。Siteデータベースには、LoggingデータベースおよびMonitoringデータベースよりも多くのロールがあります。
Site database - ADIdentitySchema_ROLE

Site database - Analytics_ROLE                # for 7.8 and newer
Site database - AppLibrarySchema_ROLE         # for 7.8 and newer
Site database - chr_Broker
Site database - chr_Controller
Site database - ConfigLoggingSiteSchema_ROLE
Site database - ConfigurationSchema_ROLE
Site database - DAS_ROLE
Site database - DesktopUpdateManagerSchema_ROLE
Site database - EnvTestServiceSchema_ROLE
Site database - HostingUnitServiceSchema_ROLE
Site database - Monitor_ROLE
Site database - OrchestrationSchema_ROLE       # for 7.11 and newer
Site database - public
Site database - StorefrontSchema_ROLE          # for 7.8 and newer
Site database - TrustSchema_ROLE               # for 7.11 and newer
Monitoring database - Monitor_ROLE
Monitoring database - public
Logging database - ConfigLoggingSchema_ROLE
Logging database - public
<!--NeedCopy-->

手順 2. 既存のデータベース接続を取得します(オプション)

既存のデータベース接続文字列を表示するには、次のコマンドを実行します。

## Load the Citrix snap-ins
asnp Citrix.*

## Get the current Delivery Controller database connections
Get-ConfigDBConnection
Get-AcctDBConnection
Get-AnalyticsDBConnection              #  for 7.6 and newer
Get-AppLibDBConnection                 #  for 7.8 and newer
Get-OrchDBConnection                   #  for 7.11 and newer
Get-TrustDBConnection                  #  for 7.11 and newer
Get-HypDBConnection
Get-ProvDBConnection
Get-BrokerDBConnection
Get-EnvTestDBConnection
Get-SfDBConnection
Get-MonitorDBConnection
Get-MonitorDBConnection -DataStore Monitor
Get-LogDBConnection
Get-LogDBConnection -DataStore Logging
Get-AdminDBConnection
<!--NeedCopy-->

手順 3. 既存のデータベース接続を削除します

Delivery Controllerで、管理者としてPowerShellを開き、次のコマンドを実行します。このプロセスにより、既存のデータベース接続がクリアされます。

## Note the state of the log site
Get-LogSite

## Load the Citrix snap-ins
asnp Citrix.*

## Disable configuration logging for the XD site:
Set-LogSite -State Disabled

## Clear the current Delivery Controller database connections

## Note: AdminDBConnection must be the last command

Set-ConfigDBConnection -DBConnection $null -Force
Set-AcctDBConnection -DBConnection $null -Force
Set-AnalyticsDBConnection -DBConnection $null -Force             #  for 7.6 and newer
Set-AppLibDBConnection -DBConnection $null -Force                #  for 7.8 and newer
Set-OrchDBConnection -DBConnection $null -Force                  #  for 7.11 and newer
Set-TrustDBConnection -DBConnection $null -Force                 #  for 7.11 and newer
Set-HypDBConnection -DBConnection $null -Force
Set-ProvDBConnection -DBConnection $null -Force
Set-BrokerDBConnection -DBConnection $null
Set-EnvTestDBConnection -DBConnection $null -Force
Set-SfDBConnection -DBConnection $null -Force
Set-MonitorDBConnection -DataStore Monitor -DBConnection $null -Force
Set-MonitorDBConnection -DBConnection $null -Force
Set-LogDBConnection -DataStore Logging -DBConnection $null -Force
Set-LogDBConnection -DBConnection $null -Force
Set-AdminDBConnection -DBConnection $null -Force
<!--NeedCopy-->

エラーメッセージが表示された場合は、すべてのCitrixサービスを再起動する必要があります。

Get-Service Citrix* | Stop-Service -Force
Get-Service Citrix* | Start-Service
<!--NeedCopy-->

Citrixサービスを再起動した後もエラーが表示される場合は、サーバーを再起動する必要があります。元のコマンドセットを再実行して、既存の接続が適切に削除されたことを確認します。

次のコマンドレットは空の出力を返す必要があります。

## Load the Citrix snap-ins
asnp Citrix.*

## Get the current Delivery Controller database connections
Get-ConfigDBConnection
Get-AcctDBConnection
Get-AnalyticsDBConnection              #  for 7.6 and newer
Get-AppLibDBConnection                 #  for 7.8 and newer
Get-OrchDBConnection                   #  for 7.11 and newer
Get-TrustDBConnection                  #  for 7.11 and newer
Get-HypDBConnection
Get-ProvDBConnection
Get-BrokerDBConnection
Get-EnvTestDBConnection
Get-SfDBConnection
Get-MonitorDBConnection
Get-LogDBConnection
Get-AdminDBConnection
<!--NeedCopy-->

手順 4. 新しいデータベース接続文字列を指定します

変数を目的の接続文字列と一致するように調整します。

  • スタンドアロンSQL Server接続文字列の場合: Server=SQLServerName; Initial Catalog=DBName; Integrated Security=True
  • データベースミラーリング接続文字列の場合: Server=PrimarySQLServerName; Initial Catalog=DBName; Integrated Security=True; Failover Partner=SecondSQLServer
  • Always On高可用性の場合: Server=ListenerName; Initial Catalog=XDdb; Integrated Security=True; MultiSubnetFailover=True

新しい接続文字列を設定するには、次のコマンドを実行します。

$ServerName = "<dbserver>"
$SiteDBName = "<SiteDbName>"
$LogDBName = "<LoggingDbName>"
$MonitorDBName = "<MonitorDbName>"
$csSite = "Server=$ServerName;Initial Catalog=$SiteDBName;Integrated Security=True"
$csLogging = "Server=$ServerName;Initial Catalog=$LogDBName;Integrated Security=True"
$csMonitoring = "Server=$ServerName;Initial Catalog=$MonitorDBName;Integrated Security=True"

Set-AdminDBConnection -DBConnection $csSite
Set-ConfigDBConnection -DBConnection $csSite
Set-AcctDBConnection -DBConnection $csSite
Set-AnalyticsDBConnection -DBConnection $csSite              # for 7.6 and newer
Set-HypDBConnection -DBConnection $csSite
Set-ProvDBConnection -DBConnection $csSite
Set-AppLibDBConnection –DBConnection $csSite                 # for 7.8 and newer
Set-OrchDBConnection –DBConnection $csSite                   # for 7.11 and newer
Set-TrustDBConnection –DBConnection $csSite                  # for 7.11 and newer
Set-BrokerDBConnection -DBConnection $csSite
Set-EnvTestDBConnection -DBConnection $csSite
Set-SfDBConnection -DBConnection $csSite
Set-LogDBConnection -DBConnection $csSite
Set-LogDBConnection -DataStore Logging -DBConnection $null -force
Set-LogDBConnection -DataStore Logging -DBConnection $csLogging
Set-MonitorDBConnection -DBConnection $csSite
Set-MonitorDBConnection -DataStore Monitor -DBConnection $null -force
Set-MonitorDBConnection -DataStore Monitor -DBConnection $csMonitoring

## If necessary, enable configuration logging for the XD site:
Set-LogSite -State Enabled
<!--NeedCopy-->

注:

先行するSet-<service>DBConnectionコマンドがすべてOKの結果を返したことを確認してください。これらのコマンドのいずれかで結果がOK以外の場合、接続失敗の原因を特定するためにログ記録またはトレースを有効にする必要があるかもしれません。

Set-LogDBConnection -DBConnection $nullSet-MonitorDBConnection -DBConnection $null は、OK という状態ではなく、DBUnconfigured という状態を返します。

ステップ5. 新しいデータベース接続文字列をテストする

  1. データベースへの接続を確認するには、次のコマンドを実行します。

    ## Load the Citrix snap-ins
    asnp citrix.*
    
    $ServerName = "<dbserver>"
    $SiteDBName = "<SiteDbName>"
    $LogDBName = "<LoggingDbName>"
    $MonitorDBName = "<MonitorDbName>"
    $csSite = "Server=$ServerName;Initial Catalog=$SiteDBName;Integrated Security=True"
    $csLogging = "Server=$ServerName;Initial Catalog=$LogDBName;Integrated Security=True"
    $csMonitoring = "Server=$ServerName;Initial Catalog=$MonitorDBName;Integrated Security=True"
    
    Test-AcctDBConnection -DBConnection $csSite
    Test-AdminDBConnection -DBConnection $csSite
    Test-AnalyticsDBConnection -DBConnection $csSite   # for 7.6 and newer
    Test-AppLibDBConnection -DBConnection $csSite      # for 7.8 and newer
    Test-BrokerDBConnection -DBConnection $csSite
    Test-ConfigDBConnection -DBConnection $csSite
    Test-EnvTestDBConnection -DBConnection $csSite
    Test-HypDBConnection -DBConnection $csSite
    Test-LogDBConnection -DBConnection $csSite
    Test-LogDBConnection -DataStore Logging -DBConnection $csLogging
    Test-MonitorDBConnection -DBConnection $csSite
    Test-MonitorDBConnection -Datastore Monitor -DBConnection $csMonitoring
    Test-OrchDBConnection -DBConnection $csSite       # for 7.11 and newer
    Test-ProvDBConnection -DBConnection $csSite
    Test-SfDBConnection -DBConnection $csSite
    Test-TrustDBConnection -DBConnection $csSite      # for 7.11 and newer
    <!--NeedCopy-->
    
  2. シトリックス スタジオ を再起動します。

詳細情報

SQL Serverの高可用性ソリューションを使用する場合のデータベース接続文字列の更新