GlassFishのロードバランサプラグインで Apache と動作確認 Part2 (GlassFish 設定編)

2009年12月25日 at 5:52 午前 2件のコメント

GlassFishのロードバランサプラグインで Apache と連携 Part1 (Apache 設定編)
に引き続きGlassFish の設定と動作確認をしてみます。

GlassFish の設定と動作確認

実際に GlassFish 上でクラスタ構成を設定し、動作を確認してみましょう。

ドメインの起動

Part 1 で作成したドメインを起動してください。

dashost > asadmin start-domain clusterDomain
ドメイン clusterDomain を起動しています。お待ちください。
デフォルトのログの場所は /export/home/appserv/domains/clusterDomain/logs/server.log です。
出力を /export/home/appserv/domains/clusterDomain/logs/server.log にリダイレクトしています
ドメイン clusterDomain が起動しました。
ドメイン [clusterDomain] はその設定で [Sun GlassFish Enterprise Server v2.1.1 ((v2.1 Patch06)(9.1_02 Patch12)) (build b31g-fcs)] を実行しています。ログは [/export/home/appserv/domains] にあります。
管理コンソールは [http://localhost:5048] で使用できます。
“asadmin” コマンドにも同じポート [5048] を使用します。
ユーザーの Web アプリケーションは次の URL で使用できます:
[http://localhost:5080 https://localhost:5081 ]。
次の web-contexts を使用できます:
[/web1 /__wstx-services ]。
標準の JMX クライアント (JConsole など) はドメイン管理のために JMXServiceURL:
[service:jmx:rmi:///jndi/rmi://dashost:5086/jmxrmi] に接続できます。
ドメインは少なくとも次のポートで接続を待機しています:
[5080 5081 5048 5037 5038 5039 5086 ]。
ドメインはアプリケーションサーバークラスタおよびその他のスタンドアロンインスタンスをサポートします。


ノードエージェントの作成

次に、ドメインに所属するノードエージェントを2つ作成してください。
それぞれのノードエージェントが稼働するマシン上でコマンドを実行してください。
nodeagent1 の作成と起動

nodeagent1 > asadmin create-node-agent nodeagent1
コマンド create-node-agent は正常に実行されました。
nodeagent1 > asadmin start-node-agent nodeagent1
出力を /export/home/appserv/nodeagents/nodeagent1/agent/logs/server.log にリダイレクトしています
アプリケーション出力を /export/home/appserv/nodeagents/nodeagent1/agent/logs/server.log にリダイレクトします
コマンド start-node-agent は正常に実行されました。


nodeagent2 の作成と起動

nodeagent2 > asadmin create-node-agent nodeagent2
コマンド create-node-agent は正常に実行されました。
nodeagent2 > asadmin start-node-agent nodeagent2
出力を /export/home/appserv/nodeagents/nodeagent2/agent/logs/server.log にリダイレクトしています
アプリケーション出力を /export/home/appserv/nodeagents/nodeagent2/agent/logs/server.log にリダイレクトします
コマンド start-node-agent は正常に実行されました。


クラスタとインスタンスの作成

ドメイン管理サーバでクラスタを1つ作成してください。
クラスタ作成後、各ノードエージェント上にそれぞれ1つずつ
クラスタに所属するインスタンスを作成してください。

dashost > asadmin create-cluster cluster1
コマンド create-cluster は正常に実行されました。
dashost > asadmin create-instance –nodeagent nodeagent1 –cluster cluster1 instance1
コマンド create-instance は正常に実行されました。
dashost > asadmin create-instance –nodeagent nodeagent2 –cluster cluster1 instance2
コマンド create-instance は正常に実行されました


クラスタの起動

作成したクラスタを起動してみましょう。

dashost > asadmin start-cluster cluster1
クラスタ化されたインスタンス instance1 の起動に成功しました。
クラスタ化されたインスタンス instance2 の起動に成功しました。
コマンド start-cluster は正常に実行されました。


サンプルアプリケーションのデプロイ

次に、作成したクラスタに対してサンプルのアプリケーションをデプロイします。

dashost > asadmin deploy –target cluster1 –availabilityenabled=true
/sun/glassfish-v2.1.1/samples/quickstart/clusterjsp/clusterjsp.ear

コマンド deploy は正常に実行されました。


ロードバランサプラグインの設定と設定ファイルのエクスポート

続いて、ロードバランサの設定を作成しデプロイしたアプリケーションに対して
負荷分散を行う設定をします。

dashost > asadmin create-http-lb-config –target cluster1 lb-config
コマンド create-http-lb-config は正常に実行されました。
dashost > asadmin enable-http-lb-server cluster1
コマンド enable-http-lb-server は正常に実行されました。
dashost > asadmin enable-http-lb-application –name clusterjsp cluster1
コマンド enable-http-lb-application は正常に実行されました。
dashost > asadmin create-http-health-checker –interval 10 –config lb-config cluster1
コマンド create-http-health-checker は正常に実行されました。
dashost > asadmin export-http-lb-config –config lb-config /tmp/loadbalancer.xml
生成されたファイルの場所: /tmp/loadbalancer.xml
コマンド export-http-lb-config は正常に実行されました。


ここで,出力されたloadbalancer.xmlファイルを Apache 上にコピーする事で
負荷分散機能を利用することができるようになります。
しかし、手動でファイルをコピーする方法は古い方法ですので、
手動でファイルをコピーするのではなく、下記の方法を利用してください。

apache > cp /tmp/loadbalancer.xml /usr/local/apache2.2.14/conf/loadbalancer.xml


autoapplyenabled機能の有効化

下記コマンドを実行すると Web Server にログインして loadbalancer.xml を
直接編集したり、手動でコピーしなくても、asadmin コマンドから直接
設定変更内容を更新する事ができるようになります.

dashost > asadmin create-http-lb –target cluster1 –autoapplyenabled=true –devicehost apache.japan.sun.com –deviceport 443 lb-config
コマンド create-http-lb は正常に実行されました。
dashost > asadmin apply-http-lb-changes lb-config
コマンド apply-http-lb-changes は正常に実行されました。
dashost >


apply-http-lb-changes を実行すると、直ちに loadbalancer.xml が
更新されるようになります。
Apache 上で更新された loadbalancer.xml は下記の通りです。

apache > cat /usr/local/apache2.2.14/conf/loadbalancer.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE loadbalancer PUBLIC “-//Sun Microsystems Inc.//DTD Sun Java System Application Server 9.1//EN” “sun-loadbalancer_1_2.dtd”>
<loadbalancer>
<cluster name=”cluster1″ policy=”round-robin”>
<instance disable-timeout-in-minutes=”30″ enabled=”true” listeners=”http://nodeagent1.japan.sun.com:38080 https://nodeagent1.japan.sun.com:38181&#8243; name=”instance1″ weight=”100″/>
<instance disable-timeout-in-minutes=”30″ enabled=”true” listeners=”http://nodeagent2.japan.sun.com:38080 https://nodeagent2.japan.sun.com:38181&#8243; name=”instance2″ weight=”100″/>
<web-module context-root=”/clusterjsp” disable-timeout-in-minutes=”30″ enabled=”true”/>
<health-checker interval-in-seconds=”30″ timeout-in-seconds=”10″ url=”/”/>
</cluster>
<property name=”response-timeout-in-seconds” value=”60″/>
<property name=”reload-poll-interval-in-seconds” value=”60″/>
<property name=”https-routing” value=”false”/>
<property name=”require-monitor-data” value=”false”/>
<property name=”active-healthcheck-enabled” value=”false”/>
<property name=”number-healthcheck-retries” value=”3″/>
<property name=”rewrite-location” value=”true”/>
<property name=”rewrite-cookies” value=”false”/>
</loadbalancer>
<!–
This file was generated on: [Fri Dec 25 18:00:39 JST 2009].
Debugging Tips:
By default, instances and web-modules are not enabled.
Please enable them manually if you have not done that using asadmin.
–>
apache >


動作確認1: 高可用性のテスト

ブラウザから Apache の稼働するマシンへアクセスしてください。

ブラウザで Apache が稼働するマシンへ接続

http://apache.japan.sun.com/clusterjsp/

Served From Server instance: instance1


表示された画面から”Served From Server instance“のエントリを
確認してください。この例ではinstance1でアプリケーションが
稼働していることが分かります。

続いて、
Enter session attribute data:
にセッション情報を追加してください。

セッション情報を追加した後、稼働中のサーバインスタンス(instance1)
を停止します。

dashost > asadmin stop-instance instance1
コマンド stop-instance は正常に実行されました.


ブラウザをリロードするか,[Reload Page]ボタンを押してください。
“Served From Server instance:”のエントリが instance1からinstance2に
変更されているかと思います。また同時にセッション情報も引き継がれていること
が確認できるかと思います。
ここまでくれば、高可用性テストは完了です。

動作確認2:ドメイン管理サーバから Apache の負荷分散設定を変更するテスト

ここでは、asadmin コマンドだけを使って Apache が稼働するシステムに
ログインすることなく、負荷分散設定を変更するテストを行います。
まず、ドメイン管理サーバから instance2 に対するリクエストを送信しないように
設定します。

dashost > asadmin set “cluster1.server-ref.instance2.lb-enabled=false”
cluster1.server-ref.instance2.lb-enabled = false
dashost > asadmin apply-http-lb-changes lb-config
コマンド apply-http-lb-changes は正常に実行されました。


コマンドを実行すると、loadbalancer.xml の instance2 に該当する
設定箇所が変更されます。 (enabled が false)

apache > cat loadbalancer.xml|grep nodeagent2
<instance disable-timeout-in-minutes=”30″ enabled=”false”
listeners=”http://nodeagent2.japan.sun.com:38080
https://nodeagent2.japan.sun.com:38181&#8243; name=”instance2″ weight=”100″/>


instance2 に対する負荷分散を再会させたい場合,下記を実行してください。

dashost > asadmin set “cluster1.server-ref.instance2.lb-enabled=true”
cluster1.server-ref.instance2.lb-enabled = true
dashost > asadmin apply-http-lb-changes lb-config
コマンド apply-http-lb-changes は正常に実行されました。


再度、Apache の loadbalancer.xml を確認してみます。
instance2 に該当する設定箇所の enabled が true に変更されている事を確認できます。

apache > cat loadbalancer.xml | grep nodeagent2
<instance disable-timeout-in-minutes=”30″ enabled=”true”
listeners=”http://nodeagent2.japan.sun.com:38080
https://nodeagent2.japan.sun.com:38181&#8243; name=”instance2″ weight=”100″/>


動作確認3:新規インスタンス追加時の負荷分散振り先の追加テスト

最後に、インスタンスを追加してクラスタ構成を変更し負荷分散の対象を増やすテストを行います。
まず、クラスタに対して新規インスタンスを追加して起動してください。
起動したのち、apply-http-lb.-changes を実行してください。
コマンドを実行すると、負荷分散の振り先が追加されます。

dashost > asadmin create-instance –nodeagent nodeagent1 –cluster cluster1 instance3
HTTP_LISTENER_PORT の代わりに 38,081 を使用します。
HTTP_SSL_LISTENER_PORT の代わりに 38,182 を使用します。
IIOP_SSL_LISTENER_PORT の代わりに 33,821 を使用します。
JMS_PROVIDER_PORT の代わりに 37,677 を使用します。
IIOP_LISTENER_PORT の代わりに 33,701 を使用します。
JMX_SYSTEM_CONNECTOR_PORT の代わりに 38,687 を使用します。
IIOP_SSL_MUTUALAUTH_PORT の代わりに 33,921 を使用します。
コマンド create-instance は正常に実行されました。
dashost > asadmin create-instance –nodeagent nodeagent2 –cluster cluster1 instance4
HTTP_LISTENER_PORT の代わりに 38,081 を使用します。
HTTP_SSL_LISTENER_PORT の代わりに 38,182 を使用します。
IIOP_SSL_LISTENER_PORT の代わりに 33,821 を使用します。
JMS_PROVIDER_PORT の代わりに 37,677 を使用します。
IIOP_LISTENER_PORT の代わりに 33,701 を使用します。
JMX_SYSTEM_CONNECTOR_PORT の代わりに 38,687 を使用します。
IIOP_SSL_MUTUALAUTH_PORT の代わりに 33,921 を使用します。
コマンド create-instance は正常に実行されました。
dashost > asadmin start-instance instance3
コマンド start-instance は正常に実行されました。
dashost > asadmin start-instance instance4
コマンド start-instance は正常に実行されました。
dashost > asadmin apply-http-lb-changes lb-config
コマンド apply-http-lb-changes は正常に実行されました。


コマンドを実行後、loadbalancer.xml を確認してみましょう。
追加したインスタンスに対する振り先設定が追加されています。

apache > cat loadbalancer.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE loadbalancer PUBLIC “-//Sun Microsystems Inc.//DTD Sun Java System Application Server 9.1//EN” “sun-loadbalancer_1_2.dtd”>
<loadbalancer>
<cluster name=”cluster1″ policy=”round-robin”>
<instance disable-timeout-in-minutes=”30″ enabled=”true” listeners=”http://nodeagent1.japan.sun.com:38080 https://nodeagent1.japan.sun.com:38181&#8243; name=”instance1″ weight=”100″/>
<instance disable-timeout-in-minutes=”30″ enabled=”true” listeners=”http://nodeagent2.japan.sun.com:38080 https://nodeagent2.japan.sun.com:38181&#8243; name=”instance2″ weight=”100″/>
<instance disable-timeout-in-minutes=”30″ enabled=”true” listeners=”http://nodeagent1.japan.sun.com:38081 https://nodeagent1.japan.sun.com:38182&#8243; name=”instance3″ weight=”100″/>
<instance disable-timeout-in-minutes=”30″ enabled=”true” listeners=”http://nodeagent2.japan.sun.com:38081 https://nodeagent2.japan.sun.com:38182&#8243; name=”instance4″ weight=”100″/>
<web-module context-root=”/clusterjsp” disable-timeout-in-minutes=”30″ enabled=”true”/>
<health-checker interval-in-seconds=”30″ timeout-in-seconds=”10″ url=”/”/>
</cluster>
<property name=”response-timeout-in-seconds” value=”60″/>
<property name=”reload-poll-interval-in-seconds” value=”60″/>
<property name=”https-routing” value=”false”/>
<property name=”require-monitor-data” value=”false”/>
<property name=”active-healthcheck-enabled” value=”false”/>
<property name=”number-healthcheck-retries” value=”3″/>
<property name=”rewrite-location” value=”true”/>
<property name=”rewrite-cookies” value=”false”/>
</loadbalancer>
<!–
This file was generated on: [Fri Dec 25 18:22:35 JST 2009].
Debugging Tips:
By default, instances and web-modules are not enabled. Please enable them manually if you have not done that using asadmin.
–>
apache >

※ 新しく追加したインスタンスの設定が enabled=”false”になっている場合、
別途、下記コマンドを実行し有効にしてください。

dashost > asadmin set “cluster1.server-ref.instance3.lb-enabled=true”
dashost > asadmin set “cluster1.server-ref.instance4.lb-enabled=true”
dashost > asadmin apply-http-lb-changes lb-config
コマンド apply-http-lb-changes は正常に実行されました。


このように、ロードバランサプラグインを利用し、自動適用の設定を行うと、
アプリケーションサーバ側のクラスタ内の変更に対して、前段の Web サーバ側に
一切ログインせずに、振り先を自由に変更できるため、導入時には若干面倒ですが、運用時はとても楽になります。

また、お気づきの事と思いますが1度設定を行うと、Apache のサーバにログインする必要がないばかりか、負荷分散設定を変更した際に、Apache の再起動なども必要としていないことがわかるかと思います。
これは、loadbalancer.xml の更新をチェックする内部プログラムが別途稼働しており、更新があった場合に、動的に設定を有効にする仕組みが導入されているためです。これで、Web サーバ側の管理が随分楽になるのではないかと思います。
ぜひ、上記を参考にお試しください。

最後に、今回は GlassFish のロードバランサプラグインを Apache にインストールしていますが、Sun Java System Web Server でも autoapply の機能は使うことができますのでご安心ください。

追記:
正直、ちょっと面倒という方は、Sun GlassFish Enterprise Server with HADB を使ってみるのもいいかもしれません、with HADB 版ではインストーラからロードバランサプラグインのインストールもかんたんにできるようになっていますので、試す価値はあるかもしれません。
with HADB 版を利用しない場合は、上記の方法をご利用ください。

広告

Entry filed under: Application Server/GlassFish. Tags: , .

GlassFishのロードバランサプラグインで Apache と連携 Part1(Apache 設定編) Java Champion による Java パフォーマンスチューニングのトレーニング開催予定

2件のコメント

  • 1. Masanobu Hatanaka  |  2010年1月27日 2:24 午前

    Sun Java System Web Serverで記事upしてほしかったす~

    • 2. Yoshio Terada  |  2010年2月3日 10:01 午後

      Sun Java System Web Server の記事は既に数多く
      書いていますよ。

      詳しくは、

      GlassFish 関連情報
      のインストール手順関連をご確認ください。


Java Champion & Evangelist

Translate

ご注意

このエントリは個人の見解であり、所属する会社の公式見解ではありません

カレンダー

2009年12月
 123456
78910111213
14151617181920
21222324252627
28293031  

カテゴリー

clustermap

ブログ統計情報

  • 1,267,390 hits

RSSフィード

アーカイブ


%d人のブロガーが「いいね」をつけました。