HomeDocumentation > 1. 管理 > 1.4. Geronimo-Tomcatでの仮想ホストの構成
{scrollbar}

top
この記事では、Tomcat版のApache Geronimoで仮想ホストを構成する方法をご紹介します。デフォルトでは、Geronimoのアプリケーションをデプロイしてスタートすると、そのアプリケーションは、利用可能なホスト名すべてに対してリスンしています。仮想ホストを構成すれば、アプリケーションが特定のホスト名やIPアドレスのみをリスンするようにできます。この記事で述べている構成手順はいくつかのホスト名で同一のIPアドレスを共用しているときでも有効です。

Geronimoで仮想ホストを構成する際は、基本的に以下の手順を踏みます。

この記事は参考としてHelloWorldアプリケーションを使いますが、このアプリケーションは 5. クイック・スタート - いますぐ始めたい人の Apache Geronimo セクションでカバーされています。

ローカルホストまたはDNSの構成

この構成を組むためには、貴方がこれから定義しようとしている仮想ホスト名が名前解決されなくてはなりません。貴方のネットワーク環境により、DNSにGeronimoサーバーのIPをエントリーとして追加しても結構です。また別の方法として、ローカルホストのテーブルへエントリーを追加するのでもよいです。ローカルホスト・テーブルへの登録の仕方はOSにより様々です。例えばWindowsでは %SystemRoot%\system32\drivers\etc\hosts ですし、UNIXベースのオペレーティング・システムでは通常は /etc/hosts になります。

例として、ローカルホスト・テーブルに定義済の下記のホスト名を使っていきましょう。

127.0.0.1 localhost virtualhost1.com virtualhost2.com virtualhost3.com virtualhost4.com

貴方のシステムでこれらの名前解決ができることを確認してください。

仮想ホストの定義

次に、仮想ホストをGeronimoに認識させるためにGeronimoの config.xml に仮想ホストを定義します。このセクションでは2つの異なる仮想ホストの定義を使います。つまりGeronimoの構成では2つの新しい HostGBean (TomcatVirtualHost1 と TomcatVirtualHost2)を作成します。そのうちの1つは複数のホスト別名を持つようにします。この例では、あるアプリケーションがひとつの仮想ホスト(virtualhost1.comとします)をリスンしており、もうひとつのアプリケーションは追加の2つのホスト別名(virtualhost3.comとvirtualhost4.comとします)を持っている別の仮想ホスト(virtualhost2.comとします) をリスンしているような構成を作ってみます

<geronimo_home>/var ディレクトリー上の config.xml ファイルを開き、<module name="org.apache.geronimo.configs/tomcat6/2.0/car"> という行を探してください。これがTomcat構成モジュールの始まりの行であり、この行のすぐ下に仮想ホストの定義を追加します。

最初のHostGBeanである TomcatVirtualHost_1 を定義するには、 <module name="org.apache.geronimo.configs/tomcat6/2.0/car"> という行のすぐ次に以下の行を追加してください。

xmlsolidconfog.xmlからの抜粋 ... <gbean gbeanInfo="org.apache.geronimo.tomcat.HostGBean" name="org.apache.geronimo.configs/tomcat6/2.0/car?ServiceModule=org.apache.geronimo.configs/tomcat6/2.0/car,j2eeType=Host,name=TomcatVirtualHost_1"> <attribute name="className">org.apache.catalina.core.StandardHost</attribute> <attribute name="initParams">name=virtualhost1.com appBase= workDir=work</attribute> </gbean> ...

2番目のHostGBeanである TomcatVirtualHost_2 の定義は、最初のHostGBeanのすぐ下に追加してください。この2つのHostGBeanは別々に分離されているので見分けるのは容易でしょう。この2つは、別名を定義するための <attribute name="aliases">..,..</attribute> の部分が異なっています。

xmlsolidconfog.xmlからの抜粋 ... <gbean gbeanInfo="org.apache.geronimo.tomcat.HostGBean" name="org.apache.geronimo.configs/tomcat6/2.0/car?ServiceModule=org.apache.geronimo.configs/tomcat6/2.0/car,j2eeType=Host,name=TomcatVirtualHost_2"> <attribute name="className">org.apache.catalina.core.StandardHost</attribute> <attribute name="initParams">name=virtualhost2.com appBase= workDir=work</attribute> <attribute name="aliases">virtualhost3.com,virtualhost4.com</attribute> </gbean> ...

