暗中观察

CentOS 安装 tomcat
1.下载tomcat地址:http://tomcat.apache.org/ wget http://mirro...
扫描右侧二维码阅读全文
10
2018/08

CentOS 安装 tomcat

1.下载tomcat

地址:http://tomcat.apache.org/

  wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.32/bin/apache-tomcat-8.5.32.tar.gz

2.安装tomcat

  tar -zxvf apache-tomcat-8.5.32.tar.gz && mv ./apache-tomcat-8.5.32 /usr/local/tomcat_web

3.配置环境变量及启动脚本

 vi /etc/init.d/tomcat_web

 #加入以下内容 : 
 
 #!/bin/bash
 export PATH=/bin:/usr/bin
 . /etc/init.d/functions
 JAVA_HOME=/usr/local/java/jdk1.8.0_171
 export JAVA_HOME
 
 U_UID=0
 TOMCAT="tomcat_web"
 
 USER=`echo $UID`
 
 if [ $USER == $U_UID ]
 then
 
 TOMCAT_START="/usr/local/tomcat_web/bin/catalina.sh"
 
 case "$1" in
 
 start)
 
         pidnum=`ps -ef | grep java | grep $TOMCAT | awk '{print $2}' | wc -l`
 
         if [ $pidnum -eq 0 ]
 
         then
                 sleep 2
                 action "Starting Tomcat..."  /bin/true
                 $TOMCAT_START $1>/dev/null 2>&1
 
         else
                 echo -e "\e[31mTomcat is running\e[0m"
         fi
         ;;
 
 stop)
 
         pidnum=`ps -ef | grep java | grep $TOMCAT | awk '{print $2}' | wc -l`
 
         if [ $pidnum -ne 0 ]
 
         then
                 sleep 2
                 action "Stoping Tomcat..." /bin/true
                 $TOMCAT_START $1 >/dev/null 2>&1
                 ps -ef | grep java | grep $TOMCAT | awk '{print $2}' | xargs kill -9
 
         else 
                 echo -e "\e[31mTomcat is stopped\e[0m"
         fi
         ;;
 
 restart)
 
         pidnum=`ps -ef | grep java|grep $TOMCAT| awk '{print $2}' | wc -l`
         if [ $pidnum -eq 0 ]
         then
                 sleep 2
                 action "Retart Tomcat..."  /bin/true
                 $TOMCAT_START start >/dev/null 2>&1
 
         else
                 sleep 2
                 ps -ef | grep java |grep $TOMCAT | awk '{print $2}' | xargs kill -9
                 action "Restart Tomcat..." /bin/true
                 $TOMCAT_START start >/dev/null 2>&1
 
         fi
         ;;
 *)
         echo
         echo -e "\e[31m You enter a wrong Parameter,please try again\e[0m"
         echo
         ;;
 esac
 else
         echo
         echo -e "       Please use 'sudo service tomcat                 \e[31mstop\e[0m|\e[31mstart\e[0m|\e[31mrestart\e[0m'"
         echo
 fi
 exit 0

#保存并退出

4.运行

  service tomcat_web start|stop|restart

5.安装多个tomcat

需要修改端口,三个地方
tomcat-mult.png

最后修改:2018 年 08 月 14 日 06 : 05 AM
如果觉得我的文章对你有用,请随意赞赏

发表评论