ラベル Tomcat7 の投稿を表示しています。 すべての投稿を表示
ラベル Tomcat7 の投稿を表示しています。 すべての投稿を表示

2012年12月28日金曜日

OpenShiftのTomcat添付README(作成中)

OpenShiftのTomcatに付いていたREADME。
徐々に翻訳予定。


Repo layout
レポレイアウト
===========
webapps/ - location for built wars (Details below)
webapps/ - 構築されたWARファイルの配置場所(以下詳細)
src/ - Maven src structure
src/ - Mavenのソース構造
pom.xml - Maven build file
pom.xml - Mavenのビルドファイル
.openshift/ - location for openshift specific files
.openshift/ - openshiftの詳細ファイル配置場所
.openshift/config/ - location for configuration files such as standalone.xml (used to modify jboss config such as datasources)
.openshift/config/ - standalone.xmlなど設定ファイル配置場所 (データソースなどJBoss設定に使用)
ん?standalone.xmlなんか無いぞ?server.xmlなどtomcatの設定ファイルだぞ?
.openshift/action_hooks/pre_build - Script that gets run every git push before the build (on the CI system if available)
.openshift/action_hooks/pre_build - git pushビルドの前に実行されるスクリプト(もし有効であればCIシステム上で)
.openshift/action_hooks/build - Script that gets run every git push as part of the build process (on the CI system if available)
.openshift/action_hooks/build - git pushビルドプロセスの一部として実行されるスクリプト(もし有効であればCIシステム上で)
.openshift/action_hooks/deploy - Script that gets run every git push after build but before the app is restarted
.openshift/action_hooks/deploy - git pushビルド後毎に実行されるアプリが再起動される前に実行されるスクリプト
.openshift/action_hooks/post_deploy - Script that gets run every git push after the app is restarted
.openshift/action_hooks/post_deploy - アプリが再起動された後、git push毎に実行されるスクリプト
.openshift/action_hooks/pre_start_jbossews-1.0 - Script that gets run prior to starting EWS1.0
.openshift/action_hooks/pre_start_jbossews-1.0 - EWS1.0を開始する前に実行されるスクリプト
.openshift/action_hooks/post_start_jbossews-1.0 - Script that gets run after EWS1.0 is started
.openshift/action_hooks/post_start_jbossews-1.0 - EWS1.0開始後に実行されるスクリプト
.openshift/action_hooks/pre_stop_jbossews-1.0 - Script that gets run prior to stopping EWS1.0
.openshift/action_hooks/pre_stop_jbossews-1.0 - EWS1.0を停止する前に実行されるスクリプト
.openshift/action_hooks/post_stop_jbossews-1.0 - Script that gets run after EWS1.0 is stopped
.openshift/action_hooks/post_stop_jbossews-1.0 - EWS1.0停止後に実行されるスクリプト


Notes about layout
レイアウトについての注意事項
==================
Note: Every time you push, everything in your remote repo dir gets recreated
      please store long term items (like an sqlite database) in the OpenShift
      data directory, which will persist between pushes of your repo.
注意:あなたがpushをかける度に、あなたのリモート・レポ・ディレクトリ内全ては再作成を受けるので、OpenShiftデータ・ディレクトリには長期アイテム(sqliteデータベースのような)をストアしてください。そこはプッシュの間も持続されます。
      The OpenShift data directory is accessible relative to the remote repo
      directory (../data) or via an environment variable OPENSHIFT_DATA_DIR.
OpenShiftのdataディレクトリは、相対的なリモートレポ(../data)経由、又はOPENSHIFT_DATA_DIR環境変数を経由してアクセス可能です。


Details about layout and deployment options
レイアウトとデプロイメント・オプションの詳細
==================
There are two options for deploying content to the Tomcat Server within OpenShift.
OpenShiftのTomcatサーバーにコンテンツをデプロイするのに2つのオプションがある。 
Both options can be used together (i.e. build one archive from source and others pre-built)
どちらのオプションも一緒に使用される(すなわち、ソースと他のプレ・ビルドから一つのアーカイブがビルドされる)。

