Windows Server フェールオーバー クラスターでの IIS World Wide Web 発行サービスの構成
この記事では、Windows Server フェールオーバー クラスター (WSFC) で Microsoft インターネット インフォメーション サービス (IIS) World Wide Web Publishing Service (W3SVC) を構成する方法について説明します。
元の製品バージョン: Windows Server 2008 以降のバージョン、インターネット インフォメーション サービス 8.0 以降のバージョン
元の KB 番号: 970759
はじめに
この記事の手順は、World Wide Web 発行サービスにのみ適用されます。 フェールオーバー クラスターで FTP 発行サービスを構成する方法については、「 Windows Server フェールオーバー クラスターで IIS の FTP を構成する方法を参照してください。
詳細
以前のバージョンのインターネット インフォメーション サービスでは、Microsoft クラスタリング インフラストラクチャを使用して高可用性 Web サーバー インスタンスをサポートするための汎用リソース モニター コンポーネントが提供されました。 ただし、このようなソリューションの可能性を完全に実現するには、カスタム コードが必要でした。 また、Microsoft が提供する汎用スクリプトは、顧客のニーズを満たしませんでした。 Windows Server フェールオーバー クラスタリングを使用するクラスター環境で IIS 7.0 以降のバージョンを構成するには、カスタム (スクリプト) コードを使用してこのような高可用性シナリオを有効にする必要があります。 この操作を行うと、ユーザーは要件を満たすようにセットアップをカスタマイズできます。 Web アプリケーションの高可用性統合を完全に制御できます。 さらに、IIS 7.0 で導入された管理と監視用のスクリプト インターフェイスは、以前に提供されたスクリプトよりも豊富な環境を提供します。
Note
IIS 7.0 のインストール ファイルには、IIS クラスター管理タスクに IIS 6.0 で使用される Clusweb.vbs および Clusftp.vbs スクリプト ファイルが含まれています。 IIS 7.0 以降のバージョンでは、これらのスクリプトを使用しないでください。
管理者は、フェールオーバー クラスタリングを使用するのではなく、IIS 7.0 以降のバージョンを実行する複数のサーバーを使用する Web アプリケーションのスケーラビリティと可用性を向上させる主な方法として、ネットワーク負荷分散 (NLB) の使用を慎重に評価することをお勧めします。 NLB の利点の 1 つは、すべてのサーバーが受信ハイパーテキスト転送プロトコル (HTTP) 要求の同時処理に積極的に参加できることです。 もう 1 つの利点は、NLB IIS 環境では、Web アプリケーションの高可用性を提供しながら、ローリング更新とロールバックをサポートする方がはるかに簡単になることです。 NLB 環境での IIS 7.0 以降のバージョンの使用の詳細については、次の記事を参照してください。
IIS サービスをクラスタリングすることによって IIS をクラスタリングすることは、Web アプリケーションの高可用性ソリューションを常に保証するとは限らないことを考慮することが重要です。 IIS サービス (具体的には WWW サービス) が稼働している場合、特定のアプリケーション プールのホスティング プロセスが終了したか、アプリケーションが内部サーバーの HTTP エラーをスローしている可能性があります。 Web アプリケーションをクラスタリングし、カスタム スクリプトを使用して正常性を監視することは、フェールオーバー クラスタリングを使用して高可用性 IIS クラスターを実現するための適切で推奨される方法です。 アプリケーション プールの状態を監視して、起動されているかどうかを判断するサンプル スクリプトを次に示します。
フェールオーバー クラスタリングを使用して IIS 7.0 以降のバージョンの Web サーバーの高可用性を構成するには、次の手順に従います。 手順 3 ~ 7 について、以下で詳しく説明します。 この記事の後半のサンプル スクリプトは、IIS 7.0 以降のバージョンの例として使用できます。
- すべてのクラスター ノードに Web サーバーの役割をインストールします。 詳細については、 IIS 7 デプロイ ガイドを参照してください。
- すべてのクラスター ノードにフェールオーバー クラスタリング機能をインストールし、クラスターを作成します。 詳細については、「 Failover Cluster Deployment Guideを参照してください。
- IIS 共有構成に使用するファイル共有を設定します。
- すべてのクラスター ノードで IIS 共有構成を構成します。
- すべてのクラスター ノードで共有構成用に IIS オフライン ファイルを構成します。
- Web サイト (関連付けられているアプリケーション プールを含む) を構成し、そのコンテンツの場所を 1 つのクラスター ノードに指定します。
- フェールオーバー クラスタリングで汎用スクリプトを作成して、Web サイトの高可用性を構成します。
IIS 共有構成に使用するファイル共有を設定する
- IIS 共有構成に使用される共有にアクセスするユーザーを作成します。
- ファイル共有を作成します。 この共有は、すべてのクラスター ノード上の IIS 間で共有される IIS 共有構成を格納するために使用されます。 複数のオプションがあります。
- フェールオーバー クラスターに含まれていないスタンドアロン サーバーで、ファイル共有を作成します。
- 別の Windows Server フェールオーバー クラスターで、高可用性ファイル共有を作成します。 詳細については、「 Failover クラスターのステップ バイ ステップ ガイド: 2 ノード ファイル サーバー フェールオーバー クラスターの構成を参照してください。
- 高可用性 Web サイトをホストするのと同じフェールオーバー クラスターで、高可用性ファイル共有を作成します。 詳細については、「 Failover クラスターのステップ バイ ステップ ガイド: 2 ノード ファイル サーバー フェールオーバー クラスターの構成を参照してください。
- 手順 2 で作成した共有に対するアクセス許可を設定します。 手順 1 で作成したユーザーに、ファイル共有と NTFS アクセス許可に対するフル コントロールのアクセス許可を付与します。
- すべてのクラスター ノードがファイル共有を参照できることを確認します。 ファイル共有へのパスは
\\<fileserver>\<share>
。
すべてのクラスター ノードで IIS 共有構成を構成する
Note
Application Host Helper Service
の権限がないため、Windows 2008 Server の IIS 共有構成に問題があります。 共有構成を機能させるには、Windows 2008 Server で IIS 共有構成を設定するときに、次の手順に従う必要があります。
管理コマンド プロンプトを開きます。
次のコマンドを実行します。
net stop apphostsvc
次のコマンドを実行します。
sc privs apphostsvc SeChangeNotifyPrivilege/SeTcbPrivilege/SeImpersonatePrivilege
次のコマンドを実行します。
net start apphostsvc
クラスター内の各 Windows 2008 サーバーでこれらの手順を完了したら、このセクションの説明に従って IIS 共有構成の設定を続行します。
クラスター ノードの 1 つで、共有構成をファイル共有にエクスポートします。
- Administrative Tools に移動し、インターネット インフォメーション サービス (IIS) マネージャーを選択します。
- 左側のウィンドウで、 サーバー名 ノードを選択します。
- [共有構成] アイコンをダブルクリックします。
- Shared Configuration ページで、Actions ペイン (右側のウィンドウ) で Export Configuration を選択して、ローカル コンピューターから別の場所に構成ファイルをエクスポートします。
- [Export 構成] ダイアログ ボックスで、[Physical パス ボックスにファイル共有 (
\\<fileserver>\<share>
) のパスを入力します。 - [ 接続を選択し、共有構成が格納されている共有にアクセスできるユーザー アカウントのユーザー名とパスワードを入力し、 OKを選択します。 このアカウントが、共有へのアクセスに使用されます。 ドメイン管理者ではない制限付き Active Directory アカウントを使用する必要があります。
- [ Export 構成 ] ダイアログ ボックスで、暗号化キーの保護に使用するパスワードを入力し、[ OK を選択します。
- [ 共有構成 ] ページで、[ 共有構成を有効にする ] チェック ボックスをオンにします。
- 前に入力した物理パス、ユーザー アカウント、およびパスワードを入力し、Actions ペインで Apply を選択します。
- [ 暗号化キーのパスワード ダイアログ ボックスで、前に設定した暗号化キーのパスワードを入力し、 OKを選択します。
- [ 共有構成 ] ダイアログ ボックスで、[ OKを選択します。
- [OK] を選択します。
他の各クラスター ノードで、ファイル共有にエクスポートした共有構成を使用します。
- Administrative Tools に移動し、インターネット インフォメーション サービス (IIS) マネージャーを選択します。
- サーバー名ノードを選択します。
- [共有構成] アイコンをダブルクリックします。
- [ 共有構成 ] ページで、[ 共有構成を有効にする ] チェック ボックスをオンにします。
- ファイル共有 (
\\<fileserver>\<share>
)、ユーザー アカウント、および前に入力したパスワードの物理パスを入力し、Actions ペインで Apply を選択します。 - [ 暗号化キーのパスワード ダイアログ ボックスで、前に設定した暗号化キーのパスワードを入力し、 OKを選択します。
- [ 共有構成 ] ダイアログ ボックスで、[ OKを選択します。
- [OK] を選択します。
Note
IIS で共有構成を設定する方法の詳細については、「 共有構成を参照してください。
すべてのクラスター ノードで共有構成用に IIS オフライン ファイルを構成する
各クラスター ノードで、オフライン ファイルを有効にします。
デスクトップ エクスペリエンスをインストールする
- Administrative Tools に移動し、サーバー マネージャーを選択します。
- 左側のウィンドウで、 Features を選択します。
- 右側のウィンドウ [機能の追加 ] を選択します。
- Windows のバージョンに応じて、次のいずれかの操作を行います。
- Windows Server 2016 については、「 デスクトップ エクスペリエンスを備えた Server のインストール」を参照してください。
- Windows Server 2102 および 2012 R2 の場合は、機能の一覧の User インターフェイスとインフラストラクチャの下にある Desktop Experience を選択します。
- Windows Server 2008 および 2008 R2 の場合は、 Desktop Experience を選択します。
- Install を選択してデスクトップ エクスペリエンスをインストールします。
- コンピューターを再起動します。
次のいずれかの操作を行います。
- Windows Server 2012、2012 R2、2016 の場合は、コントロール パネルで Sync Center を選択し、オフライン ファイルの管理を選択します。
- Windows Server 2008 および 2008 R2 の場合は、コントロール パネルで Offline Files を選択します。
[オフライン ファイル 可能を選択します。 現時点では、コンピューターを再起動しないでください。
キャッシュが読み取り専用に設定されていることを確認します。 これを行うには、管理者特権のコマンド プロンプトで次のコマンドを実行します。
REG ADD "HKLM\System\CurrentControlSet\Services\CSC\Parameters" /v ReadOnlyCache /t REG_DWORD /d 1 /f
コンピューターを再起動します。
コンピューターからファイル サーバーを参照します。 IIS 共有構成を含む共有を右クリックし、 Always Available Offline を選択します。
Note
IIS ノードをホストするのと同じフェールオーバー クラスターでファイル共有を高可用性に設定した場合、 Always Available Offline オプションは、高可用性ファイル サーバーをホストしているクラスター ノードの場合、共有を右クリックしても表示されません。 使用可能な高いファイル サーバー アプリケーションを別のノードに移動する必要があります。
コントロール パネルで、Offline Files を開きます。 [同期センター 開くを選択し、 Schedule を選択します。
毎日、または要件に従って、オフライン ファイル同期をスケジュールします。 オフライン同期を数分ごとに実行するように構成することもできます。 スケジューラを設定していない場合でも、 Applicationhost.config ファイルで何かを変更すると、変更は Web サーバーに反映されます。
Note
IIS で共有構成用にオフライン ファイルを構成する方法の詳細については、「 共有構成のオフライン ファイルを参照してください。
Web サイトを構成し、そのコンテンツの場所を 1 つのクラスター ノードに指定する
Web サイトのコンテンツ ファイルが残るクラスター ディスク リソースを所有するクラスター ノードを見つけます。
- Administrative Tools に移動し、Failover クラスター マネージャーを選択します。
- クラスターに接続します。 いずれかのクラスター ノードを使用している場合は、クラスターが自動的に一覧に表示されます。
- Storageで、Web ページコンテンツが存在するディスク リソースを見つけます。 これを行うには、ディスク リソースのストレージ ツリーを展開します。 クラスター上の他の高可用性アプリケーションでストレージが使用されていないことを確認します。 ストレージは Available Storage にあります。
- このリソースがオンラインになっているクラスター ノード。 そのクラスター ノードで IIS を構成します。
- クラスター ディスク リソース名。
これはコンテンツ ファイルに使用します。 リソースがオンラインになっているクラスター ノードで、Web サイトのコンテンツに共有ディスクを使用するように Web サーバーを構成します。
- Administrative Tools に移動し、インターネット インフォメーション サービス (IIS) マネージャーを選択します。
- 左側のウィンドウで、サーバー名ノードを展開します。
- Sites を展開し、Sitesで、構成するサイトを選択します。
- 右側のウィンドウで、[管理 Web サイトの下にある [Advanced Settings を選択します。
- General設定でPhysical Pathプロパティを見つけ、Web サイトのコンテンツ ファイルがある場所を入力します。 これは、前の手順の手順 5 で書き込んだクラスター ディスク リソースの場所です。
- [OK] を選択します。
フェールオーバー クラスター マネージャーで汎用スクリプトを作成して、Web サイトの高可用性を構成する
IIS Web サーバーの高可用性を構成する最後の手順では、Web サイトと Web サイトのアプリケーション プールの監視に使用する汎用スクリプト リソースを設定します。
各クラスター ノードで、この記事の最後に記載されているスクリプトを
Windows\System32\inetsrv\Clusweb7.vbs
にコピーします。既定では、スクリプトは Default Web Site という名前の Web サイトと、 DefaultAppPool という名前のアプリケーション プールを監視します。 これらが正しい Web サイトとアプリケーション プールでない場合は、
SITE_NAME and APP_POOL_NAME
変数を変更します。 スクリプト内の同じ Web サイトとアプリケーション プールがすべてのクラスター ノードに存在することを確認します。Note
名前では大文字と小文字が区別されます。
Administrative Tools に移動し、Failover クラスター マネージャーを選択します。
クラスターに接続します。 いずれかのクラスター ノードを使用している場合は、クラスターが自動的に一覧に表示されます。
次のいずれかの操作を行います。
- Windows Server 2012、2012 R2、および 2016 の場合は、 Roles を右クリックし、 [ロールの構成] を選択して作成します。
- Windows Server 2008 および 2008 R2 の場合は、クラスターを右クリックし、 サービスまたはアプリケーションの構成を選択します。 ウィザードによって高可用性ワークロードが作成されます。
Generic スクリプトを選択します。
%systemroot%\System32\Inetsrv\clusweb7.vbs
からスクリプト ファイルを選択します。クライアント アクセス ポイント (CAP) 名を、クライアントが高可用性 Web サイトへの接続に使用する Web サイト名に設定します。 Web サイト CAP に使用する静的 IP を指定します。 動的ホスト構成プロトコル (DHCP) を使用している場合、このオプションは表示されません。
ストレージの選択手順で、Web サイト コンテンツ ファイルが存在するクラスター共有ディスクを選択します。 ストレージは、クラスター上の他の高可用性アプリケーションで使用されていない必要があります。
Note
IIS 共有構成に使用されるファイル共有が同じクラスターでホストされている場合は、ここで別のディスク リソースを使用する必要があります。
設定を確認すると、ウィザードによってクラスター グループ、クラスター リソース、およびリソース間の依存関係が作成され、リソースがオンラインになります。
Note
同じフェールオーバー クラスターで複数の高可用性 Web サイトをホストするには、上記と同じ手順に従います。 ただし、Web サイトごとに異なるスクリプト ファイルを使用し、異なるクラスター化された共有ストレージを使用します。 たとえば、
%systemroot%\System32\Inetsrv
では、最初の Web サイトには clusweb7.vbs 、2 番目の Web サイトには clweb7-2.vbs 、3 番目の Web サイトには clweb7-3.vbs などを使用します。 各スクリプト ファイルは、異なる Web サイトとアプリケーション プールを監視します。
次のスクリプトはサンプルのみを目的としており、Microsoft では明示的にサポートされていません。 IIS 7.0 以降のバージョンのクラスター化された環境でこのスクリプトを使用する場合は、ご自身の責任で行ってください。
'<begin script sample>
'This script provides high availability for IIS websites
'By default, it monitors the "Default Web Site" and "DefaultAppPool"
'To monitor another website, change the SITE_NAME below
'To monitor another application pool, change the APP_POOL_NAME below
'More thorough and application-specific health monitoring logic can be added to the script if needed
Option Explicit
DIM SITE_NAME
DIM APP_POOL_NAME
Dim START_WEB_SITE
Dim START_APP_POOL
Dim SITES_SECTION_NAME
Dim APPLICATION_POOLS_SECTION_NAME
Dim CONFIG_APPHOST_ROOT
Dim STOP_WEB_SITE
'Note:
'Replace this with the site and application pool you want to configure high availability for
'Make sure that the same website and application pool in the script exist on all cluster nodes. Note that the names are case-sensitive.
SITE_NAME = "Default Web Site"
APP_POOL_NAME = "DefaultAppPool"
START_WEB_SITE = 0
START_APP_POOL = 0
STOP_WEB_SITE = 1
SITES_SECTION_NAME = "system.applicationHost/sites"
APPLICATION_POOLS_SECTION_NAME = "system.applicationHost/applicationPools"
CONFIG_APPHOST_ROOT = "MACHINE/WEBROOT/APPHOST"
'Helper script functions
'Find the index of the website on this node
Function FindSiteIndex(collection, siteName)
Dim i
FindSiteIndex = -1
For i = 0 To (CInt(collection.Count) - 1)
If collection.Item(i).GetPropertyByName("name").Value = siteName Then
FindSiteIndex = i
Exit For
End If
Next
End Function
'Find the index of the application pool on this node
Function FindAppPoolIndex(collection, appPoolName)
Dim i
FindAppPoolIndex = -1
For i = 0 To (CInt(collection.Count) - 1)
If collection.Item(i).GetPropertyByName("name").Value = appPoolName Then
FindAppPoolIndex = i
Exit For
End If
Next
End Function
'Get the state of the website
Function GetWebSiteState(adminManager, siteName)
Dim sitesSection, sitesSectionCollection, siteSection, index, siteMethods, startMethod, executeMethod
Set sitesSection = adminManager.GetAdminSection(SITES_SECTION_NAME, CONFIG_APPHOST_ROOT)
Set sitesSectionCollection = sitesSection.Collection
index = FindSiteIndex(sitesSectionCollection, siteName)
If index = -1 Then
GetWebSiteState = -1
End If
Set siteSection = sitesSectionCollection(index)
GetWebSiteState = siteSection.GetPropertyByName("state").Value
End Function
'Get the state of the ApplicationPool
Function GetAppPoolState(adminManager, appPool)
Dim configSection, index, appPoolState
set configSection = adminManager.GetAdminSection(APPLICATION_POOLS_SECTION_NAME, CONFIG_APPHOST_ROOT)
index = FindAppPoolIndex(configSection.Collection, appPool)
If index = -1 Then
GetAppPoolState = -1
End If
GetAppPoolState = configSection.Collection.Item(index).GetPropertyByName("state").Value
End Function
'Start the w3svc service on this node
Function StartW3SVC()
Dim objWmiProvider
Dim objService
Dim strServiceState
Dim response
'Check to see if the service is running
set objWmiProvider = GetObject("winmgmts:/root/cimv2")
set objService = objWmiProvider.get("win32_service='w3svc'")
strServiceState = objService.state
If ucase(strServiceState) = "RUNNING" Then
StartW3SVC = True
Else
'If the service is not running, try to start it
response = objService.StartService()
'response = 0 or 10 indicates that the request to start was accepted
If ( response <> 0 ) and ( response <> 10 ) Then
StartW3SVC = False
Else
StartW3SVC = True
End If
End If
End Function
'Start the application pool for the website
Function StartAppPool()
Dim ahwriter, appPoolsSection, appPoolsCollection, index, appPool, appPoolMethods, startMethod, callStartMethod
Set ahwriter = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
Set appPoolsSection = ahwriter.GetAdminSection(APPLICATION_POOLS_SECTION_NAME, CONFIG_APPHOST_ROOT)
Set appPoolsCollection = appPoolsSection.Collection
index = FindAppPoolIndex(appPoolsCollection, APP_POOL_NAME)
Set appPool = appPoolsCollection.Item(index)
'See if it is already started
If appPool.GetPropertyByName("state").Value = 1 Then
StartAppPool = True
Exit Function
End If
'Try To start the application pool
Set appPoolMethods = appPool.Methods
Set startMethod = appPoolMethods.Item(START_APP_POOL)
Set callStartMethod = startMethod.CreateInstance()
callStartMethod.Execute()
'If started return true, otherwise return false
If appPool.GetPropertyByName("state").Value = 1 Then
StartAppPool = True
Else
StartAppPool = False
End If
End Function
'Start the website
Function StartWebSite()
Dim ahwriter, sitesSection, sitesSectionCollection, siteSection, index, siteMethods, startMethod, executeMethod
Set ahwriter = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
Set sitesSection = ahwriter.GetAdminSection(SITES_SECTION_NAME, CONFIG_APPHOST_ROOT)
Set sitesSectionCollection = sitesSection.Collection
index = FindSiteIndex(sitesSectionCollection, SITE_NAME)
Set siteSection = sitesSectionCollection(index)
if siteSection.GetPropertyByName("state").Value = 1 Then
'Site is already started
StartWebSite = True
Exit Function
End If
'Try to start site
Set siteMethods = siteSection.Methods
Set startMethod = siteMethods.Item(START_WEB_SITE)
Set executeMethod = startMethod.CreateInstance()
executeMethod.Execute()
'Check to see if the site started, if not return false
If siteSection.GetPropertyByName("state").Value = 1 Then
StartWebSite = True
Else
StartWebSite = False
End If
End Function
'Stop the website
Function StopWebSite()
Dim ahwriter, sitesSection, sitesSectionCollection, siteSection, index, siteMethods, startMethod, executeMethod, autoStartProperty
Set ahwriter = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
Set sitesSection = ahwriter.GetAdminSection(SITES_SECTION_NAME, CONFIG_APPHOST_ROOT)
Set sitesSectionCollection = sitesSection.Collection
index = FindSiteIndex(sitesSectionCollection, SITE_NAME)
Set siteSection = sitesSectionCollection(index)
'Stop the site
Set siteMethods = siteSection.Methods
Set startMethod = siteMethods.Item(STOP_WEB_SITE)
Set executeMethod = startMethod.CreateInstance()
executeMethod.Execute()
End Function
'Cluster resource entry points. More details here:
'http://msdn.microsoft.com/en-us/library/aa372846(VS.85).aspx
'Cluster resource Online entry point
'Make sure the website and the application pool are started
Function Online( )
Dim bOnline
'Make sure w3svc is started
bOnline = StartW3SVC()
If bOnline <> True Then
Resource.LogInformation "The resource failed to come online because w3svc could not be started."
Online = False
Exit Function
End If
'Make sure the application pool is started
bOnline = StartAppPool()
If bOnline <> True Then
Resource.LogInformation "The resource failed to come online because the application pool could not be started."
Online = False
Exit Function
End If
'Make sure the website is started
bOnline = StartWebSite()
If bOnline <> True Then
Resource.LogInformation "The resource failed to come online because the web site could not be started."
Online = False
Exit Function
End If
Online = true
End Function
'Cluster resource offline entry point
'Stop the website
Function Offline( )
StopWebSite()
Offline = true
End Function
'Cluster resource LooksAlive entry point
'Check for the health of the website and the application pool
Function LooksAlive( )
Dim adminManager, appPoolState, configSection, i, appPoolName, appPool, index
i = 0
Set adminManager = CreateObject("Microsoft.ApplicationHost.AdminManager")
appPoolState = -1
'Get the state of the website
if GetWebSiteState(adminManager, SITE_NAME) <> 1 Then
Resource.LogInformation "The resource failed because the " & SITE_NAME & " web site is not started."
LooksAlive = false
Exit Function
End If
'Get the state of the Application Pool
if GetAppPoolState(adminManager, APP_POOL_NAME) <> 1 Then
Resource.LogInformation "The resource failed because Application Pool " & APP_POOL_NAME & " is not started."
LooksAlive = false
Exit Function
End if
'Web site and Application Pool state are valid return true
LooksAlive = true
End Function
'Cluster resource IsAlive entry point
'Do the same health checks as LooksAlive
'If a more thorough than what we do in LooksAlive is required, this should be performed here
Function IsAlive()
IsAlive = LooksAlive
End Function
'Cluster resource Open entry point
Function Open()
Open = true
End Function
'Cluster resource Close entry point
Function Close()
Close = true
End Function
'Cluster resource Terminate entry point
Function Terminate()
Terminate = true
End Function
'<end script sample>