これでGeronimo.に2つの異なる仮想ホストを構成することができました。 config.xml に対して行った変更を保管してGeronimoを start してください。

Back to Top

ご参考までに、下記に2つのHostGBeanが定義済の config.xml の全体を掲載します。

xmlsolidconfig.xml <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- $Rev: 562176 $ $Date: 2007-08-02 12:31:43 -0400 (Thu, 02 Aug 2007) $ --> <!-- ======================================================== --> <!-- Warning - This XML file is re-generated by Geronimo when --> <!-- changes are made to Geronimo's configuration, therefore --> <!-- any comments added to this file will be lost. --> <!-- ======================================================== --> <attributes xmlns="http://geronimo.apache.org/xml/ns/attributes-1.1"> <module name="org.apache.geronimo.configs/rmi-naming/2.0/car"> <gbean name="RMIRegistry"> <attribute name="port">${NamingPort + PortOffset}</attribute> </gbean> <gbean name="NamingProperties"> <!-- Check whether this really works if host name is 0.0.0.0 --> <attribute name="namingProviderUrl">rmi://${ServerHostname}:${NamingPort + PortOffset}</attribute> </gbean> <gbean name="DownloadedPluginRepos"> <attribute name="repositoryList">http://geronimo.apache.org/plugins/plugin-repository-list-2.0.txt</attribute> <attribute name="userRepositories">[]</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/j2ee-server/2.0/car"/> <module name="org.apache.geronimo.configs/transaction/2.0/car"/> <module name="org.apache.geronimo.configs/j2ee-security/2.0/car"> <gbean name="JMXService"> <attribute name="protocol">rmi</attribute> <attribute name="host">${ServerHostname}</attribute> <attribute name="port">${JMXPort + PortOffset}</attribute> <attribute name="urlPath">/jndi/rmi://${ServerHostname}:${NamingPort + PortOffset}/JMXConnector</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/axis/2.0/car" load="false"/> <module name="org.apache.geronimo.configs/axis2/2.0/car" load="false"/> <module name="org.apache.geronimo.configs/cxf/2.0/car" load="false"/> <module name="org.apache.geronimo.configs/openejb/2.0/car"> <gbean name="EJBNetworkService"> <attribute name="port">${OpenEJBPort + PortOffset}</attribute> <attribute name="host">${ServerHostname}</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/j2ee-corba-yoko/2.0/car" load="false"> <gbean name="NameServer"> <attribute name="port">${COSNamingPort + PortOffset}</attribute> <attribute name="host">${COSNamingHost}</attribute> </gbean> <gbean name="Server"> <attribute name="port">${ORBSSLPort + PortOffset}</attribute> <attribute name="host">${ORBSSLHost}</attribute> </gbean> <gbean name="UnprotectedServer"> <attribute name="port">${ORBPort + PortOffset}</attribute> <attribute name="host">${ORBHost}</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/system-database/2.0/car"> <gbean name="DerbyNetwork"> <attribute name="host">${ServerHostname}</attribute> <attribute name="port">${DerbyPort + PortOffset}</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/activemq-broker/2.0/car"> <gbean name="ActiveMQ.tcp.default"> <attribute name="host">${ServerHostname}</attribute> <attribute name="port">${ActiveMQPort + PortOffset}</attribute> </gbean> <gbean name="ActiveMQ.stomp.default"> <attribute name="host">${ServerHostname}</attribute> <attribute name="port">${ActiveMQStompPort + PortOffset}</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/activemq-ra/2.0/car"> <gbean name="ActiveMQ RA"> <attribute name="ServerUrl">tcp://${ServerHostname}:${ActiveMQPort + PortOffset}</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/jasper/2.0/car" load="false"/> <module name="org.apache.geronimo.configs/myfaces/2.0/car"/> <module name="org.apache.geronimo.configs/tomcat6/2.0/car"> <gbean gbeanInfo="org.apache.geronimo.tomcat.HostGBean" name="org.apache.geronimo.configs/tomcat6/2.0/car?ServiceModule=org.apache.geronimo.configs/tomcat6/2.0/car, j2eeType=Host,name=TomcatVirtualHost_1"> <attribute name="className">org.apache.catalina.core.StandardHost</attribute> <attribute name="initParams">name=virtualhost1.com appBase= workDir=work </attribute> </gbean> <gbean gbeanInfo="org.apache.geronimo.tomcat.HostGBean" name="org.apache.geronimo.configs/tomcat6/2.0/car?ServiceModule=org.apache.geronimo.configs/tomcat6/2.0/car, j2eeType=Host,name=TomcatVirtualHost_2"> <attribute name="className">org.apache.catalina.core.StandardHost</attribute> <attribute name="initParams">name=virtualhost2.com appBase= workDir=work </attribute> <attribute name="aliases">virtualhost3.com,virtualhost4.com</attribute> </gbean> <!-- To disable accesslogging uncomment the following lines <gbean name="TomcatEngine"> <reference name="TomcatValveChain" /> </gbean> <gbean name="FirstValve" load="false"></gbean> --> <gbean name="TomcatResources"/> <gbean name="TomcatWebConnector"> <attribute name="host">${ServerHostname}</attribute> <attribute name="port">${HTTPPortPrimary + PortOffset}</attribute> <attribute name="redirectPort">${HTTPSPortPrimary + PortOffset}</attribute> </gbean> <gbean name="TomcatAJPConnector"> <attribute name="host">${ServerHostname}</attribute> <attribute name="port">${AJPPortPrimary + PortOffset}</attribute> <attribute name="redirectPort">${HTTPSPortPrimary + PortOffset}</attribute> </gbean> <gbean name="TomcatWebSSLConnector"> <attribute name="host">${ServerHostname}</attribute> <attribute name="port">${HTTPSPortPrimary + PortOffset}</attribute> </gbean> </module> <!-- NOTE: n.b. be sure the gbean deployer is explicitly loaded before j2ee-deployer so that defaultEnvironment overrides work properly --> <module name="org.apache.geronimo.configs/geronimo-gbean-deployer/2.0/car"/> <module name="org.apache.geronimo.configs/j2ee-deployer/2.0/car"> <gbean name="WebBuilder"> <attribute name="defaultNamespace">http://geronimo.apache.org/xml/ns/j2ee/web/tomcat-2.0</attribute> </gbean> <gbean name="EnvironmentEntryBuilder"> <attribute name="eeNamespaces">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/connector-deployer/2.0/car"> <gbean name="ResourceRefBuilder"> <attribute name="eeNamespaces">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</attribute> <attribute name="defaultEnvironment"> <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2"> <dependencies> <dependency> <groupId>org.apache.geronimo.configs</groupId> <artifactId>j2ee-corba-yoko</artifactId> <type>car</type> </dependency> </dependencies> </environment> </attribute> </gbean> <gbean name="AdminObjectRefBuilder"> <attribute name="eeNamespaces">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</attribute> </gbean> <gbean name="ClientResourceRefBuilder"> <attribute name="eeNamespaces">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</attribute> <attribute name="defaultEnvironment"> <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2"> <dependencies> <dependency> <groupId>org.apache.geronimo.configs</groupId> <artifactId>client-corba-yoko</artifactId> <type>car</type> </dependency> </dependencies> </environment> </attribute> </gbean> </module> <module name="org.apache.geronimo.configs/persistence-jpa10-deployer/2.0/car"> <gbean name="PersistenceUnitBuilder"> <attribute name="defaultPersistenceProviderClassName">org.apache.openjpa.persistence.PersistenceProviderImpl</attribute> <attribute name="defaultPersistenceUnitProperties"> openjpa.Log=commons # openjpa.jdbc.DBDictionary=org.apache.openjpa.jdbc.sql.DerbyDictionary openjpa.jdbc.SynchronizeMappings=buildSchema(ForeignKeys=true) openjpa.jdbc.UpdateManager=operation-order openjpa.Sequence=table(Table=OPENJPASEQ, Increment=100) </attribute> <attribute name="defaultEnvironment"> <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2"> <dependencies> <dependency> <groupId>org.apache.geronimo.configs</groupId> <artifactId>openjpa</artifactId> <type>car</type> </dependency> </dependencies> </environment> </attribute> </gbean> </module> <module name="org.apache.geronimo.configs/openejb-deployer/2.0/car"> <gbean name="EjbRefBuilder"> <attribute name="eeNamespaces">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</attribute> </gbean> <gbean name="ClientEjbRefBuilder"> <attribute name="eeNamespaces">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/client-deployer/2.0/car"> </module> <module name="org.apache.geronimo.configs/axis2-deployer/2.0/car" condition="props.getProperty('org.apache.geronimo.jaxws.provider', 'axis2') == 'axis2'"> <gbean name="Axis2ModuleBuilderExtension"> <attribute name="listener">?name=TomcatWebContainer</attribute> <attribute name="defaultEnvironment"> <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2"> <dependencies> <dependency> <groupId>org.apache.geronimo.configs</groupId> <artifactId>tomcat6</artifactId> <type>car</type> </dependency> </dependencies> </environment> </attribute> </gbean> </module> <module name="org.apache.geronimo.configs/cxf-deployer/2.0/car" condition="props['org.apache.geronimo.jaxws.provider'] == 'cxf'"> <gbean name="CXFModuleBuilderExtension"> <attribute name="listener">?name=TomcatWebContainer</attribute> <attribute name="defaultEnvironment"> <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2"> <dependencies> <dependency> <groupId>org.apache.geronimo.configs</groupId> <artifactId>tomcat6</artifactId> <type>car</type> </dependency> </dependencies> </environment> </attribute> </gbean> </module> <module name="org.apache.geronimo.configs/axis-deployer/2.0/car"> <gbean name="AxisServiceRefBuilder"> <attribute name="eeNamespaces">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</attribute> </gbean> <gbean name="AxisModuleBuilderExtension"> <attribute name="listener">?name=TomcatWebContainer</attribute> <attribute name="defaultEnvironment"> <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2"> <dependencies> <dependency> <groupId>org.apache.geronimo.configs</groupId> <artifactId>tomcat6</artifactId> <type>car</type> </dependency> </dependencies> </environment> </attribute> </gbean> </module> <module name="org.apache.geronimo.configs/javamail/2.0/car"> <gbean name="SMTPTransport"> <attribute name="host">localhost</attribute> <attribute name="port">25</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/sharedlib/2.0/car"> <gbean name="SharedLib"> <attribute name="classesDirs">var/shared/classes</attribute> <attribute name="libDirs">var/shared/lib</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/tomcat6-deployer/2.0/car"/> <module name="org.apache.geronimo.configs/jasper-deployer/2.0/car"/> <module name="org.apache.geronimo.configs/myfaces-deployer/2.0/car"/> <module name="org.apache.geronimo.configs/welcome-tomcat/2.0/car"/> <module name="org.apache.geronimo.configs/dojo-tomcat/2.0/car"/> <module name="org.apache.geronimo.configs/webconsole-tomcat/2.0/car"/> <module name="org.apache.geronimo.configs/uddi-tomcat/2.0/car" load="false"/> <module name="org.apache.geronimo.configs/remote-deploy-tomcat/2.0/car" /> <module name="org.apache.geronimo.configs/hot-deployer/2.0/car"/> <module name="org.apache.geronimo.configs/jsr88-rar-configurer/2.0/car"/> <module name="org.apache.geronimo.configs/ca-helper-tomcat/2.0/car" load="false"/> </attributes>

