![IMG_6906](https://img-proxy.blog-video.jp/images?url=http%3A%2F%2Ffarm4.staticflickr.com%2F3491%2F4055486946_cdb1fb2b3c.jpg)
以前のエントリー(Tomcat起動時のJava仮想マシンのパフォーマンスチューニング)とかぶる部分もあるけど、色々調べたのでまとめ。
一応Tomcat7で調べた結果です。
Tomcatの起動オプションは${CATALINA_BASE}/bin/setenv.shに色々書くといい。
JAVA_HOMEなんかを書いていく。
でオプションは2種類の書き方がある。
JAVA_OPTSとCATALINA_OPTS
前者は起動時停止時に呼ばれる。後者は起動時のみ。
詳しくはcatalina.shに書いてある。
一部抜粋
# CATALINA_OPTS (Optional) Java runtime options used when the "start",# "run" or "debug" command is executed.# Include here and not in JAVA_OPTS all options, that should# only be used by Tomcat itself, not by the stop process,# the version command etc.# Examples are heap size, GC logging, JMX ports etc.
...
# JAVA_OPTS (Optional) Java runtime options used when any command# is executed.# Include here and not in CATALINA_OPTS all options, that# should be used by Tomcat and also by the stop process,# the version command etc.# Most options should go into CATALINA_OPTS.
これを読む限り、JAVA_OPTSには-versionオプションぐらいで、基本CATALINA_OPTSに書くと良いらしい。
余談ですがTomcat4.1以前(あまり細かくは知らない)のバージョンではここに差は無かった様子。
なんにせよCATALINA_OPTSに色々書いていく。
-server
JVMにはサーバ用VMとクライアント用VMがあり、サーバ用VMは長時間動作するのに最適化されている。
-XX:MaxPermSize=256m -XX:PermSize=256m -XX:SurvivorRatio=2 -Xmn1024m -Xmx2048m -Xms2048m
ヒープの設定。この辺は別の記事を見て下さい。。
-XX:+PrintGCDetails -Xloggc:${CATALINA_BASE}/logs/gc.log.${DATE}
GCのログ出し。障害時に見るといいよ。
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3333 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true
JMXによる監視の設定、一応認証をTrueにしているので下記の設定も必要。
ちなみにportの設定を間違えてJAVA_OPTSに設定すると、Tomcatが停止しなくなる。
-Dcom.sun.management.jmxremote.password.file=${CATALINA_BASE}/conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=${CATALINA_BASE}/conf/jmxremote.access
jmxremote.passwordとjmxremote.accessという2つのファイルを使って認証を制御する。
詳しくわこっちを。
Java VisualVMを使ってみた話
こんな感じで設定しました。
#!/bin/shumask 002DATE=`date +'%Y%m%d-%H%M'`
JAVA_HOME=/usr/local/javaexport JAVA_HOME
CATALINA_OPTS="-server -XX:MaxPermSize=256m -XX:PermSize=256m -XX:SurvivorRatio=2 -Xmn1024m -Xmx2048m -Xms2048m"CATALINA_OPTS="${CATALINA_OPTS} -XX:+PrintGCDetails -Xloggc:${CATALINA_BASE}/logs/gc.log.${DATE}"
CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3333 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true"CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote.password.file=${CATALINA_BASE}/conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=${CATALINA_BASE}/conf/jmxremote.access"export CATALINA_OPTS
もっと良い設定を知ってるよって人は教えてください!
![]() | Apache Tomcat 7 Aleksa Vukotic James Goodwill Apress 2011-08-29 売り上げランキング : 71994 Amazonで詳しく見る |