linux下安装配置tomcat以及tomcat开机自启配置

Linux下Tomcat安装配置以及Windows不能连接服务器Tomcat解决方案

一、从官方网站上下载tomcat软件包。

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

点击左侧的 download的一个版本,我选择的是 tomcat7.0,选择一个后缀名为.tar.gz文件直接下载到本地。

二、通过工具SSH Secure 上传至linux服务器中,进行解压

解压tomcat压缩文件:

#tar zxvf apache-tomcat-7.0.53.tar.gz

将解压后的tomcat文件移动至/usr/local下

#mv apach-tomcat-6.0.16 /usr/local

三、配置tomcat环境;【之前我已经安装好JDK了】

编辑profie文件:

#vi /etc/profile

将下面文件copy到export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL后面;具体jdk路径根据你安装的位置来配置;

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

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

export PATH=$PATH:$JAVA_HOME/bin

export CATALINA_HOME=/usr/local/apache-tomcat-7.0.53

export CATALINA_BASE=/usr/local/apache-tomcat-7.0.53

保存退出,重新登录使之生效。

四、启动tomcat服务器

进入到/usr/local/apach-tomcat-6.0.20/bin目录

运行./startup.sh

启动成功会出现如下内容:

Using CATALINA_BASE:   /usr/local/apache-tomcat-7.0.53

Using CATALINA_HOME:   /usr/local/apache-tomcat-7.0.53

Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.53/temp

Using JRE_HOME:        /usr/java/jdk1.7.0_15

Using CLASSPATH:       /usr/local/apache-tomcat-7.0.53/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.53/bin/tomcat-juli.jar

Tomcat started.

五、测试是否启动成功

在linux浏览器中输入http://localhost:8080/就可以看到tomcat的log了

如果8080端口被占用,或者你只是想修改tomcat的端口,请参考如下文件,我直接copy上来了。【我这里是修改为9080端口】

<?xml version=‘1.0‘ encoding=‘utf-8‘?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="9005" shutdown="SHUTDOWN">

  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <Listener className="org.apache.catalina.core.JasperListener" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->

    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connector port="9080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the JSSE configuration, when using APR, the
         connector should be using the OpenSSL style configuration
         described in the APR documentation -->
    <!--
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="9009" protocol="AJP/1.3" redirectPort="8443" />

    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->        

      <!-- The request dumper valve dumps useful debugging information about
           the request and response data received and sent by Tomcat.
           Documentation at: /docs/config/valve.html -->
      <!--
      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
      -->

      <!-- This Realm uses the UserDatabase configured in the global JNDI
           resources under the key "UserDatabase".  Any edits
           that are performed against this UserDatabase are immediately
           available for use by the Realm.  -->
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>

      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
        -->

      </Host>
    </Engine>
  </Service>
</Server>

修改完后,启动tomcat,如果Windows访问Linux的Tomcat,显示无法连接,先查看tomcat下的logs日志文件,如果现实地址已被占用,则需重新修改,如果已经正常启动,说明防火墙未关闭。则只有修改linux防火墙的配置,打开8080端口。

1,在开启了防火墙时,做如下设置,开启相关端口,修改/etc/sysconfig/iptables 文件,添加以下内容:

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

2、直接关闭Linux防火墙。

在此说一下关于启动和关闭防火墙的命令

1) 重启后生效

开启: chkconfig iptables on

关闭: chkconfig iptables off

2) 即时生效,重启后失效

开启: service iptables start

关闭: service iptables stop

附文:linux下配置完tomcat后,要想tomcat开机自动启动的话,需要另外的配置!

方法一:【建议采用方法一,我试过了,成功了,方法二貌似没弄好,呵呵】

linux 下tomcat开机自启动

修改Tomcat/bin/startup.sh 为:

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

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

export PATH=$PATH:$JAVA_HOME/bin

export CATALINA_HOME=/usr/local/tomcat

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

在/etc/rc.d/rc.local中加入:

/usr/local/tomcat/bin/startup.sh

方法二:

1、把下面的代码保存为tomcat文件,并让它成为可执行文件 chmod 755 tomcat.

#!/bin/bash

#

# kenny [email protected]

# /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  //这句的意思是添加tomcat服务

3、在tomcat/bin/catalina.sh文件中加入以下语句:

export JAVA_HOME=/YOURPATH/tomcat/jdk

export CATALINA_HOME=/YOURPATH/tomcat

export CATALINA_BASE=/YOURPATH/tomcat

export CATALINA_TMPDIR=/YOURPATH/tomcat/temp

启动tomcat: service tomcat start

停止tomcat:  service tomcat stop

至此tomcat开机启动全部配置完毕,下次linux重启的时候就会自动启动tomcat了

linux下安装配置tomcat以及tomcat开机自启配置,布布扣,bubuko.com

时间: 2024-10-17 00:25:58

linux下安装配置tomcat以及tomcat开机自启配置的相关文章

Linux下安装tar.gz类型的jdk,并配置环境变量