Back to Top

デプロイメント・プランでの仮想ホストの宣言

以前述べた通り、この例では 5. クイック・スタート - いますぐ始めたい人の Apache Geronimo でご説明したHelloWorldサンプル・アプリケーションを使います。これはWebアプリケーションなので、変更するべきデプロイメント・プランは geronimo-web.xml です。もし別の種類のアプリケーションを利用している場合は例えば geronimo-application.xml のような別の種類のデプロイメント・プランを使う必要がある場合もあるでしょう。

前のセクションでは2つの仮想ホストを定義しました。ではこれから2つのアプリケーションが各々の仮想ホストを別々に利用するような形でデプロイしてみます。

双方のケースで同一のアプリケーションを使いますが、お互いを区別するために異なった artifactId を与えてデプロイします。そうすれば、コードを変更せずに各々のデプロイメントを区別することができます。

貴方が 5. クイック・スタート - いますぐ始めたい人の Apache Geronimo のセクションで説明した手順を実施済とすると、貴方の環境は下記のような構造になっているはずです。

solid <app_home>\ + HelloWorld.jsp + WEB-INF\ + geronimo-web.xml + web.xml

geronimo-web.xml ファイルを開き、デプロイメントがユニークになるように artifactIdcontext-root を編集してください。更に web-app セクションに host 属性を追加して、このアプリケーションにリスンさせたい仮想ホスト、このケースでは virtualhost1.com を記述します。

