zoukankan      html  css  js  c++  java
  • linux应用之tomcat安装(centos)

     安装方式:源码安装 

    软件:apache-tomcat-7.0.29.tar.gz
    下载地址:http://tomcat.apache.org/download-70.cgi

    安装前提

    系统必须已经安装配置了JDK6+,如果不会安装请参考linux应用之jdk安装。

    安装tomcat

    将apache-tomcat-7.0.29.tar.gz文件上传到/usr/local中执行以下操作:

    [root@admin local]# cd /usr/local
    [root@admin local]# tar -zxv -f apache-tomcat-7.0.29.tar.gz         // 解压压缩包 
    [root@admin local]# rm -rf apache-tomcat-7.0.29.tar.gz   // 删除压缩包 
    [root@admin local]# mv apache-tomcat-7.0.29  tomcat

    启动Tomcat

    执行以下操作:

    [root@admin ~]#  /usr/local/tomcat/bin/startup.sh   //启动tomcat
    Using CATALINA_BASE:   /usr/local/tomcat
    Using CATALINA_HOME:   /usr/local/tomcat
    Using CATALINA_TMPDIR: /usr/local/tomcat/temp
    Using JRE_HOME:        /usr/java/jdk1.7.0/jre
    Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

    出现以上的打印信息说明已经成功启动。

    防火墙开放8080端口

    增加8080端口到防火墙配置中,执行以下操作:

    [root@admin ~]# vi + /etc/sysconfig/iptables
    #增加以下代码 
    -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

    重启防火墙

    [root@admin java]# service iptables restart

    检验Tomcat安装运行

    通过以下地址查看tomcat是否运行正常(根据自己的ip):

    http://202.116.147.88:8080/

    看到tomcat系统界面,恭喜,安装成功!如果看不到,可以修改tomcat的端口号(conf目录中的server.xml中),然后重启再试试。

    停止Tomcat

    [root@admin ~]#  /usr/local/tomcat/bin/shutdown.sh   //停止tomcat

    建立自己的启动脚本/etc/init.d/tomcat

    #vi /etc/init.d/tomcat

    #chmod 755 /etc/init.d/tomcat

    #chmod root:root /etc/init.d/tomcat

    #/etc/init.d/tomcat restart    (测试是否能正常工作)

    测试过程中发现用

    #service tomcat restart        启动时出现

    Neither the JAVA_HOME nor the JRE_HOME environment variable is defined

    问题。

    解决办法:在脚本中找到以下行,将自己的JAVA_HOME补全即可(也可以找到tomcat的catalina.sh文件,将JAVA_HOME和JRE_HOME添加到脚本开始位置)

      #Location of JAVA_HOME (bin files)  
        export JAVA_HOME= 

    具体启动脚本内容如下:

    #!/bin/bash  
        #  
        # chkconfig: - 95 15   
        # description: Tomcat start/stop/status script  
          
        #Location of JAVA_HOME (bin files)  
        export JAVA_HOME=  
          
        #Add Java binary files to PATH  
        export PATH=$JAVA_HOME/bin:$PATH  
          
        #CATALINA_HOME is the location of the configuration files of this instance of Tomcat  
        CATALINA_HOME=/usr/local/tomcat  
          
        #TOMCAT_USER is the default user of tomcat  
        TOMCAT_USER=www  
          
        #TOMCAT_USAGE is the message if this script is called without any options  
        TOMCAT_USAGE="Usage: $0 {e[00;32mstarte[00m|e[00;31mstope[00m|e[00;32mstatuse[00m|e[00;31mrestarte[00m}"  
          
        #SHUTDOWN_WAIT is wait time in seconds for java proccess to stop  
        SHUTDOWN_WAIT=20  
          
        tomcat_pid() {  
                echo `ps -ef | grep $CATALINA_HOME | grep -v grep | tr -s " "|cut -d" " -f2`  
        }  
          
        start() {  
          pid=$(tomcat_pid)  
          if [ -n "$pid" ];then  
            echo -e "e[00;31mTomcat is already running (pid: $pid)e[00m"  
          else  
            echo -e "e[00;32mStarting tomcate[00m"  
            if [ `user_exists $TOMCAT_USER` = "1" ];then  
              su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh  
            else  
              $CATALINA_HOME/bin/startup.sh  
            fi  
            status  
          fi  
          return 0  
        }  
          
        status(){  
          pid=$(tomcat_pid)  
          if [ -n "$pid" ];then  
            echo -e "e[00;32mTomcat is running with pid: $pide[00m"  
          else  
            echo -e "e[00;31mTomcat is not runninge[00m"  
          fi  
        }  
          
        stop() {  
          pid=$(tomcat_pid)  
          if [ -n "$pid" ];then  
            echo -e "e[00;31mStoping Tomcate[00m"  
                $CATALINA_HOME/bin/shutdown.sh  
          
            let kwait=$SHUTDOWN_WAIT  
            count=0;  
            until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]  
            do  
              echo -n -e "e[00;31mwaiting for processes to exite[00m
    ";  
              sleep 1  
              let count=$count+1;  
            done  
          
            if [ $count -gt $kwait ];then  
              echo -n -e "
    e[00;31mkilling processes which didn't stop after $SHUTDOWN_WAIT secondse[00m"  
              kill -9 $pid  
            fi  
          else  
            echo -e "e[00;31mTomcat is not runninge[00m"  
          fi  
          
          return 0  
        }  
          
        user_exists(){  
          if id -u $1 >/dev/null 2>&1; then  
            echo "1"  
          else  
            echo "0"  
          fi  
        }  
          
        case $1 in  
                start)  
                  start  
                ;;  
          
                stop)    
                  stop  
                ;;  
          
                restart)  
                  stop  
                  start  
                ;;  
          
                status)  
              status  
                ;;  
          
                *)  
              echo -e $TOMCAT_USAGE  
                ;;  
        esac      
        exit 0
  • 相关阅读:
    HTTP协议抓包分析
    cmd 中使用 tracert
    Ubuntu 搭建zabbix
    kerberos+ldap
    运行程序显示丢失“MSVCR100D.dll”
    熊猫烧香病毒样本分析
    Masm32sdk安装指南
    16位汇编实现三大基本排序
    逆向工程初步160个crackme-------3
    一个入门级CTF的Reverse
  • 原文地址:https://www.cnblogs.com/tankblog/p/6097011.html
Copyright © 2011-2022 走看看