Linux下Tomcat的安裝部署
一、 linux下安裝JDK1.6
JDK(Java Development Kit)是Sun Microsystems針對Java開發員的產品。自從Java推出以來,JDK已經成爲使用最廣泛的Java SDK。JDK 是整個Java的核心,包括了Java運行環境,Java工具和Java基礎的類庫。下面我們就來學習如何在CentOS系統下安裝 JDK。
1. CentOS系統創建安裝目錄
mkdir /usr/java
- 下載(oracle官網下載,需要登錄認證,無法直接下載,直接網站上下載上傳)
先去 www.oracle.com 網站尋找到 最新jdk1.6(JDK 6 Update 30)的下載地址:
http://download.oracle.com/otn-pub/java/jdk/6u30-b12/jdk-6u30-linux-i586-rpm.bin
在當前目錄下(/usr/java)執行:
wget http://download.oracle.com/otn-pub/java/jdk/6u30-b12/jdk-6u30-linux-i586-rpm.bin
可以喝杯水,慢慢等待…… - 在CentOS系統中安裝
下載完成之後執行命令,即可擁有對 .bin文件的執行權限
chmod 777 *.bin
然後輸入:
./*.bin
安裝jdk時會顯示出JDK的安裝許可協議,按空格翻頁,最後程序會問你是不是同意上面的協議,當然同意啦,輸入“yes”之後開始解壓JDK到當前目錄。此時屏幕上會顯示解壓的進度。
解壓完成後 /usr/java目錄下會新建一個名爲“jdk**”的目錄,至此我們已經在CentOS系統下安裝好了JDK。
如果是*.i586.bin的話
chmod a+x *-i586.bin
./*-i586.bin
- 配置
安裝後之後需要配置環境變量。
vi /etc/profile
在最後加入以下幾行:
export JAVA_HOME=/usr/java/jdk1.6.0_30
export CLASSPATH=.:JAVAHOME/jre/lib/rt.jar: JAVA_HOME/lib/dt.jar:JAVAHOME/lib/tools.jarexportPATH= PATH:$JAVA_HOME/bin
注意,需要把jdk名字修改成您所下載的JDK當前版本。
設置好JDK,輸入 reboot 命令重啓即可。 - 刪除/卸載
用 rm -rf jdk1.6.0_30 命令即可刪除JDK,切記需要把配置文件的相關內容清空。
這樣就可以在CentOS系統下安裝 JDK了。
二、 Linux下安裝Tomcat
1.下載安裝tomcat(http://tomcat.apache.org/)
[root@master ~]# unzip apache-tomcat-6.0.30.zip
[root@master ~]# mv apache-tomcat-6.0.30/ /usr/local/
[root@master ~]cd /usr/local/
[root@master local]# ln -s /usr/local/apache-tomcat-6.0.30/ /usr/local/tomcat
[root@master local]# cd tomcat/bin/
[root@master bin]#ls
[root@master bin]#vim catalina.sh
添加以下內容:
CATALINA_HOME=/usr/local/apache-tomcat-6.0.30/
[root@master local]#chmod +x *.sh
2.啓動tomcat服務器
[root@master tomcat]# /usr/local/tomcat /bin/catalina.sh start
Using CATALINA_BASE: /usr/local/apache-tomcat-6.0.30/
Using CATALINA_HOME: /usr/local/apache-tomcat-6.0.30/
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-6.0.30//temp
Using JRE_HOME: /usr/local/jdk1.6.0_05
Using CLASSPATH: /usr/local/apache-tomcat-6.0.30//bin/bootstrap.jar
[root@master logs]# cd /usr/local/tomcat/logs/
[root@master logs]# tail -f catalina.out
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Jul 4, 2011 11:06:57 AM org.apache.coyote.http11.Http11Protocol pause
INFO: Pausing Coyote HTTP/1.1 on http-8080
Jul 4, 2011 11:06:58 AM org.apache.catalina.core.StandardService stop
INFO: Stopping service Catalina
Jul 4, 2011 11:06:58 AM org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8080
3.在瀏覽器中輸入
http://localhost:8080/(如果不是本機,則輸入對應的ip地址)
測試出現tomcat頁面則測試成功
ps:需要說明的是tomcat的默認測試頁面是放在webapps下面,這個其實是在server.xml文件中配置的,如下所示:
!/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.
—————————————————————————–
Start/Stop Script for the CATALINA Server
#
Environment Variable Prerequisites
#
CATALINA_HOME May point at your Catalina “build” directory.
#
CATALINA_BASE (Optional) Base directory for resolving dynamic portions
of a Catalina installation. If not present, resolves to
the same directory that CATALINA_HOME points to.
#
CATALINA_OUT (Optional) Full path to a file where stdout and stderr
will be redirected.
Default is $CATALINA_BASE/logs/catalina.out
#
CATALINA_OPTS (Optional) Java runtime options used when the “start”,
or “run” command is executed.
#
CATALINA_TMPDIR (Optional) Directory path location of temporary directory
the JVM should use (java.io.tmpdir). Defaults to
$CATALINA_BASE/temp.
#
JAVA_HOME Must point at your Java Development Kit installation.
Required to run the with the “debug” argument.
#
JRE_HOME Must point at your Java Development Kit installation.
Defaults to JAVA_HOME if empty.
#
JAVA_OPTS (Optional) Java runtime options used when the “start”,
“stop”, or “run” command is executed.
#
JAVA_ENDORSED_DIRS (Optional) Lists of of colon separated directories
containing some jars in order to allow replacement of APIs
created outside of the JCP (i.e. DOM and SAX from W3C).
It can also be used to update the XML parser implementation.
Defaults to $CATALINA_HOME/endorsed.
#
JPDA_TRANSPORT (Optional) JPDA transport used when the “jpda start”
command is executed. The default is “dt_socket”.
#
JPDA_ADDRESS (Optional) Java runtime options used when the “jpda start”
command is executed. The default is 8000.
#
JPDA_SUSPEND (Optional) Java runtime options used when the “jpda start”
command is executed. Specifies whether JVM should suspend
execution immediately after startup. Default is “n”.
#
JPDA_OPTS (Optional) Java runtime options used when the “jpda start”
command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
and JPDA_SUSPEND are ignored. Thus, all required jpda
options MUST be specified. The default is:
#
-agentlib:jdwp=transport=$JPDA_TRANSPORT,
address=JPDAADDRESS,server=y,suspend= JPDA_SUSPEND
#
CATALINA_PID (Optional) Path of the file which should contains the pid
of catalina startup java process, when start (fork) is used
#
LOGGING_CONFIG (Optional) Override Tomcat’s logging config file
Example (all one line)
LOGGING_CONFIG=”-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties”
#
LOGGING_MANAGER (Optional) Override Tomcat’s logging manager
Example (all one line)
LOGGING_MANAGER=”-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager”
#
Id:catalina.sh11460972011−07−1315:25:05Zmarkt
—————————————————————————–
export JRE_HOME=/usr/java/jdk1.6.0_38
export CATALINA_HOME=/home/xrltest1/tomcat
JAVA_OPTS=”-server -Xms2048m -Xmx2048m -Xmn768m -XX:PermSize=128m -XX:MaxPermSize=256m -XX:+UseParallelOldGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/xrltest1/tomcat/dumpfile/heap.bin -Xloggc:/home/xrltest1/tomcat/logs/gc.log”
作者添加的環境申明,如果一臺服務器中有多臺tomcat要使用不同版本的JVM,就可以直接這這邊添加JRE_HOME,不需要再/etc/profile.d中再配置JRE_HOME環境變量
OS specific support. $var must be set to either true or false.
此處語句判斷操作系統,同時對操作系統支持
os400是 IBM的AIX
darwin是MacOSX 操作環境的操作系統成份
Darwin是windows平臺上運行的類UNIX模擬環境
cygwin=false
os400=false
darwin=false
case “uname
” in
CYGWIN*) cygwin=true;;
OS400*) os400=true;;
Darwin*) darwin=true;;
esac
resolve links - $0 may be a softlink
此處的RPG抓取的是文件名,因爲可能是符號鏈接,所以下面循環語句的作用就是找到文件真實源路徑
PRG=”
ls=ls -ld "$PRG"
link=expr "$ls" : '.*-> \(.*\)$'
if expr “
else
PRG=dirname "$PRG"
/”$link”
fi
done
獲取腳本目錄真實目錄地址
Get standard environment variables
PRGDIR=dirname "$PRG"
Only set CATALINA_HOME if not already set
[ -z “$CATALINA_HOME” ] && CATALINA_HOME=cd "$PRGDIR/.." >/dev/null; pwd
Copy CATALINA_BASE from CATALINA_HOME if not already set
[ -z “CATALINA_BASE" ] && CATALINA_BASE=" CATALINA_HOME”
上面兩個語句判斷變量CATALINAHOME和 CATALINA_BASE是否存在,不存在則給予附值
CATALINA_BASE=”$CATALINA_HOME”
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=
test –r File 文件存在並且可讀
if [ -r “
elif [ -r “
fi
默認的tomcat的bin目錄下沒有這個文件,可以自行編寫setenv.sh這個文件設定環境變量
For Cygwin, ensure paths are in UNIX format before anything is touched
if cygpath --unix "$JAVA_HOME"
[ -n “$JRE_HOME” ] && JRE_HOME=cygpath --unix "$JRE_HOME"
[ -n “$CATALINA_HOME” ] && CATALINA_HOME=cygpath --unix "$CATALINA_HOME"
[ -n “$CATALINA_BASE” ] && CATALINA_BASE=cygpath --unix "$CATALINA_BASE"
[ -n “$CLASSPATH” ] && CLASSPATH=cygpath --path --unix "$CLASSPATH"
fi
For OS400
if os400; then
# Set job priority to standard for interactive (interactive - 6) by using
# the interactive priority - 6, the helper threads that respond to requests
# will be running at the same priority as interactive jobs.
COMMAND=’chgjob job(‘ JOBNAME’) runpty(6)’
system $COMMAND
# Enable multi threading
export QIBM_MULTI_THREADED=Y
fi
Get standard Java environment variables
if os400; then
# -r will Only work on the os400 if the files are:
# 1. owned by the user
# 2. owned by the PRIMARY group of the user
# this will not work if the user belongs in secondary groups
BASEDIR=” CATALINA_HOME”
. “CATALINA_HOME”/bin/setclasspath.sh
else
#這點一定要注意了,本腳本中沒有賦值卻突然冒出的變量
#都是在setclasspath.sh這個腳本中執行賦值的。比如 _RUNJAVA
#作者會在下一篇文章中,分析setclasspath.sh這個腳本
if [ -r “
. “
echo “This file is needed to run this program”
exit 1
fi
fi
以上是出現在其他操作環境下的腳本的可用性設置,因默認linux系統,上面就不做解讀了
if [ -z “
fi
將變量賦值
Add tomcat-juli.jar and bootstrap.jar to classpath
tomcat-juli.jar can be over-ridden per instance
if [ ! -z “
fi
雖然前面已將做出CATALINA_BASE=”$CATALINA_HOME”的語句
此處還是添加了判斷,增強了代碼的健壯性
添加變量$CLASSPATH的值
if [ “
else
CLASSPATH=”
fi
確認日誌路徑$CATALINA_OUT
這部分主要判斷這些變量是否預定義,有就以預定義爲主,沒有就設置爲默認格式
if [ -z “
fi
if [ -z “CATALINA_TMPDIR” ] ; then
# Define the java.io.tmpdir to use for Catalina
CATALINA_TMPDIR=” CATALINA_BASE”/temp
fi
Bugzilla 37848: When no TTY is available, don’t output to console
獲取當前shell運行的終端設備
have_tty=0
if [ “tty
” != “not a tty” ]; then
have_tty=1
fi
For Cygwin, switch paths to Windows format before running java
if $cygwin; then
JAVA_HOME=cygpath --absolute --windows "$JAVA_HOME"
JRE_HOME=cygpath --absolute --windows "$JRE_HOME"
CATALINA_HOME=cygpath --absolute --windows "$CATALINA_HOME"
CATALINA_BASE=cygpath --absolute --windows "$CATALINA_BASE"
CATALINA_TMPDIR=cygpath --absolute --windows "$CATALINA_TMPDIR"
CLASSPATH=cygpath --path --windows "$CLASSPATH"
JAVA_ENDORSED_DIRS=cygpath --path --windows "$JAVA_ENDORSED_DIRS"
fi
Set juli LogManager config file if it is present and an override has not been issued
確認$LOGGING_CONFIG變量
if [ -z “
LOGGING_CONFIG=”-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties”
else
# Bugzilla 45585
LOGGING_CONFIG=”-Dnop”
fi
fi
確認$LOGGING_MANAGER變量
if [ -z “
else
JAVA_OPTS=”
fi
—– Execute The Requested Command —————————————–
Bugzilla 37848: only output this if we have a TTY
正常情況下have_tty=1
if [
echo “Using CATALINA_HOME:
if [ “
else
echo “Using JRE_HOME:
#以下這句判斷設置的
if [ ! -z “
fi
fi
以上就是在啓動tomcat是輸出的環境變量信息
#
獲取第一次參數,jpda在後面的說明爲:jpda start Start Catalina under JPDA debugger
if [ “
JPDA_TRANSPORT=”dt_socket”
fi
if [ -z “
JPDA_SUSPEND=”n”
fi
if [ -z “
fi
CATALINA_OPTS=”
shift
fi
JPDA 模式是開啓遠程debug模式,端口就是JPDA_ADDRESS,生產環境用不到,不去深入
這個是debug模式
值得注意的是變量$_RUNJDB,居然在全文沒有找到賦值的語句。
從這邊開始就注意了,裏面的if-fi判斷很多,一定要先調好格式再看
if [ “
echo “Debug command not available on OS400”
exit 1
else
shift
if [ “
echo “Using Security Manager”
fi
shift
exec “
-Djava.endorsed.dirs=”
-sourcepath “
-Dcatalina.base=”
-Djava.io.tmpdir=”
else
exec “
-Djava.endorsed.dirs=”
-sourcepath “
-Dcatalina.home=”
org.apache.catalina.startup.Bootstrap “$@” start
fi
fi
#上面語句是適配AIX環境的,不做解讀
當參數是debug時
elif [ “$1” = “run” ]; then
shift
當使用shift命令之後,原來的2會變成 1,並且原有的1變得不可用,通過 #命令獲得的參數個數也會少1
這樣就可以使用$1獲取第二個參數
if [ “
echo “Using Security Manager”
fi
shift
作廢掉前兩個參數
exec “
-Djava.endorsed.dirs=”
-Djava.security.manager \
-Djava.security.policy==”
-Dcatalina.home=”
org.apache.catalina.startup.Bootstrap “
-Dcatalina.home=”
org.apache.catalina.startup.Bootstrap “$@” start
這個命令其實就是java命令,指定org.apache.catalina.startup.Bootstrap 這個class文件,$@和”start”作用類似於傳參到前面的安格class裏
fi
正式進入啓動的過程啦~
elif [ “
#test –z 字符串 字符串的長度爲零 ,判斷這個變量或者文件內有數據
if [ -f “$CATALINA_PID” ]; then
-f 該『文件名』是否爲文件(file)?(常用)
if [ -s “CATALINA_PID” ]; then
#-s 偵測該文件名是否爲『非空白文件』?
echo “Existing PID file found during start.”
if [ -r “ CATALINA_PID” ]; then
-r 偵測該文件名是否具有『可讀』的屬性?
以上if語句主要判斷這個$CATALINA_PID,是否能正常可讀
PID=cat "$CATALINA_PID"
ps -p PID >/dev/null 2>&1
if [ ? -eq 0 ] ; then
#判斷這個PID現在有沒有被佔用,有就輸出這個tomcat依舊在運行,退出
#上面這段語句功能非常好,可以判斷出這個PID是否還在運行
echo “Tomcat appears to still be running with PID
刪除了這個$CATALINA_PID文件
if [
#-w 偵測該文件名是否具有『可寫』的屬性?
cat /dev/null > “$CATALINA_PID”
清空$CATALINA_PID文件
else
#如果不具有可寫權限,則輸出信息,退出
echo “Unable to remove or clear stale PID file. Start aborted.”
exit 1
fi
fi
fi
else
如果”$CATALINA_PID”沒有可讀權限,任然輸出信息退出。
echo “Unable to read PID file. Start aborted.”
exit 1
fi
else
#”
強制刪除$CATALINA_PID文件
if [ $? != 0 ]; then
成功則進行判斷,沒有讀權限則退出腳本
if [ ! -w “$CATALINA_PID” ]; then
echo “Unable to remove or write to empty PID file. Start aborted.”
exit 1
fi
fi
fi
fi
fi
這段語句,主要目的就是清空$CATALINA_PID文件,如果出現不可讀寫,則輸出信息退出
shift
#作廢掉前面參數,
#創建
#如果第二個參數是-security
if [
-Dcatalina.base=”
-Djava.io.tmpdir=”
“CATALINA_OUT” 2>&1 &
else
#我們平時執行啓動tomcat核心就是這一句了
#
“ _RUNJAVA" "LOGGINGCONFIG” JAVA_OPTSCATALINAOPTS −Djava.endorsed.dirs=” JAVA_ENDORSED_DIRS" -classpath "CLASSPATH” −Dcatalina.base=” CATALINA_BASE” \
-Dcatalina.home=”CATALINAHOME” −Djava.io.tmpdir=” CATALINA_TMPDIR” \
org.apache.catalina.startup.Bootstrap “@”start “ CATALINA_OUT” 2>&1 &
從&可以看出啓動的命令在後臺啓動
fi
if [ ! -z “$CATALINA_PID” ]; then
判斷CATALINA_PID如果不是空字符,則將Shell最後運行的後臺Process的PID 傳給$CATALINA_PID
echo
在使用命令運行進程至後臺時,可以使用$!抓取前面啓動運行在後臺進程的進程號
fi
fi
下面開始了tomcat停止模塊了
elif [ “$1” = “stop” ] ; then
shift
SLEEP=5
if [ ! -z “
if [
shift
fi
fi
#上面語句主要是判斷停止語句執行到此時,設定幾秒後再執行停止語句
#用來配合stop n
FORCE=0
if [ “$1” = “-force” ]; then
shift
FORCE=1
fi
#如果參數中使用了-force,則FORCE=1
if [ ! -z “CATALINA_PID” ]; then
# CATALINA_PID文件不是非空
if [ -f “
kill -0 cat "$CATALINA_PID"
>/dev/null 2>&1
kill -0 pid 不發送任何信號,但是系統會進行錯誤檢查。
if [ $? -gt 0 ]; then
echo "PID file found but no matching process was found. Stop aborted."
exit 1
fi
else
echo "PID file is empty and has been ignored."
fi
else
echo "\$CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop aborted."
exit 1
fi
fi
#以上腳本是進行停止命令檢錯的,如果可能停止不了,則可以直接報錯
“
-Djava.endorsed.dirs=”
-Dcatalina.base=”
-Djava.io.tmpdir=”
這個就是停止腳本的核心命令了
if [ ! -z “
while [ $SLEEP -ge 0 ]; do
kill -0 cat "$CATALINA_PID"
>/dev/null 2>&1
if [
if [
cat /dev/null > “
sleep 1
fi
if [
echo “Tomcat did not stop in time. PID file was not removed.”
fi
fi
SLEEP=expr $SLEEP - 1
done
fi
fi
#上段語句主要是清空$CATALINA_PID
#值得注意的是,生產環境偶爾不加-force選項,tomcat有時無法停止下來
#如果參數帶”-force” ,則強制kill掉tomcat
if [
echo “Kill failed: $CATALINA_PID not set”
else
if [ -f “$CATALINA_PID” ]; then
PID=cat "$CATALINA_PID"
echo “Killing Tomcat with the PID:
強制執行的核心命令
rm -f "$CATALINA_PID" >/dev/null 2>&1
if [ $? != 0 ]; then
echo "Tomcat was killed but the PID file could not be removed."
fi
fi
fi
fi
查看版本參數
elif [ “
-classpath “
echo ” debug Start Catalina in a debugger (not available on OS400)”
echo ” debug -security Debug Catalina with a security manager (not available on OS400)”
else
echo ” debug Start Catalina in a debugger”
echo ” debug -security Debug Catalina with a security manager”
fi
echo ” jpda start Start Catalina under JPDA debugger”
echo ” run Start Catalina in the current window”
echo ” run -security Start in the current window with security manager”
echo ” start Start Catalina in a separate window”
echo ” start -security Start in a separate window with security manager”
echo ” stop Stop Catalina, waiting up to 5 seconds for the process to end”
echo ” stop n Stop Catalina, waiting up to n seconds for the process to end”
echo ” stop -force Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running”
echo ” stop n -force Stop Catalina, wait up to n seconds and then use kill -KILL if still running”
echo ” version What version of tomcat are you running?”
echo “Note: Waiting for the process to end and use of the -force option require that $CATALINA_PID is defined”
exit 1
fi
http://www.2cto.com/os/201503/384698.html
四、 setclasspath.sh分析
#!/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.
—————————————————————————–
Set CLASSPATH and Java options
#
Id:setclasspath.sh7950372009−07−1710:52:16Zmarkt
—————————————————————————–
Make sure prerequisite environment variables are set
因爲setclasspath.sh腳本是被catalina.sh調用,所以可以繼承catalina.sh中的變量申明
if [ -z “
判斷用戶有沒有提前做JAVAHOME和 JRE_HOME全局變量聲明,如果都沒進行申明
# Bugzilla 37284 (reviewed).
if $darwin; then
#要理解這個判斷,先看下startup.sh和shutdown.sh就會明白
#這個是win仿真unix不用管下面兩個語句
if [ -d “/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home” ]; then
export JAVA_HOME=”/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home”
fi
else
#其他環境沒有申明,那麼系統自己想辦法找這兩個變量的路徑
JAVA_PATH=which java 2>/dev/null
此語句可以把java命令位置找出來
if [ "x$JAVA_PATH" != "x" ]; then
如果能找出java路徑,則可以定位到java命令的路徑,經過作者驗證不是java的裝路徑
所以通過此處就可以看出,老鳥們爲什麼都要自己指定這兩個變量了
JAVA_PATH=`dirname $JAVA_PATH 2>/dev/null`
JRE_HOME=`dirname $JAVA_PATH 2>/dev/null`
fi
if [ "x$JRE_HOME" = "x" ]; then
如果找不到java路徑,那麼就看有沒有/usr/bin/java這個執行文件,有的話就它了,沒有就算了
# XXX: Should we try other locations?
if [ -x /usr/bin/java ]; then
JRE_HOME=/usr
fi
fi
fi
if [ -z “
#再驗證一邊,有沒有這兩個變量,沒有不好意思,我不執行了,退出
#這個exit 1 不但是結束setclasspath.sh,會徹底退出catalina.sh腳本的
#對於在腳本中引用腳本的童鞋們,就需要注意了,小心使用exit。
echo “Neither the JAVA_HOME nor the JRE_HOME environment variable is defined”
echo “At least one of these environment variable is needed to run this program”
exit 1
fi
fi
if [ -z “
echo “JAVA_HOME should point to a JDK in order to run in debug mode.”
exit 1
fi
if [ -z “
fi
If we’re running under jdb, we need a full jdk.
if [ “
if [ ! -x “
echo “The JAVA_HOME environment variable is not defined correctly”
echo “This environment variable is needed to run this program”
echo “NB: JAVA_HOME should point to a JDK not a JRE”
exit 1
fi
else
if [ ! -x “
echo “The JAVA_HOME environment variable is not defined correctly”
echo “This environment variable is needed to run this program”
echo “NB: JAVA_HOME should point to a JDK not a JRE”
exit 1
fi
fi
fi
上段的代碼都是在確認JAVAHOME和 JRE_HOME變量的申明情況及後續的解決過程
if [ -z “$BASEDIR” ]; then
對”$BASEDIR變量的檢查,木有的話就退出
echo “The BASEDIR environment variable is not defined”
echo “This environment variable is needed to run this program”
exit 1
fi
if [ ! -x “$BASEDIR”/bin/setclasspath.sh ]; then
確認”$BASEDIR”/bin/setclasspath.sh有木有,木有還是退出
if $os400; then
# -x will Only work on the os400 if the files are:
# 1. owned by the user
# 2. owned by the PRIMARY group of the user
# this will not work if the user belongs in secondary groups
eval
eval不清楚嘛意思
else
echo “The BASEDIR environment variable is not defined correctly”
echo “This environment variable is needed to run this program”
exit 1
fi
fi
Don’t override the endorsed dir if the user has set it previously
這個是確認JAVA_ENDORSED_DIRS的位置
if [ -z “JAVA_ENDORSED_DIRS” ]; then
# Set the default -Djava.endorsed.dirs argument
JAVA_ENDORSED_DIRS=” BASEDIR”/endorsed
fi
OSX hack to CLASSPATH
JIKESPATH=
if [ uname -s
= “Darwin” ]; then
OSXHACK=”/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes”
if [ -d “
JIKESPATH=”
done
fi
fi
Set standard commands for invoking Java.
這句是響噹噹的重要,確定了$_RUNJAVA的值
_RUNJAVA=”
_RUNJDB=”$JAVA_HOME”/bin/jdb
fi
http://www.2cto.com/os/201503/384700.html
五、 centos6下,Tomcat6自啓動設置
1、修改start.sh文件
vim /home/wwwroot/tomcat_wiki/bin/startup.sh
在文件頭增加以下內容:
!/bin/sh
chkconfig: 2345 97 00
description:tomcat auto start
processname: tomcat
2、修改catalina.sh文件
vim /home/wwwroot/tomcat_wiki/bin/catalina.sh
增加以下內容:
export CATALINA_BASE=/home/wwwroot/tomcat_wiki
export CATALINA_HOME=/home/wwwroot/tomcat_wiki
export CATALINA_TMPDIR=/home/wwwroot/tomcat_wiki/temp
export JRE_HOME=/usr/local/jdk1.6.0_37
3、創建鏈接文件
ln –s /home/wwwroot/tomcat_wiki/bin/startup.sh /etc/init.d/tomcat
4、修改權限
chmod +x tomcat
5、添加啓動
chkconfig –add tomcat(add前是兩個減號)
chkconfig tomcat on
6、檢查
service tomcat start
或者reboot