1) (Preferred) You can upload your content in a Maven src structure as is this sample project and on git push have the application built and deployed.
1) (好ましい方法)サンプルプロジェクトのようにMavenソース構造のコンテンツをアップロード可能であり、そしてgit pushでアプリケーションをビルドし、デプロイされる。
For this to work you'll need your pom.xml at the root of your repository and a maven-war-plugin like in this sample to move the output from the build to the webapps directory.
これが正常に機能するために、レポジトリルートにpom.xmlが必要で、サンプルのようなmaven-war-pluginがbuildからwebappsディレクトリへ出力するのに必要だろう。
By default the warName is ROOT within pom.xml.
デフォルトのWARファイル名は、pom.xmlの中にあるROOTである。
This will cause the webapp contents to be rendered at http://app_name-amespace.rhcloud.com/.
これはwebappコンテンツがhttp://app_name-amespace.rhcloud.com/で表示されるためである。
If you change the warName in pom.xml to app_name, your base url would then become http://app_name-namespace.rhcloud.com/app_name.
もしpom.xml中のwarNameをapp_nameに変えたなら、ベースURLはhttp://app_name-namespace.rhcloud.com/app_nameとなる。
Note: If you are building locally you'll also want to add any output wars under webapps
from the build to your .gitignore file.
注意:もしローカルでビルドしているのなら、幾つかwebapps下に出力したwarファイルを、ビルドから.gitignoreファイルまで追加を望むでしょう。
Note: If you are running scaled EWS1.0 then you need an application deployed to the root context (i.e. http://app_name-namespace.rhcloud.com/) for the HAProxy load-balancer to recognize that the EWS1.0 instance is active.
注意:もし貴方がスケールされたEWS1.0を実行しているなら、EWS1.0インスタンスがアクティブであることを認識する為に、HAProxyロードバランサーの為に、ルートコンテキストへのアプリケーション配備が必要です。
or
もしくは
2) You can git push pre-built wars into webapps/.
2) webappsフォルダにプレビルドのwarをgit pushすることができる。
To do this with the default repo you'll want to first run 'git rm -r src/ pom.xml' from the root of your repo.
デフォルトのレポでこれを行うには、あなたのレポのルートから'git rm -r src/ pom.xml'を最初に実行しようと望むだろう。
Basic workflows for deploying pre-built content (each operation will require associated git add/commit/push operations to take effect):
ビルド前コンテンツをデプロイするための基本ワークフロー(各オペレーションは有効となるためにgit add/commit/push操作に関連が必要となる):

A) Add new zipped content and deploy it:
A)新規ZIPコンテンツを追加し、それをデプロイする:

1. cp target/example.war webapps/

B) Undeploy currently deployed content:
B)現在デプロイされたコンテンツをアンデプロイする:

1. git rm webapps/example.war

C) Replace currently deployed zipped content with a new version and deploy it:
C)現在デプロイされたZIPコンテンツを新バージョンに置き換え、それをデプロイする:

1. cp target/example.war webapps/

Note: You can get the information in the uri above from running 'rhc domain show'
注意:あなたは'rhc domain show'実行結果のURIの中で、情報を入手可能である。

If you have already committed large files to your git repo, you rewrite or reset the history of those files in git to an earlier point in time and then 'git push --force' to apply those changes on the remote OpenShift server.
あなたがGitレポに、既にコミットされた大きなファイルを有しているのなら、あなたは上書き又はそれらのファイルの履歴をgit以前の時点にリセットし、次に'git push --force'を適用してリモートOpenShiftサーバー上でこれらを変更して欲しい。
A git gc on the remote OpenShift repo can be forced with (Note: tidy also does other cleanup including clearing log files and tmp dirs):
リモートOpenShift上のgit gcは、強制させることもできる(注意:)
rhc app tidy -a appname


Whether you choose option 1) or 2) the end result will be the application
deployed into the webapps directory. The webapps directory in the
Tomcat distribution is the location end users can place
their deployment content (e.g. war, ear, jar, sar files) to have it
automatically deployed into the server runtime.

Environment Variables
=====================

OpenShift provides several environment variables to reference for ease
of use.  The following list are some common variables but far from exhaustive:

    System.getenv("OPENSHIFT_APP_NAME")  - Application name
    System.getenv("OPENSHIFT_DATA_DIR")  - For persistent storage (between pushes)
    System.getenv("OPENSHIFT_TMP_DIR")   - Temp storage (unmodified files deleted after 10 days)
    System.getenv("OPENSHIFT_INTERNAL_IP")  - The IP address used to bind EWS1.0

When embedding a database using 'rhc app cartridge add', you can reference environment
variables for username, host and password. For example, when embedding MySQL 5.1, the
following variables will be available:

    System.getenv("OPENSHIFT_MYSQL_DB_HOST")      - DB host
    System.getenv("OPENSHIFT_MYSQL_DB_PORT")      - DB Port
    System.getenv("OPENSHIFT_MYSQL_DB_USERNAME")  - DB Username
    System.getenv("OPENSHIFT_MYSQL_DB_PASSWORD")  - DB Password