xmlsolidgeronimo-web.xml for HelloWorld_1 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.2"> <environment> <moduleId> <groupId>sample.applications</groupId> <artifactId>HelloWorldApp_1</artifactId> <version>2.0</version> <type>war</type> </moduleId> </environment> <context-root>/hello_1</context-root> <host>virtualhost1.com</host> </web-app>

geronimo-web.xml ファイルへの変更を保管し<app_home>ディレクトリーで下記のコマンドを入力してWARファイルを生成します。:

 jar -cvf HelloWorld_1.war *

一旦デプロイされれば、このアプリケーションはホスト名 virtualhost1.com だけをリスンしているはずです。

この手順を繰り返して2番目のWARを作ります、再度 geronimo-web.xml ファイルを編集し下記の例から中身をコピーしてください。変更するのは artifactId , context-roothost だけですのでご注意ください。

xmlsolidgeronimo-web.xml for HelloWorld_2 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.2"> <environment> <moduleId> <groupId>sample.applications</groupId> <artifactId>HelloWorldApp_2</artifactId> <version>2.0</version> <type>war</type> </moduleId> </environment> <context-root>/hello_2</context-root> <host>virtualhost2.com</host> </web-app>

geronimo-web.xml ファイルへの変更を保管し<app_home> ディレクトリーで下記のコマンドを入力してWARファイルを生成します。

 jar -cvf HelloWorld_2.war *