近期因要学习一门技术,必须在Linux下运行,故开始学习如何使用Linux. 在安装jdk时出现了困难,环境变量配置不成功,花了一天时间才搞定,特分享出来,供大家参考. Linux下安装jdk,步骤如下 1:下载jdk包:本章使用的为后缀为tar.gz的文件(不需要安装),如jdk-7u67-linux-i586.tar.gz 2: 把jdk文件保存至Linux下目录:通过控制台,使用mkdir命令生成user/java目录,并把文件放入其下 3:解压tar.gz文件:通过控制台,进入user/

Linux下安装jdk与部署tomcat

首先使用ssh工具远程登入Linux服务器 命令行查看一下路径,下面的路径是安装jdk和tomcat时需要用到的,首先将jdk和tomcat的程序拷贝上去: cd /usr/local ls 安装jdk:这里使用的是jdk1.5的linux版,版本号:jdk-1_5_0-linux-i586-rpm.bin 下载地址(建议迅雷):http://www.javaresearch.org/members/jross/jdk/jdk-1_5_0-linux-i586-rpm.bin 在jdk-1_5_

Linux下安装PHP并在nginx服务器中进行配置的详细方法

先介绍一下使用的环境:centos 7.4, PHP 7.0 , nginx 1.12 Linux系统版本可以通过命令:lsb_release -a 查看. 现在开始步入正题了! 1.  首先查看一下nginx是否已经安装成功. Linux命令:find /|grep nginx.conf  如果安装完成,会显示出你的nginx配置文件所在的目录,我这里的目录是在  /etc/nginx目录下. 不会安装的小伙伴请自行百度,有时间的时候我也会写篇博客专门介绍nginx的安装及其配置等问题,在这里

linux 下安装 jdk tomcat 并配置

linux下安装TOMCAT与JDK 第1步:新建boss用户,用户名:boss,密码:boss 第2步:将安装用户路径设置成/app/boss [[email protected]]# useradd-d /app/boss -m boss [[email protected]]# passwdboss Changing password for user boss. New password:  boss passwd: all authentication tokens updated s

[Linux]Linux下安装和配置solr/tomcat/IK分词器 详细实例二.

为了更好的排版, 所以将IK分词器的安装重启了一篇博文,  大家可以接上solr的安装一同查看.[Linux]Linux下安装和配置solr/tomcat/IK分词器 详细实例一: http://www.cnblogs.com/wang-meng/p/5814798.html 8, 打开浏览器查看solr可视化界面 到了这里solr就配置好了, 可是我们的IK 分词器还没有配置呢, 如果不配IK分词器的话 它是怎样分词的呢? 我们就来先看一下:  每个字都分成了一个词, 这当然不是我们想要的结果

Linux 下安装tomcat +JDK环境部署

Linux下安装apache比较简单,安装apache的httpd就可以了. 但是如果要用tomcat的话,要稍微复杂一点,但如果按步骤来,也会很顺利地装好. 首先,tomcat安装之前,需要安装java环境,即需要下载java JDK,配置好后,再配置tomcat环境(两个的配置差不多).   1,下载java JDK. 到oracle甲骨文官网下载(要对应系统的版本,有解压版和安装版,推荐解压版),本次我使用的是安装版. 下载rpm安装文件后,通过 rpm -iv jdk-xxx.rpm 进

Linux下安装Tomcat服务器和部署Web应用

一.上传Tomcat服务器 二.安装Tomcat服务器 2.1.解压tomcat服务器压缩包 2.2.配置环境变量 tomcat服务器运行时是需要JDK支持的,所以必须配置好JDK用到的那些环境变量 编辑/etc下的profile文件,加上如下内容: 2.3.修改tomcat服务器的启动端口 修改将Tomcat服务器启动时使用的端口,例如改成9999 修改完server.xml文件之后,保存,退出. 三.Tomcat服务器启动和关闭 3.1.启动Tomcat服务器 进入tomcat服务器的bin

linux下安装tomcat和部署web应用

孤傲苍狼 只为成功找方法,不为失败找借口! Linux下安装Tomcat服务器和部署Web应用 一.上传Tomcat服务器 二.安装Tomcat服务器 2.1.解压tomcat服务器压缩包 2.2.配置环境变量 tomcat服务器运行时是需要JDK支持的,所以必须配置好JDK用到的那些环境变量 编辑/etc下的profile文件,加上如下内容: 2.3.修改tomcat服务器的启动端口 修改将Tomcat服务器启动时使用的端口,例如改成9999 修改完server.xml文件之后,保存,退出.

Linux 下设置java环境和tomcat安装

接下来提供几个比较有用的控制台命令给大家,方便使用的过程中,顺带学习Linux的操作. 命令: 新建文件夹:mkdir 新建的文件夹名 进入文件夹:cd 文件夹名 返回根目录:cd -c为断点续传下载到当前文件夹:wget -c 需要下载的链接 查看当前文件夹下所有内容:dir 分类高亮显示当前文件下所有内容:ls 删除:rm -rf 目录名字 重命名:mv 源文件 新文件名 移动文件/文件夹:mv 文件 文件夹 二.在线安装JAVA JDK环境 注意:JDK 可以在线安装,也可以下载好后,传到