码迷,mamicode.com
首页 > 系统相关 > 详细

Linux下tomcat安装与配置

时间:2015-09-08 16:52:46      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:tomcat安装

确保服务器上已经安装JDK。。。

1,下载地址:

    

http://tomcat.apache.org/download-60.cgi


2,解压

    mkdir /usr/local/tomcat

    cd /usr/local/tomcat

    tar -xvf apache### (下载的版本)

3,启动服务

    idongcd /usr/local/tomcat/bin

    ./statup.sh

4,开启防火墙,使外部能够访问

   (1) 开放8080端口

                -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

   (2)保存修改

        service iptables save

   (3)重启服务

        service iptables restart

        或修改配置文件

        vi /etc/sysconfig/iptables

 5,修改tomcat端口,

        编译 conf目录下的文件 service.xml 修改Connectors元素(tomcat默认端口是8080),            然后重启服务

        vi /usr/local/tomcat/server/conf/service.xml    

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443">

  6,验证是否安装成功:

   在浏览器输入http://172.16.8.94:8080 如下图则表示安装成功技术分享

7,部署网站首页

   最简洁的方法是将网站文件(包含 index.html/index.php等)直接放到Apache   目录的 /webapps/目录下(默认的configure文件里是配index.html/index/php)

  如果是其他语言的网站,如jsp/apsx,在configure文件里配置即可。

  接下来写一个简单的HTML文件,放到webapps目录下。

      <html><body>

        linux -html

      </body></html>

    打开浏览器,如下图则表示OK

技术分享

8,添加tomcat开机启动服务

    方法1

    (1)修改tomcat/bin/startup.sh

         

    export JAVA_HOME=/usr/java/jdk1.7.0_79

    export JAVA_BIN=$JAVA_HOME/bin

    export PATH=$PATH:$JAVA_HOME/bin

    export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

    export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

    export CATALINA_HOME=/usr/local/tomcat

 

    /usr/local/tomcat/Server/bin/catalina.sh start

     (2) 在/etc/rc.d/rc.local 中添加

        /usr/local/tomcat/Service/bin/catalina.sh start

    方法2:

        (1)将一下代码保存为tomcat文件,并让他成文可执行文件 chmod 755               tomcat

            

             #!/bin/bash

             #

             # kenny kenny.zhou@tom.com

             # /etc/rc.d/init.d/tomcat

             # init script for tomcat precesses

             #

             # processname: tomcat

             # description: tomcat is a j2se server

             # chkconfig: 2345 86 16

             # description:  Start up the Tomcat servlet engine.

            if [ -f /etc/init.d/functions ]; then

                     . /etc/init.d/functions

             elif [ -f /etc/rc.d/init.d/functions ]; then

                     . /etc/rc.d/init.d/functions

             else

                     echo -e "\atomcat: unable to locate functions lib. Cannot continue."

                     exit -1

             fi

             RETVAL=$?

             CATALINA_HOME="/usr/local/tomcat"

             case "$1" in

             start)

                     if [ -f $CATALINA_HOME/bin/startup.sh ];

                       then

                         echo $"Starting Tomcat"

                         $CATALINA_HOME/bin/startup.sh

                     Fi

              ;;

             stop)

                     if [ -f $CATALINA_HOME/bin/shutdown.sh ];

                       then

                         echo $"Stopping Tomcat"

                         $CATALINA_HOME/bin/shutdown.sh

                     fi

                     ;;

             *)

                     echo $"Usage: $0 {start|stop}"

                     exit 1

                     ;;

             esac

             exit $RETVAL

             #以上为tomcat开机启动的启动脚本代码

            (2)将tomcat文件复制到 /etc/init.d/目录下,

             运行 chkconfig --add tomcat(添加服务)

         (3)在tomcat/bin/catalina.sh 中添加一下内容

                
                        

                      export JAVA_HOME=/usr/java/default
                                            export CATALINA_HOME=/usr/local/tomcat
                                            export CATALINA_BASE=/usr/local/tomcat
                                            export CATALINA_TMPDIR=/usr/local/tomcat


                                            启动tomcat:service tomcat start

                                            启动tomcat:service tomcat stop 




                                

            

Linux下tomcat安装与配置

标签:tomcat安装

原文地址:http://karry3.blog.51cto.com/6323173/1692682

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!