Tomcat調優及JMX監控html
實驗背景java
======================================================node
系統版本:CentOS release 6.5 (Final)算法
Tomcat版本: Apache-tomcat-7.0.54express
Tomcat介紹:apache
Tomcat是Apache 軟件基金會(Apache Software Foundation)的Jakarta 項目中的一個核心項目,由Apache、Sun 和其餘一些公司及我的共同開發而成。因爲有了Sun 的參與和支持,最新的Servlet 和JSP 規範老是能在Tomcat 中獲得體現,Tomcat 5支持最新的Servlet 2.4 和JSP 2.0 規範。由於Tomcat 技術先進、性能穩定,並且免費,於是深受Java 愛好者的喜好並獲得了部分軟件開發商的承認,成爲目前比較流行的Web 應用服務器。目前最新版本是8.0。bootstrap
======================================================vim
1
2
|
Tomcat 7最新版本下載連接:
http:
//mirrors
.cnnic.cn
/apache/tomcat/tomcat-7/v7
.0.56
/bin/apache-tomcat-7
.0.56.
tar
.gz
|
1
2
|
Tomcat 安裝:
tar
zxvf apache-tomcat-7.0.54.
tar
.gz -C
/opt/
|
1
2
3
4
5
6
7
8
|
jsvc編譯及調優:
cd
apache-tomcat-7.0.54
/bin
tar
zxvf commons-daemon-native.
tar
.gz
cd
commons-daemon-1.0.x-native-src
/unix
.
/configure
make
-j4
cp
jsvc ../../
cd
../../
|
1
2
|
添加tomcat用戶,後面用來啓動tomcat進程:
useradd
-s
/sbin/nologin
tomcat
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
jsvc help文件:
# export JAVA_HOME=/opt/jdk1.7.0_60/
# ./jsvc --help
Usage: jsvc [-options] class [args...]
Where options include:
-help | --help | -?
show this help page (implies -nodetach)
-jvm <JVM name>
use a specific Java Virtual Machine. Available JVMs:
'server'
-client
use a client Java Virtual Machine.
-server
use a server Java Virtual Machine.
-
cp
| -classpath <directories and zip
/jar
files>
set
search path
for
service classes and resouces
-java-home | -home <directory>
set
the path of your JDK or JRE installation (or
set
the JAVA_HOME environment variable)
-version
show the current Java environment version (to check
correctness of -home and -jvm. Implies -nodetach)
-showversion
show the current Java environment version (to check
correctness of -home and -jvm) and
continue
execution.
-nodetach
don't detach from parent process and become a daemon
-debug
verbosely print debugging information
-check
only check service (implies -nodetach)
-user <user>
user used to run the daemon (defaults to current user)
-verbose[:class|gc|jni]
enable
verbose output
-cwd <
/full/path
>
set
working directory to given location (defaults to /)
-outfile <
/full/path/to/file
>
Location
for
output from stdout (defaults to
/dev/null
)
Use the value
'&2'
to simulate
'1>&2'
-errfile <
/full/path/to/file
>
Location
for
output from stderr (defaults to
/dev/null
)
Use the value
'&1'
to simulate
'2>&1'
-pidfile <
/full/path/to/file
>
Location
for
output from the
file
containing the pid of jsvc
(defaults to
/var/run/jsvc
.pid)
-D<name>=<value>
set
a Java system property
-X<option>
set
Virtual Machine specific option
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable
assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable
system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-procname <procname>
use the specified process name
-wait <waittime>
wait waittime seconds
for
the service to start
waittime should multiple of 10 (min=10)
-stop
stop the service using the
file
given
in
the -pidfile option
-keepstdin
does not redirect stdin to
/dev/null
jsvc (Apache Commons Daemon) 1.0.15-dev
Copyright (c) 1999-2013 Apache Software Foundation.
|
=============================================================瀏覽器
接下來是重點了!tomcat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
jsvc 調優參數:
export
PATH=
/bin
:
/sbin
:
/usr/bin
:
/usr/sbin
export
JAVA_HOME=
/opt/jdk1
.7.0_60
export
JRE_HOME=
/opt/jdk1
.7.0_60
/jre
export
CATALINA_BASE=
/opt/apache-tomcat-7
.0.54
export
CATALINA_HOME=
/opt/apache-tomcat-7
.0.54
export
CATALINA_PID=$CATALINA_BASE
/logs/catalina-daemon
.pid
export
CATALINA_TMP=$CATALINA_BASE
/temp
export
TOMCAT_USER=tomcat
export
CATALINA_OPTS="-server -Xss512k -Xms2048M -Xmx2048M -XX:MaxPermSize=256M -XX:PermSize=128M -XX:NewSize=128M -XX:+CMSIncreme
ntalMode -XX:CMSInitiatingOccupancyFraction=80 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:ParallelGCThreads=8 -Djavax.servlet.r
equest.encoding=UTF-8 -Djavax.servlet.response.encoding=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia
/Shanghai
-Dcom.sun.manage
ment.jmxremote -Dcom.sun.management.jmxremote.port=100861 -Dcom.sun.management.jmxremote.ssl=
false
-Dcom.sun.management.jmxremote.a
uthenticate=
false
-Djava.rmi.server.
hostname
=192.168.3.5"
|
1
2
|
-XX:+CMSIncrementalMode
該標誌將開啓CMS收集器的增量模式。增量模式常常暫停CMS過程,以便對應用程序線程做出徹底的讓步。所以,收集器將花更長的時間完成整個收集週期。所以,只有經過測試後發現正常CMS週期對應用程序線程干擾太大時,才應該使用增量模式。因爲現代服務器有足夠的處理器來適應併發的垃圾收集,因此這種狀況發生得不多。
|
1
2
3
|
-XX:CMSInitiatingOccupancyFraction
當堆滿以後,並行收集器便開始進行垃圾收集,例如,當沒有足夠的空間來容納新分配或提高的對象。對於CMS收集器,長時間等待是不可取的,由於在併發垃圾收集期間應用持續在運行(而且分配對象)。所以,爲了在應用程序使用完內存以前完成垃圾收集週期,CMS收集器要比並行收集器更先啓動。
由於不一樣的應用會有不一樣對象分配模式,JVM會收集實際的對象分配(和釋放)的運行時數據,而且分析這些數據,來決定何時啓動一次CMS垃圾收集週期。爲了引導這一過程, JVM會在一開始執行CMS週期前做一些線索查找。該線索由 -XX:CMSInitiatingOccupancyFraction=<value>來設置,該值表明老年代堆空間的使用率。好比,value=75意味着第一次CMS垃圾收集會在老年代被佔用75%時被觸發。一般CMSInitiatingOccupancyFraction的默認值爲68(以前很長時間的經從來決定的)。
|
1
2
|
-XX:+UseConcMarkSweepGC
該標誌首先是激活CMS收集器。默認HotSpot JVM使用的是並行收集器。
|
1
2
3
|
-XX:UseParNewGC
當使用CMS收集器時,該標誌激活年輕代使用多線程並行執行垃圾回收。這使人很驚訝,咱們不能簡單在並行收集器中重用-XX:UserParNewGC標誌,由於概念上年輕代用的算法是同樣的。然而,對於CMS收集器,年輕代GC算法和老年代GC算法是不一樣的,所以年輕代GC有兩種不一樣的實現,而且是兩個不一樣的標誌。
注意最新的JVM版本,當使用-XX:+UseConcMarkSweepGC時,-XX:UseParNewGC會自動開啓。所以,若是年輕代的並行GC不想開啓,能夠經過設置-XX:-UseParNewGC來關掉。
|
1
2
3
4
|
XX:ConcGCThreads
標誌-XX:ConcGCThreads=<value>(早期JVM版本也叫-XX:ParallelCMSThreads)定義併發CMS過程運行時的線程數。好比value=4意味着CMS週期的全部階段都以4個線程來執行。儘管更多的線程會加快併發CMS過程,但其也會帶來額外的同步開銷。所以,對於特定的應用程序,應該經過測試來判斷增長CMS線程數是否真的可以帶來性能的提高。
若是還標誌未設置,JVM會根據並行收集器中的-XX:ParallelGCThreads參數的值來計算出默認的並行CMS線程數。該公式是ConcGCThreads = (ParallelGCThreads + 3)
/4
。所以,對於CMS收集器, -XX:ParallelGCThreads標誌不只影響「stop-the-world」垃圾收集階段,還影響併發階段。
總之,有很多方法能夠配置CMS收集器的多線程執行。正是因爲這個緣由,建議第一次運行CMS收集器時使用其默認設置, 而後若是須要調優再進行測試。只有在生產系統中測量(或類生產測試系統)發現應用程序的暫停時間的目標沒有達到 , 就能夠經過這些標誌應該進行GC調優。
|
1
|
-XX:ParallelGCThreads=n:設置並行收集器收集時使用的CPU數。並行收集線程數。
|
1
2
3
4
5
6
7
|
接下來這些參數 是針對於 JMX 遠程監控的:
-Dcom.sun.management.jmxremote 啓用JMX遠程監控
-Dcom.sun.management.jmxremote.port=100861 使用端口100861
-Dcom.sun.management.jmxremote.authenticate=
false
遠程鏈接不須要密碼認證
-Dcom.sun.management.jmxremote.ssl=
false
不使用SSL
-Dcom.sun.management.jmxremote.access.
file
=$CATALINA_HOME
/conf/jmxremote
.access 使用指定的JMX賬號受權文件
-Dcom.sun.management.jmxremote.password.
file
=$CATALINA_HOME
/conf/jmxremote
.password 使用指定的JMX賬號文件
|
=============================================================
到這裏爲止 tomcat 針對jsvc 調優已經差很少了,下面啓動tomcat 測試:
1
2
3
|
# cp ./daemon.sh /etc/init.d/tomcat
# chmod +x /etc/init.d/tomcat
# /etc/init.d/tomcat start
|
1
2
3
|
# ps -ef |grep tomcat
root 12166 1 0 16:09 ? 00:00:00 jsvc.
exec
-java-home
/opt/jdk1
.7.0_60 -user tomcat -pidfile
/opt/apache-tomcat-7
.0.54
/logs/catalina-daemon
.pid -wait 10 -outfile
/opt/apache-tomcat-7
.0.54
/logs/catalina-daemon
.out -errfile &1 -classpath
/opt/apache-tomcat-7
.0.54
/bin/bootstrap
.jar:
/opt/apache-tomcat-7
.0.54
/bin/commons-daemon
.jar:
/opt/apache-tomcat-7
.0.54
/bin/tomcat-juli
.jar -Djava.util.logging.config.
file
=
/opt/apache-tomcat-7
.0.54
/conf/logging
.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -server -Xss512k -Xms2048M -Xmx2048M -XX:MaxPermSize=256M -XX:PermSize=128M -XX:NewSize=128M -XX:+CMSIncrementalMode -XX:CMSInitiatingOccupancyFraction=80 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:ParallelGCThreads=8 -Djavax.servlet.request.encoding=UTF-8 -Djavax.servlet.response.encoding=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia
/Shanghai
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10086 -Dcom.sun.management.jmxremote.ssl=
false
-Dcom.sun.management.jmxremote.authenticate=
false
-Djava.rmi.server.
hostname
=192.168.3.5 -Djava.endorsed.
dirs
= -Dcatalina.base=
/opt/apache-tomcat-7
.0.54 -Dcatalina.home=
/opt/apache-tomcat-7
.0.54 -Djava.io.tmpdir=
/opt/apache-tomcat-7
.0.54
/temp
org.apache.catalina.startup.Bootstrap
tomcat 12167 12166 34 16:09 ? 00:00:05 jsvc.
exec
-java-home
/opt/jdk1
.7.0_60 -user tomcat -pidfile
/opt/apache-tomcat-7
.0.54
/logs/catalina-daemon
.pid -wait 10 -outfile
/opt/apache-tomcat-7
.0.54
/logs/catalina-daemon
.out -errfile &1 -classpath
/opt/apache-tomcat-7
.0.54
/bin/bootstrap
.jar:
/opt/apache-tomcat-7
.0.54
/bin/commons-daemon
.jar:
/opt/apache-tomcat-7
.0.54
/bin/tomcat-juli
.jar -Djava.util.logging.config.
file
=
/opt/apache-tomcat-7
.0.54
/conf/logging
.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -server -Xss512k -Xms2048M -Xmx2048M -XX:MaxPermSize=256M -XX:PermSize=128M -XX:NewSize=128M -XX:+CMSIncrementalMode -XX:CMSInitiatingOccupancyFraction=80 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:ParallelGCThreads=8 -Djavax.servlet.request.encoding=UTF-8 -Djavax.servlet.response.encoding=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia
/Shanghai
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10086 -Dcom.sun.management.jmxremote.ssl=
false
-Dcom.sun.management.jmxremote.authenticate=
false
-Djava.rmi.server.
hostname
=192.168.3.5 -Djava.endorsed.
dirs
= -Dcatalina.base=
/opt/apache-tomcat-7
.0.54 -Dcatalina.home=
/opt/apache-tomcat-7
.0.54 -Djava.io.tmpdir=
/opt/apache-tomcat-7
.0.54
/temp
org.apache.catalina.startup.Bootstrap
|
1
2
3
4
5
6
7
8
|
若是你的系統開起了iptables的話,這裏須要開放針對jmx 和 tomcat 的端口:
vim
/etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 10086 -j ACCEPT
/etc/init
.d
/iptables
restart
重啓防火牆生效;
|
1
2
|
接下來打開瀏覽器測試tomcat是否已經work;
http:
//192
.168.3.5:8080
|
=============================================================
這裏咱們驗證一下JMX遠程監控,推薦使用VisualVM監控;
JDK中還藏着一個寶貝,它的名字叫作VisualVM。VisualVM是Sun的一個OpenJDK項目,其目的在於爲Java應用建立一個整套的問題解決工具;
1
2
|
官網主頁:
http:
//visualvm
.java.net/
|
步驟以下:
1)添加遠程主機:
2)添加jmx鏈接:
這裏須要注意格式:主機+端口 ,另外下面勾選 不要求SSL鏈接;
3)添加完成以後打開查看tomcat 資源使用狀況;
添加成功以後下面有個jmx的主機鏈接:
打開便可!
So Next ,Enjoy it!
下面是一個優化後的tomcat啓動腳本的範例,能夠放置在/etc/init.d/下 使用, start 、 stop等進行啓動 、關閉操做;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
#!/bin/sh
# 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.
#
# -----------------------------------------------------------------------------
# Scripts for tomcat based on jsvc
# -----------------------------------------------------------------------------
#
# resolve links - $0 may be a softlink
export
PATH=
/bin
:
/sbin
:
/usr/bin
:
/usr/sbin
export
JAVA_HOME=
/opt/jdk1
.7.0_60
export
JRE_HOME=
/opt/jdk1
.7.0_60
/jre
export
CATALINA_BASE=
/opt/apache-tomcat-7
.0.54
export
CATALINA_HOME=
/opt/apache-tomcat-7
.0.54
export
CATALINA_PID=$CATALINA_BASE
/logs/catalina-daemon
.pid
export
CATALINA_TMP=$CATALINA_BASE
/temp
export
TOMCAT_USER=tomcat
export
CATALINA_OPTS=
"-server -Xss512k -Xms2048M -Xmx2048M -XX:MaxPermSize=256M -XX:PermSize=128M -XX:NewSize=128M -XX:+CMSIncrementalMode -XX:CMSInitiatingOccupancyFraction=80 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:ParallelGCThreads=8 -Djavax.servlet.request.encoding=UTF-8 -Djavax.servlet.response.encoding=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=22222 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=192.168.3.5"
ARG0=
"$0"
while
[ -h
"$ARG0"
];
do
ls
=`
ls
-ld
"$ARG0"
`
link=`
expr
"$ls"
:
'.*-> \(.*\)$'
`
if
expr
"$link"
:
'/.*'
>
/dev/null
;
then
ARG0=
"$link"
else
ARG0=
"`dirname $ARG0`/$link"
fi
done
DIRNAME=
"`dirname $ARG0`"
PROGRAM=
"`basename $ARG0`"
while
[
".$1"
!= . ]
do
case
"$1"
in
--java-home )
JAVA_HOME=
"$2"
shift
;
shift
;
continue
;;
--catalina-home )
CATALINA_HOME=
"$2"
shift
;
shift
;
continue
;;
--catalina-base )
CATALINA_BASE=
"$2"
shift
;
shift
;
continue
;;
--catalina-pid )
CATALINA_PID=
"$2"
shift
;
shift
;
continue
;;
--tomcat-user )
TOMCAT_USER=
"$2"
shift
;
shift
;
continue
;;
* )
break
;;
esac
done
# OS specific support (must be 'true' or 'false').
cygwin=
false
;
darwin=
false
;
case
"`uname`"
in
CYGWIN*)
cygwin=
true
;;
Darwin*)
darwin=
true
;;
esac
# Use the maximum available, or set MAX_FD != -1 to use that
test
".$MAX_FD"
= . && MAX_FD=
"maximum"
# Setup parameters for running the jsvc
#
test
".$TOMCAT_USER"
= . && TOMCAT_USER=tomcat
# Set JAVA_HOME to working JDK or JRE
# JAVA_HOME=/opt/jdk-1.6.0.22
# If not set we'll try to guess the JAVA_HOME
# from java binary if on the PATH
#
if
[ -z
"$JAVA_HOME"
];
then
JAVA_BIN=
"`which java 2>/dev/null || type java 2>&1`"
test
-x
"$JAVA_BIN"
&& JAVA_HOME=
"`dirname $JAVA_BIN`"
test
".$JAVA_HOME"
!= . && JAVA_HOME=`
cd
"$JAVA_HOME/.."
>
/dev/null
;
pwd
`
else
JAVA_BIN=
"$JAVA_HOME/bin/java"
fi
# Only set CATALINA_HOME if not already set
test
".$CATALINA_HOME"
= . && CATALINA_HOME=`
cd
"$DIRNAME/.."
>
/dev/null
;
pwd
`
test
".$CATALINA_BASE"
= . && CATALINA_BASE=
"$CATALINA_HOME"
test
".$CATALINA_MAIN"
= . && CATALINA_MAIN=org.apache.catalina.startup.Bootstrap
# If not explicitly set, look for jsvc in CATALINA_BASE first then CATALINA_HOME
if
[ -z $JSVC ];
then
JSVC=
"$CATALINA_BASE/bin/jsvc"
if
[ ! -x $JSVC ];
then
JSVC=
"$CATALINA_HOME/bin/jsvc"
fi
fi
# Set the default service-start wait time if necessary
test
".$SERVICE_START_WAIT_TIME"
= . && SERVICE_START_WAIT_TIME=10
# Ensure that any user defined CLASSPATH variables are not used on startup,
# but allow them to be specified in setenv.sh, in rare case when it is needed.
CLASSPATH=
JAVA_OPTS=
if
[ -r
"$CATALINA_BASE/bin/setenv.sh"
];
then
.
"$CATALINA_BASE/bin/setenv.sh"
elif
[ -r
"$CATALINA_HOME/bin/setenv.sh"
];
then
.
"$CATALINA_HOME/bin/setenv.sh"
fi
# Add on extra jar files to CLASSPATH
test
".$CLASSPATH"
!= . && CLASSPATH=
"${CLASSPATH}:"
CLASSPATH=
"$CLASSPATH$CATALINA_HOME/bin/bootstrap.jar:$CATALINA_HOME/bin/commons-daemon.jar"
test
".$CATALINA_OUT"
= . && CATALINA_OUT=
"$CATALINA_BASE/logs/catalina-daemon.out"
test
".$CATALINA_TMP"
= . && CATALINA_TMP=
"$CATALINA_BASE/temp"
# Add tomcat-juli.jar to classpath
# tomcat-juli.jar can be over-ridden per instance
if
[ -r
"$CATALINA_BASE/bin/tomcat-juli.jar"
] ;
then
CLASSPATH=
"$CLASSPATH:$CATALINA_BASE/bin/tomcat-juli.jar"
else
CLASSPATH=
"$CLASSPATH:$CATALINA_HOME/bin/tomcat-juli.jar"
fi
# Set juli LogManager config file if it is present and an override has not been issued
if
[ -z
"$LOGGING_CONFIG"
];
then
if
[ -r
"$CATALINA_BASE/conf/logging.properties"
];
then
LOGGING_CONFIG=
"-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
else
# Bugzilla 45585
LOGGING_CONFIG=
"-Dnop"
fi
fi
test
".$LOGGING_MANAGER"
= . && LOGGING_MANAGER=
"-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
JAVA_OPTS=
"$JAVA_OPTS $LOGGING_MANAGER"
# Set -pidfile
test
".$CATALINA_PID"
= . && CATALINA_PID=
"$CATALINA_BASE/logs/catalina-daemon.pid"
# Increase the maximum file descriptors if we can
if
[
"$cygwin"
=
"false"
];
then
MAX_FD_LIMIT=`
ulimit
-H -n`
if
[
"$?"
-
eq
0 ];
then
# Darwin does not allow RLIMIT_INFINITY on file soft limit
if
[
"$darwin"
=
"true"
-a
"$MAX_FD_LIMIT"
=
"unlimited"
];
then
MAX_FD_LIMIT=`
/usr/sbin/sysctl
-n kern.maxfilesperproc`
fi
test
".$MAX_FD"
=
".maximum"
&& MAX_FD=
"$MAX_FD_LIMIT"
ulimit
-n $MAX_FD
if
[
"$?"
-
ne
0 ];
then
echo
"$PROGRAM: Could not set maximum file descriptor limit: $MAX_FD"
fi
else
echo
"$PROGRAM: Could not query system maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# ----- Execute The Requested Command -----------------------------------------
case
"$1"
in
run )
shift
"$JSVC"
$* \
$JSVC_OPTS \
-java-home
"$JAVA_HOME"
\
-pidfile
"$CATALINA_PID"
\
-wait 10 \
-nodetach \
-outfile
"&1"
\
-errfile
"&2"
\
-classpath
"$CLASSPATH"
\
"$LOGGING_CONFIG"
$JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.
dirs
=
"$JAVA_ENDORSED_DIRS"
\
-Dcatalina.base=
"$CATALINA_BASE"
\
-Dcatalina.home=
"$CATALINA_HOME"
\
-Djava.io.tmpdir=
"$CATALINA_TMP"
\
$CATALINA_MAIN
exit
$?
;;
start )
"$JSVC"
$JSVC_OPTS \
-java-home
"$JAVA_HOME"
\
-user $TOMCAT_USER \
-pidfile
"$CATALINA_PID"
\
-wait 10 \
-outfile
"$CATALINA_OUT"
\
-errfile
"&1"
\
-classpath
"$CLASSPATH"
\
"$LOGGING_CONFIG"
$JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.
dirs
=
"$JAVA_ENDORSED_DIRS"
\
-Dcatalina.base=
"$CATALINA_BASE"
\
-Dcatalina.home=
"$CATALINA_HOME"
\
-Djava.io.tmpdir=
"$CATALINA_TMP"
\
$CATALINA_MAIN
exit
$?
;;
stop )
"$JSVC"
$JSVC_OPTS \
-stop \
-pidfile
"$CATALINA_PID"
\
-classpath
"$CLASSPATH"
\
-Djava.endorsed.
dirs
=
"$JAVA_ENDORSED_DIRS"
\
-Dcatalina.base=
"$CATALINA_BASE"
\
-Dcatalina.home=
"$CATALINA_HOME"
\
-Djava.io.tmpdir=
"$CATALINA_TMP"
\
$CATALINA_MAIN
exit
$?
;;
version )
"$JSVC"
\
-java-home
"$JAVA_HOME"
\
-pidfile
"$CATALINA_PID"
\
-classpath
"$CLASSPATH"
\
-errfile
"&2"
\
-version \
-check \
$CATALINA_MAIN
if
[
"$?"
= 0 ];
then
"$JAVA_BIN"
\
-classpath
"$CATALINA_HOME/lib/catalina.jar"
\
org.apache.catalina.util.ServerInfo
fi
exit
$?
;;
* )
echo
"Unknown command: \`$1'"
echo
"Usage: $PROGRAM ( commands ... )"
echo
"commands:"
echo
" run Start Tomcat without detaching from console"
echo
" start Start Tomcat"
echo
" stop Stop Tomcat"
echo
" version What version of commons daemon and Tomcat"
echo
" are you running?"
exit
1
;;
esac
|
=============================================================
1
2
3
4
5
|
參考資料:
http:
//tomcat
.apache.org
/tomcat-7
.0-doc
/setup
.html
#Unix_daemon
http:
//tomcat
.apache.org
/tomcat-7
.0-doc
/RUNNING
.txt
https:
//svn
.apache.org
/repos/asf/tomcat/tc7
.0.x
/trunk/bin/daemon
.sh
http:
//ifeve
.com
/useful-jvm-flags-part-7-cms-collector/
|
=========================================================