第3章 Apache と mod_jk を使用した負荷分散の設定

本章のタスクに従い、Apache と mod_jk コネクタを使用して正しく負荷分散を設定します。

タスク : mod_jk をロードするために Apache を設定する。

このタスクでは、mod_jk をロードするため Apache を設定します。

前提条件

  1. HTTPD_DIST/conf/httpd.conf を開いて、ファイルの最後に 1 行追加します。
    # Include mod_jk's specific configuration file  
    Include conf/mod-jk.conf
    
  2. HTTPD_DIST/conf/mod-jk.conf という新しいファイルを作成します。
  3. mod-jk.conf ファイルに次の設定を追加します。

    重要

    LoadModule ディレクティブはインストールしたネイティブバイナリに適用可能な mod_jk ライブラリディレクトリの場所を参照する必要があります。

    注記

    JkMount ディレクティブは Apache が mod_jk モジュールにどの URL を転送すべきか指定します。ディレクティブの設定に基づき、mod_jk は受信した URL を正しい Servlet コンテナに転送します。
    Apache が静的コンテンツ (または PHP コンテンツ) に直接対応し、Java アプリケーションにロードバランサを使用可能なようにするためには、推奨される設定は /application/*mod_jk ロードバランサに送られる URL パスですべての要求を指定します。
    ロードバランサとして mod_jk だけを使用している場合は、ディレクティブの /* を指定することですべての URL を mod_jk に転送します。
    # Load mod_jk module
    # Specify the filename of the mod_jk lib
    LoadModule jk_module modules/mod_jk.so
     
    # Where to find workers.properties
    JkWorkersFile conf/workers.properties
    
    # Where to put jk logs
    JkLogFile logs/mod_jk.log
     
    # Set the jk log level [debug/error/info]
    JkLogLevel info 
     
    # Select the log format
    JkLogStampFormat  "[%a %b %d %H:%M:%S %Y]"
     
    # JkOptions indicates to send SSK KEY SIZE
    JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
     
    # JkRequestLogFormat
    JkRequestLogFormat "%w %V %T"
                   
    # Mount your applications
    JkMount /application/* loadbalancer
     
    # Add shared memory.
    # This directive is present with 1.2.10 and
    # later versions of mod_jk, and is needed for
    # for load balancing to work properly
    JkShmFile logs/jk.shm 
                  
    # Add jkstatus for managing runtime data
    <Location /jkstatus/>
        JkMount status
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    </Location>
    
  4. オプション : JKMountFile ディレクティブ

    JkMount ディレクティブに加え、JkMountFile ディレクティブを使用して、マウントポイント設定ファイルを指定することもできます。その設定ファイルには複数の Tomcat 転送 URL マッピングが含まれています。
    1. HTTPD_DIST/conf に移動します。
    2. uriworkermap.properties という名前のファイルを作成します。
    3. 転送する URL と次の構文サンプルをガイドとして使用してワーカー名を指定します。
      サンプルブロックは mod_jk を設定し、/jmx-console/web-console への要求を Apache に転送します。
      必要な構文の形式は /url=worker_name です。
      # Simple worker configuration file
      
      # Mount the Servlet context to the ajp13 worker
      /jmx-console=loadbalancer
      /jmx-console/*=loadbalancer
      /web-console=loadbalancer
      /web-console/*=loadbalancer
      
    4. HTTPD_DIST/conf/mod-jk.conf では、次のディレクティブを追加します。
      # You can use external file for mount points.
      # It will be checked for updates each 60 seconds.
      # The format of the file is: /url=worker
      # /examples/*=loadbalancer
      JkMountFile conf/uriworkermap.properties

3.1. mod_jk のワーカーノードの設定

タスク : mod_jk ワーカーノードを設定する。

このタスクでは、2 つのサーブレットコンテナ間でスティッキーセッションをアクティブにした状態で、重み付きラウンドロビン設定の 2 つの mod_jk ワーカーノードの定義を設定します。

前提条件

  1. HTTPD_DIST/conf/ に移動します。
  2. workers.properties という名前のファイルを作成します。
  3. workers.properties に次の情報を追加します。
    # Define list of workers that will be used
    # for mapping requests
    worker.list=loadbalancer,status
    
    # Define Node1
    # modify the host as your host IP or DNS name.
    worker.node1.port=8009
    worker.node1.host=node1.mydomain.com
    worker.node1.type=ajp13
    worker.node1.ping_mode=A
    worker.node1.lbfactor=1 
    
    # Define Node2
    # modify the host as your host IP or DNS name.
    worker.node2.port=8009
    worker.node2.host=node2.mydomain.com
    worker.node2.type=ajp13
    worker.node2.ping_mode=A
    worker.node2.lbfactor=1
    
    # Load-balancing behavior
    worker.loadbalancer.type=lb
    worker.loadbalancer.balance_workers=node1,node2
    worker.loadbalancer.sticky_session=1
    
    # Status worker for managing load balancer
    worker.status.type=status