1.jdk安装
tar xf jdk-8u212-linux-x64.tar.gz
ln -s /data/jdk1.8.0_212 /data/jdk
vim /etc/profile
----------------------------------------------------------------------------------------------
export HISTTIMEFORMAT="%F %T `whoami` "
export exportLANG="en_US.utf-8"
export JAVA_HOME=/data/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
ln -sv /data/jdk/bin/java /usr/bin/
java -version
2.tomcat安装
tar xf apache-tomcat-8.5.39.tar.gz
ln -sv /data/apache-tomcat-8.5.39 /data/tomcat
#创建账户
useradd -m www -u 2019 -s /bin/bash
#tomcat_appdir 保存web压缩包;tomcat_webdir保存解压后的web目录
mkdir /data/tomcat/{tomcat_appdir,tomcat_webdir}
mkdir /data/tomcat/tomcat_webdir/myapp
echo 192.168.47.106 > /data/tomcat/tomcat_webdir/myapp/index.html
#修改配置文件
vim /data/apache-tomcat-8.5.39/conf/server.xml
----------------------------------------------------------------------
<Host name="localhost" appBase="/data/tomcat/tomcat_webdir"
unpackWARs="true" autoDeploy="true">
----------------------------------------------------------------------
#启动
/data/tomcat/bin/catalina.sh start
访问:http://192.168.47.106:8080/myapp/
普通用户访问
chown www.www /data/tomcat/ /data/apache-tomcat-8.5.39 -R
su - www
/data/tomcat/bin/catalina.sh start
#日志:
tail -f /data/tomcat/logs/catalina.out
tomcat启动脚本
tomcat
JDK_HOME=/data/jdk1.8.0_212
CATALINA_HOME=/data/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进程,请稍等10秒钟!"
sleep 10
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
chmod a+x tomcat
cp tomcat /etc/init.d/
/etc/init.d/tomcat start
passwd www
ssh www@192.168.1.107 "/etc/init.d/tomcat start"
ssh www@192.168.1.107 "/etc/init.d/tomcat stop"