To get a full list of environment variables, simply add a line in your
.openshift/action_hooks/build script that says "export" and push.

2012年6月20日水曜日

Pluto2.0の日本語文字化け対策

ApachePluto2.0をデフォルトのまま使うと、こんな文字化けが発生する。
  1. JSPやポートレットの日本語が文字化けする。
  2. 画面からPostした日本語が文字化けする。
で、その対策を書いておく。

対策としては、普通のWEBアプリ同様エンコードをUTF-8に統一すればOK。
今回、その対象となるのが、Plutoのフロントエンドとなるplutoアプリ。
この、plutoアプリのweb.xmlを修正する。
つまり、pluto-2.0.3/webapps/pluto/WEB-INF/web.xmlを修正する。

修正したのが下記XML。
修正内容としては、変更や削除は何もなく、サーブレットパラメータとエンコーディングフィルタの追加のみ。
  1. 青文字が、JSPやポートレットの文字化け対策。
    plutoPortalDriverサーブレットのcharsetパラメータにUTF-8を指定する。
    参考情報
    Pluto - Frequently Asked Questions
    http://portals.apache.org/pluto/faq.html
    How can I change the default encoding of the Pluto Portal
  2. 赤文字が、Postした日本語の文字化け対策。
    Tomcatが持ってるエンコーディングフィルタを使って、ブラウザと送受信するデータをUTF-8と指定する。
    昔はサンプルだったのに、いつのまにやら本体に入ってたのね。
エンコーディングフィルタはともかく、サーブレットパラメータはデフォルトをUTF-8にしてくれればいいのにね。