これで2つのアプリケーションを2つの別々の仮想ホストへデプロイすることができました。

Back to Top

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

ここまでで、Geronimoを2つの仮想ホストを使うように構成できました。そのうちの片方は追加の別名もリスンするよう構成されています。あとはアプリケーションをデプロイしてテストをするだけです。アプリケーションをデプロイするには以下のコマンドを<geronimo_home>\binディレクトリーで入力してください。

deploy --user system --password manager deploy <app_home>\HelloWorld_1.war

下のような成功の確認メッセージが表示されるはずです。

dashed D:\geronimo-tomcat6-jee5-2.0\bin>deploy --user system --password manager deploy \HelloWorld_2.0\HelloWorld_1.war Using GERONIMO_BASE: D:\geronimo-tomcat6-jee5-2.0 Using GERONIMO_HOME: D:\geronimo-tomcat6-jee5-2.0 Using GERONIMO_TMPDIR: var\temp Using JRE_HOME: C:\Java\jdk1.5.0_06\jre Deployed sample.applications/HelloWorldApp_1/2.0/war @ /hello_1

2番目のアプリケーションも同様にデプロイします。

java -jar deployer.jar --user system --password manager deploy <app_home>\HelloWorld_2.war

下のような成功の確認メッセージが表示されるはずです。

dashed D:\geronimo-tomcat6-jee5-2.0\bin>deploy --user system --password manager deploy \HelloWorld_2.0\HelloWorld_2.war Using GERONIMO_BASE: D:\geronimo-tomcat6-jee5-2.0 Using GERONIMO_HOME: D:\geronimo-tomcat6-jee5-2.0 Using GERONIMO_TMPDIR: var\temp Using JRE_HOME: C:\Java\jdk1.5.0_06\jre Deployed sample.applications/HelloWorldApp_2/2.0/war @ /hello_2

あとはデプロイされたアプリケーションをテストするだけです、まず先に hello_1 に対してGeronimoサーバーのマシンに定義されているホスト名を使ってアクセスしてみます。

次は hello_2 で繰り返します。

おめでとうございます!!! 2つのアプリケーションを2つの異なる仮想ホストと別名に割当てる構成とデプロイが成功しました。

Back to Top