您好,登錄后才能下訂單哦!
首先準備jdk環境
mkdir /apps && cd /apps
上傳jdk壓縮包到/apps內
tar xvf jdk-7u79-linux-x64.tar.gz
ln -sv /apps/jdk1.7.0_79 /apps/jdk
vim /etc/profile
export export LANG="en_US.utf-8"
export JAVA_HOME=/apps/jdk
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile && java -version
然后安裝tomcat
將tomcat壓縮包上傳到/apps內
tar xvf apache-tomcat-7.0.59.tar.gz
ln -sv /apps/apache-tomcat-7.0.59 /apps/tomcat
將tomcat啟動腳本上傳到/root內
cp /root/tomcat /etc/init.d/
chmod +x /etc/init.d/tomcat
/etc/init.d/tomcat start
http://192.168.1.17:8080
http://192.168.1.18:8080
單獨準備tomcat數據目錄,生產環境,數據和軟件不能放在一個目錄
mkdir -p /data/tomcat/webapps
vim /apps/tomcat/conf/server.xml
<Host name="localhost" appBase="/data/tomcat/webapps"
cd /data/tomcat/webapps/
mkdir web01 && cd web01
vim index.html
Tomcat!!!
/etc/init.d/tomcat restart
http://192.168.1.17:8080/web01
http://192.168.1.18:8080/web01
tomcat啟動腳本
#!/bin/bash
JDK_HOME=/apps/jdk
CATALINA_HOME=/apps/tomcat
export JDK_HOME CATALINA_HOME
source /etc/profile
#PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'`
#NUM=`ps -ef | grep -v grep | grep java | awk '{print $2}' | wc -l`
#case $1 in
start() {
echo "正在判斷服務狀態,請稍等!"
echo "請稍等3秒鐘"
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
if netstat -an | grep 8080 | grep LISTEN >/dev/null
then
echo "Tomcat已經正在運行了!"
else
echo "Tomcat沒有運行,1秒后啟動!"
echo 1;sleep 1
$CATALINA_HOME/bin/catalina.sh start
echo "Tomcat 已經成功啟動完成,5秒后判斷是否啟動成功"
echo "5";sleep 1;echo "4";sleep 1
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
if netstat -an | grep 8080 | grep LISTEN >/dev/null
then
PID=`ps -ef | grep tomcat | grep jdk | awk '{print $2}'`
NUM=`ps -ef | grep tomcat | grep jdk | awk '{print $2}' | wc -l`
echo "Tomcat 已經成功啟動${NUM} 個Tomcat進程!,PID為${PID}"
else
echo "Tomcat啟動失敗,請重新啟動!"
echo 1
fi
fi
}
stop() {
PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'`
NUM=`ps -ef | grep -v "color" | grep tomcat | awk '{print $2}' | wc
-l` echo "正在判斷服務狀態,請稍等3秒鐘!"
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
if netstat -an | grep 8080 | grep LISTEN >/dev/null
then
echo "Tomcat運行中,1秒后關閉!"
echo 1;sleep 1
echo "即將關閉Tomcat服務,請稍等!"
$CATALINA_HOME/bin/catalina.sh stop ;echo "已經執行關閉命令,正在檢查關閉了多少
Tomcat進程,請稍等30秒鐘!" sleep 27
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
pkill java && pkill tomcat
if netstat -an | grep 8080 | grep LISTEN >/dev/null;then
PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'`
NUM=`ps -ef | grep -v "color" | grep tomcat | awk '{print $2
}' | wc -l` kill -9 $PID ;echo "已成功關閉${NUM} 個tomcat進程"
else
echo "Tomcat 已經關閉完成!"
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
fi
else
echo "Tomcat 沒有運行"
echo 1
fi
if netstat -an | grep 8080 | grep LISTEN >/dev/null;then
PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'`
#NUM=`ps -ef | grep -v "color" | grep tomcat | awk '{print $2}' | wc -l`
echo "關閉失敗,即將強制刪除tomcat進程!"
sleep 2
pkill tomcat ;sleep 2
if netstat -an | grep 8080 | grep LISTEN >/dev/null;then
echo "強制關閉失敗,即將再次強制刪除tomcat進程!"
pkill java; sleep 2
fi
fi
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
esac
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。