この章では、サーバー・テンプレートの概要と、WebLogic Server 12.1.3でのサーバー・テンプレートの作成、構成および使用方法について説明します。
この章には次の項が含まれます:
サーバー・テンプレートには、一連のサーバー・インスタンスに適用でき、テンプレート構成を継承する、共通のデフォルト以外の設定および属性が含まれています。サーバー・インスタンス定義のサーバー・テンプレートのオーバーライドによって、一意の属性を必要とするサーバー・インスタンスにサーバー固有の値を定義できます。実行時に、ドメインでは、サーバー・テンプレートで構成されている属性とサーバー固有のすべてのオーバーライドがマージされ、すべてのサーバー・インスタンスにすべての属性が定義されるようになります。
例5-1は、サーバー・テンプレートを使用するサンプルのconfig.xml
ファイルを示しています。この例では、共通の構成は<server-template>
要素で定義されています。個々のサーバー定義はサーバー固有の属性(name
、listen-port
)を設定し、追加の構成のベースとなるサーバー・テンプレート(my-cluster-server-template
)を指定します。
例5-1 サーバー・テンプレートを使用するサンプルconfig.xmlファイル
<server> <name>my-server-1</name> <listen-port>7010</listen-port> <server-template>my-cluster-server-template</server-template> </server> <server> <name>my-server-2</name> <listen-port>7020</listen-port> <server-template>my-cluster-server-template</server-template> </server> <server-template> <name>my-cluster-server-template</name> <accept-backlog>2000</accept-backlog> <cluster>my-cluster</cluster> <restart-max>10</restart-max> <reverse-dns-allowed>true</reverse-dns-allowed> <startup-timeout>600</startup-timeout> </server-template>
サーバー・テンプレートによって、集中化された場所でのサーバー・インスタンスのグループの構成を簡単に管理できます。サーバー・テンプレートに共通の構成属性を定義し、他のサーバー・インスタンスにテンプレートを適用できます。それぞれを手動で構成する必要はありません。サーバー固有の属性を定義する必要がある場合、個別のサーバー・レベルでサーバー・テンプレートを簡単にオーバーライドできます。
すべてのサーバー・インスタンスにわたる属性を更新する必要がある場合、サーバー・テンプレートでその値を変更するのみで、新しい値は、そのサーバー・テンプレートを使用するすべてのサーバー・インスタンスで有効になります。ドメイン内のすべてのサーバーを更新するためにWLSTスクリプトを記述する必要はありません。
サーバー・テンプレートは、パフォーマンスおよび起動時間の点でも役立ちます。各サーバー・インスタンス定義で同じ属性を設定するかわりに、サーバー・テンプレートで共通属性を一度定義すると、config.xml
ファイルのサイズを小さくできます。
サーバー・テンプレートは、動的クラスタの作成にも使用します。詳細は、『Oracle WebLogic Serverのクラスタの管理』の動的クラスタに関する項を参照してください。
サーバー・テンプレートは、WebLogic Scripting Tool (WLST)またはWebLogic Server管理コンソールを使用して作成します。例5-2でWLSTの使用方法を示します。WebLogic Server管理コンソールの使用方法の詳細は、Oracle WebLogic Server管理コンソール・オンライン・ヘルプのサーバー・テンプレートの作成に関する項を参照してください。サーバー・テンプレートを構成するには、『Oracle WebLogic Serverの理解』のシステム管理ツールおよびAPIの概要に関する項にリストされている管理ツールのいずれかを使用します。
必要に応じて、サーバー固有の属性を定義するか、個別のサーバー定義でサーバー・テンプレートの値を直接オーバーライドできます。たとえば、いくつかのサーバー固有の属性(Notes
、ConsensusProcessIdentifier
、InterfaceAddress
など)は、個別のサーバー・レベルで定義したほうが便利です。
サーバー・テンプレートには、プリミティブ・データ型、シングルトン要素、構成要素からなる配列など、様々な種類の属性が含まれています。サーバー・テンプレートの値をオーバーライドするには、個別のサーバー定義で属性を定義します。
WebLogic Serverは、次のオーバーライド階層に基づいて、どの属性値を使用するのかを決定します。
個別のサーバー構成とサーバー・テンプレートのいずれでも属性を定義しない場合は、デフォルトの値が使用されます。
サーバー・テンプレートで属性を定義する場合は、そのサーバー・テンプレートによってデフォルトの値がオーバーライドされます。サーバー・テンプレート値が使用されます。
個別のサーバー構成で属性を定義する場合は、そのサーバー構成によってサーバー・テンプレートの値およびデフォルトの値がオーバーライドされます。個別のサーバー構成の値が使用されます。
注意: 個別のサーバー構成で値をオーバーライドすると、この値が常にサーバー・テンプレートの値より優先されます。オーバーライドされた値を削除してサーバー・テンプレートの値を使用するには、unSet 属性コマンドを使用します。 |
実行時に、ドメインは、サーバー・テンプレートで定義されている属性と個別のサーバー定義をマージし、目的の構成を戻します。
サーバー・インスタンスはサーバー・テンプレートの属性をオーバーライドできますが、属性のタイプごとにオーバーライドが異なります。プリミティブ・データ型の場合、サーバー構成の値によってサーバー・テンプレートの値がオーバーライドされます。たとえば、サーバー・テンプレートがリスニング・ポートを7101
に定義しているが、サーバー構成で明示的なリスニング・ポート値を設定する場合、サーバー・インスタンスの値がサーバー・テンプレートのリスニング・ポート値をオーバーライドします。
サーバー・インスタンスは、子のシングルトン要素内に含まれている属性の値もオーバーライドします。たとえば、サーバー・テンプレートが共通ルート・ディレクトリ値を<server-start>
子要素で定義しているが、サーバー構成で<server-start>
要素に明示的なルート・ディレクトリ値を設定する場合、サーバー・インスタンスがサーバー・テンプレートのルート・ディレクトリ値をオーバーライドします。
子配列構成要素の場合、サーバー・インスタンスは、配列内の子要素内の個別の子要素や属性をオーバーライドすることはできません。サーバー構成は、構成要素の配列全体のみをオーバーライドできます。たとえば、サーバー・テンプレートでNetworkAccessPoint
要素の配列が定義されており、サーバー・インスタンス構成でNetworkAccessPoints
の配列が定義されている場合、サーバー・インスタンスNetworkAccessPoints
が、サーバー・テンプレートの値をオーバーライドします。
次の例は、サーバー・インスタンスのNetworkAccessPoints
を、WLSTを使用してオーバーライドする例を示しており、インライン・コメントを含んでいます。
# #A server template named Cluster Template defines a NetworkAccessPoint named
#AccessPoint-1. The server instance s1 references Cluster Template as its
#template. A ls() command on s1 shows the following: # wls:/mydomain/edit/Servers/s1/NetworkAccessPoints !> ls drw- AccessPoint-1 # #Server instance s1 then defines a NetworkAccessPoint at the server instance
#level. # wls:/mydomain/edit/Servers/s1 !> cmo.createNetworkAccessPoint("AccessPoint-2") # #This results in an override of the NetworkAccessPoints from the Cluster Template.
#AccessPoint-1 is no longer present in s1 and only AccessPoint-2 is defined in s1. # wls:/mydomain/edit/Servers/s1/NetworkAccessPoints !> ls drw- AccessPoint-2
サーバー・テンプレートは、共通属性を含んでおり、テンプレートから構成を継承する各サーバー・インスタンスに同じ値を提供します。場合によっては、属性に対して標準値を定義したいが、その値は各サーバー・インスタンスでわずかに異なるようにする必要が生じることがあります。各サーバー・インスタンスでサーバー固有の属性値を定義できますが、属性が1つのパターンに従っている場合はマクロを使用できる可能性があります。
サーバー・テンプレート内のどの文字列属性に対してもマクロを定義できます。マクロは大文字小文字を区別し、整数値または他の構成要素の参照には使用できません。サーバー・テンプレートで使用可能な有効なマクロは次のとおりです。
${id}
: 動的に作成されたサーバーのインスタンスID。このIDは1
から始まります。
${serverName}
: この要素が属するサーバー名。
${clusterName}
: この要素が属するクラスタ名。この要素がクラスタに属していない場合、空の文字列が代入されます。
${domainName}
: この要素が属するドメイン名。
${system-property-name}
: これが、前述の事前定義済マクロ名ではない場合、システム・プロパティとして評価され、その値が返されます。システム・プロパティが存在しない場合は、空の文字列が代入されます。
例5-2は、WLSTを使用して同じサーバー・テンプレートを使用する2つのサーバー・インスタンスを作成する例を示しています。この例には、インライン・コメントと次の作業の実行方法が示されています。
サーバー・テンプレートを作成して、my-cluster-server-template
という名前を付けます。
my-cluster-server-template
のすべての共通属性を設定します。
サーバー・インスタンスmy-server1
およびmy-server2
を作成し、各インスタンスにmy-cluster-server-template
を割り当てます。
サーバー固有の属性を設定します。
例5-2 WLSTによるサーバー・テンプレートの使用
# # This example demonstrates the WLST commands needed to create a server template # (my-cluster-server-template) and server instances (my-server-1, my-server-2) # that use the server template. The creation of the cluster (my-cluster) and # machines (PrimaryMachine, SecondaryMachine) are not included in this example; # they must be created before running this script. To keep this example # simple, error handling was omitted. # connect() edit() startEdit() # # Create the server template and set the common attributes that are used in all # servers. Attributes such as Accept Backlog, Auto Restart, etc. are the same # across all cluster members. # serverTemplate=cmo.createServerTemplate("my-cluster-server-template") serverTemplate.setAcceptBacklog(2000) serverTemplate.setAutoRestart(true) serverTemplate.setRestartMax(10) serverTemplate.setReverseDNSAllowed(true) serverTemplate.setStagingMode("external_stage") serverTemplate.setStartupTimeout(600) myCluster=cmo.lookupCluster("my-cluster") serverTemplate.setCluster(myCluster) # # Create the individual server instances, set the server specific attributes, and # set the template so the server uses the common attributes from the template. # Attributes such as cluster weight, listen port, and machine are server-specific # so they are not included in the server template. # server1=cmo.createServer("my-server-1") server1.setClusterWeight(70) server1.setListenPort(7010) primary=cmo.lookupMachine("PrimaryMachine") server1.setMachine(primary) server1.setServerTemplate(serverTemplate) # server2=cmo.createServer("my-server-2") server2.setClusterWeight(90) server2.setListenPort(7020) secondary=cmo.lookupMachine("SecondaryMachine") server2.setMachine(secondary) server2.setServerTemplate(serverTemplate) # # activate the changes # activate()
この結果得られるconfig.xml
ファイルは次のようになります。
<server> <name>my-server-1</name> <cluster-weight>70</cluster-weight> <listen-port>7010</listen-port> <machine>PrimaryMachine</machine> <server-template>my-cluster-server-template</server-template> </server> <server> <name>my-server-2</name> <cluster-weight>90</cluster-weight> <listen-port>7020</listen-port> <machine>SecondaryMachine</machine> <server-template>my-cluster-server-template</server-template> </server> <server-template> <name>my-cluster-server-template</name> <accept-backlog>2000</accept-backlog> <auto-restart>true</auto-restart> <cluster>my-cluster</cluster> <restart-max>10</restart-max> <reverse-dns-allowed>true</reverse-dns-allowed> <staging-mode>external_stage</staging-mode> <startup-timeout>600</startup-timeout> </server-template>