[web.xml]

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

  <display-name>Apache Pluto Portal Driver</display-name>

    <filter>
        <filter-name>EncodeFilter</filter-name>
        <filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>EncodeFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/pluto-portal-driver-services-config.xml</param-value>
  </context-param>

  <filter>
    <filter-name>plutoPortalDriver</filter-name>
    <filter-class>org.apache.pluto.driver.PortalDriverFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>plutoPortalDriver</filter-name>
    <url-pattern>/about.jsp</url-pattern>
  </filter-mapping>

  <filter-mapping>
    <filter-name>plutoPortalDriver</filter-name>
    <url-pattern>/about.jsp/*</url-pattern>
  </filter-mapping>

  <listener>
    <listener-class>org.apache.pluto.driver.PortalStartupListener</listener-class>
  </listener>

  <servlet>
    <servlet-name>plutoPortalDriver</servlet-name>
    <display-name>Pluto Portal Driver</display-name>
    <description>Pluto Portal Driver Controller</description>
    <servlet-class>org.apache.pluto.driver.PortalDriverServlet</servlet-class>
    <init-param>
      <param-name>charset</param-name>
      <param-value>UTF-8</param-value>
   </init-param>
  </servlet>

  <servlet>
    <servlet-name>plutoPortalDriverLogout</servlet-name>
    <display-name>Pluto Portal Driver</display-name>
    <description>Pluto Portal Driver Logout</description>
    <servlet-class>org.apache.pluto.driver.PortalDriverLogoutServlet</servlet-class>
  </servlet>

  <servlet>
    <servlet-name>portletApplicationPublisher</servlet-name>
    <display-name>Portlet Application Publisher</display-name>
    <description>Portlet Application Publisher Service</description>
    <servlet-class>org.apache.pluto.driver.PublishServlet</servlet-class>
  </servlet>

  <servlet>
    <servlet-name>tckDriver</servlet-name>
    <display-name>Pluto TCK Driver</display-name>
    <description>Pluto TCK Driver Controller</description>
    <servlet-class>org.apache.pluto.driver.TCKDriverServlet</servlet-class>
  </servlet>

  <servlet>
    <servlet-name>AboutPortlet</servlet-name>
    <servlet-class>org.apache.pluto.container.driver.PortletServlet</servlet-class>
    <init-param>
      <param-name>portlet-name</param-name>
      <param-value>AboutPortlet</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>AdminPortlet</servlet-name>
    <servlet-class>org.apache.pluto.container.driver.PortletServlet</servlet-class>
    <init-param>
      <param-name>portlet-name</param-name>
      <param-value>AdminPortlet</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>PlutoPageAdmin</servlet-name>
    <servlet-class>org.apache.pluto.container.driver.PortletServlet</servlet-class>
    <init-param>
      <param-name>portlet-name</param-name>
      <param-value>PlutoPageAdmin</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>plutoPortalDriver</servlet-name>
    <url-pattern>/portal/*</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>plutoPortalDriverLogout</servlet-name>
    <url-pattern>/Logout</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>portletApplicationPublisher</servlet-name>
    <url-pattern>/admin/Publish</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>tckDriver</servlet-name>
    <url-pattern>/tck/*</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>AboutPortlet</servlet-name>
    <url-pattern>/PlutoInvoker/AboutPortlet</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>AdminPortlet</servlet-name>
    <url-pattern>/PlutoInvoker/AdminPortlet</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>PlutoPageAdmin</servlet-name>
    <url-pattern>/PlutoInvoker/PlutoPageAdmin</url-pattern>
  </servlet-mapping>

  <taglib>
    <taglib-uri>http://portals.apache.org/pluto</taglib-uri>
    <taglib-location>/WEB-INF/tld/pluto.tld</taglib-location>
  </taglib>

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>portal</web-resource-name>
      <url-pattern>/portal</url-pattern>
      <url-pattern>/portal/*</url-pattern>
      <http-method>GET</http-method>
      <http-method>POST</http-method>
      <http-method>PUT</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>pluto</role-name>
    </auth-constraint>
  </security-constraint>

  <login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
      <form-login-page>/login.jsp</form-login-page>
      <form-error-page>/login.jsp?error=1</form-error-page>
    </form-login-config>
  </login-config>

  <security-role>
    <role-name>pluto</role-name>
  </security-role>

</web-app>


2012年6月19日火曜日

OpenShiftDIYのTomcat7用server.xml

OpenShiftにDIYアプリケーションを作成し、その中にTomcat7を作ってみた。
その際に設定のキモだったのがTomcatのserver.xmlだったので、その中身を書いておく。

Liferayや他のアプリケーションサーバでもTomcat7なら、このserver.xmlでいけるかもしれない。
でもLiferayはデプロイ設定を変えないとNGだろうな…、OpenShiftはホームディレクトリに書き込み権限が無いからね。
っと思い、試しにOpenShiftDIYにLiferayをセットアップし、走らせた結果…
起動中に「Killed」が出てきてダウンした。
たぶんメモリ不足か何か使用可能リソース制限に触れたのだと思う。
ならばJetspeed2でどうよ、っと思いJetspeed2を試した結果…
Jetspeed2も起動中に「Killed」でダウン。
主要ポートレットコンテナ2つが使用不可なのが残念。
Pluto2.0は動作可能だから、とりあえずはPluto2.0でいいや。

ココの料金ページによると、無料で使えるFreeは、Gear SizesはSmallがデフォルト。
このSmallだとメモリ容量は512 MB RAMだそうな。Mediumだと1 GB RAMだそうな。
Pricing

ココのコミュニティフォーラム記事によると、デフォルトはスモールサイズらしい。
ミディアムサイズにしたければopenshift@redhat.comにメールを送れってことだった。
Cannot deploy Liferay because of PermGen

20120927 Liferayのクイックスタートがあるので、Liferayを作れるかもしれない
openshift / jbossas7-liferay-quickstart

で、本題に戻って…
DIYの中にTomcatを作る方法は、ココ。
Free Apache Tomcat Hosting in the Cloud for Java Applications? It's Called OpenShift!
https://openshift.redhat.com/community/blogs/free-apache-tomcat-hosting-in-the-cloud-for-java-applications-its-called-openshift

20120918 どうやらshutdown設定とajp設定にIPアドレスを入れないと動かないようになったみたいなので、設定追加

で、今回は各設定を下記のようにした前提。
URL = tomcat-yourdomain.rhcloud.com
OPENSHIFT_INTERNAL_IP = 127.6.99.1

[server.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.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="15005" shutdown="SHUTDOWN" address="127.6.99.1" >
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <Listener className="org.apache.catalina.core.JasperListener" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               address="127.6.99.1"
               redirectPort="15443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the JSSE configuration, when using APR, the
         connector should be using the OpenSSL style configuration
         described in the APR documentation -->
    <!--
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="15009" protocol="AJP/1.3" redirectPort="8443" address="127.6.99.1" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="127.6.99.1">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="tomcat-yourdomain.rhcloud.com"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>