centos7下安装tomcat

安装tomcat前需要先安装JDK,本文JDK安装目录:/java/jdk1.8.0_141

安装前先关闭防火墙:

[[email protected] ~]# systemctl stop firewalld.service
[[email protected] ~]# systemctl disable firewalld.service

步骤1:解压apache-tomcat-7.0.79.tar.gz到home目录

[[email protected] ~]# tar -zxvf apache-tomcat-7.0.79.tar.gz

步骤2:创建目录/tomcat并将解压后的文件apache-tomcat-7.0.79移动到该目录下

[[email protected] ~]# mkdir /tomcat
[[email protected] ~]# mv ~/apache-tomcat-7.0.79 /tomcat

步骤3:配置tomcat的catalina.sh文件(文件中添加红色部分)

[[email protected] bin]# vi /tomcat/apache-tomcat-7.0.79/bin/catalina.sh
#!/bin/sh

# 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.

# -----------------------------------------------------------------------------
# Control Script for the CATALINA Server
#
# Environment Variable Prerequisites
#
#   Do not set the variables in this script. Instead put them into a script
#   setenv.sh in CATALINA_BASE/bin to keep your customizations separate.
#
#   CATALINA_HOME   May point at your Catalina "build" directory.
#
#   CATALINA_BASE   (Optional) Base directory for resolving dynamic portions
#                   of a Catalina installation.  If not present, resolves to
#                   the same directory that CATALINA_HOME points to.
#
#   CATALINA_OUT    (Optional) Full path to a file where stdout and stderr
#                   will be redirected.
#                   Default is $CATALINA_BASE/logs/catalina.out
#
#   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
#                   "run" or "debug" command is executed.
#                   Include here and not in JAVA_OPTS all options, that should
#                   only be used by Tomcat itself, not by the stop process,
#                   the version command etc.
#                   Examples are heap size, GC logging, JMX ports etc.
#
#   CATALINA_TMPDIR (Optional) Directory path location of temporary directory
#                   the JVM should use (java.io.tmpdir).  Defaults to
#                   $CATALINA_BASE/temp.
#
#   JAVA_HOME       Must point at your Java Development Kit installation.
#                   Required to run the with the "debug" argument.
#
#   JRE_HOME        Must point at your Java Runtime installation.
#                   Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
#                   are both set, JRE_HOME is used.
#
#   JAVA_OPTS       (Optional) Java runtime options used when any command
#                   is executed.
#                   Include here and not in CATALINA_OPTS all options, that
#                   should be used by Tomcat and also by the stop process,
#                   the version command etc.
#                   Most options should go into CATALINA_OPTS.
#
#   JAVA_ENDORSED_DIRS (Optional) Lists of of colon separated directories
#                   containing some jars in order to allow replacement of APIs
#                   created outside of the JCP (i.e. DOM and SAX from W3C).
#                   It can also be used to update the XML parser implementation.
#                   Defaults to $CATALINA_HOME/endorsed.
#
#   JPDA_TRANSPORT  (Optional) JPDA transport used when the "jpda start"
#                   command is executed. The default is "dt_socket".
#
#   JPDA_ADDRESS    (Optional) Java runtime options used when the "jpda start"
#                   command is executed. The default is 8000.
#
#   JPDA_SUSPEND    (Optional) Java runtime options used when the "jpda start"
#                   command is executed. Specifies whether JVM should suspend
#                   execution immediately after startup. Default is "n".
#
#   JPDA_OPTS       (Optional) Java runtime options used when the "jpda start"
#                   command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
#                   and JPDA_SUSPEND are ignored. Thus, all required jpda
#                   options MUST be specified. The default is:
#
#                   -agentlib:jdwp=transport=$JPDA_TRANSPORT,
#                       address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND
#
#   JSSE_OPTS       (Optional) Java runtime options used to control the TLS
#                   implementation when JSSE is used. Default is:
#                   "-Djdk.tls.ephemeralDHKeySize=2048"
#
#   CATALINA_PID    (Optional) Path of the file which should contains the pid
#                   of the catalina startup java process, when start (fork) is
#                   used
#
#   LOGGING_CONFIG  (Optional) Override Tomcat‘s logging config file
#                   Example (all one line)
#                   LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
#
#   LOGGING_MANAGER (Optional) Override Tomcat‘s logging manager
#                   Example (all one line)
#                   LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
#
#   USE_NOHUP       (Optional) If set to the string true the start command will
#                   use nohup so that the Tomcat process will ignore any hangup
#                   signals. Default is "false" unless running on HP-UX in which
#                   case the default is "true"
# -----------------------------------------------------------------------------

# OS specific support.  $var _must_ be set to either true or false.

JAVA_OPTS="-Xms512m -Xmx1024m -Xss1024K -XX:PermSize=512m -XX:MaxPermSize=1024m"
export TOMCAT_HOME=/tomcat/apache-tomcat-7.0.79
export CATALINA_HOME=/tomcat/apache-tomcat-7.0.79
export JRE_HOME=/java/jdk1.8.0_141/jre
export JAVA_HOME=/java/jdk1.8.0_141

cygwin=false
darwin=false
os400=false
hpux=false
case "`uname`" in
CYGWIN*) cygwin=true;;
Darwin*) darwin=true;;
OS400*) os400=true;;
HP-UX*) hpux=true;;
esac

# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ]; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : ‘.*-> \(.*\)$‘`
  if expr "$link" : ‘/.*‘ > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

步骤4:修改tomcat端口参数(红色部分)

[[email protected] conf]# vi /tomcat/apache-tomcat-7.0.79/conf/server.xml
<?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="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--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" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- 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="8081" URIEncoding="UTF-8"  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 BIO implementation that requires the JSSE
         style configuration. When using the APR/native implementation, the
         OpenSSL style configuration is required as described in the APR/native
         documentation -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" 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"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- 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"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- 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
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

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

步骤4:启动和关闭tomcat

[[email protected] ~]# cd /tomcat/apache-tomcat-7.0.79/bin/
[[email protected] bin]#
[[email protected] bin]#
[[email protected] bin]#
[[email protected] bin]# ls
bootstrap.jar       commons-daemon-native.tar.gz  digest.sh         startup.bat           tool-wrapper.sh
catalina.bat        configtest.bat                setclasspath.bat  startup.sh            version.bat
catalina.sh         configtest.sh                 setclasspath.sh   tomcat-juli.jar       version.sh
catalina-tasks.xml  daemon.sh                     shutdown.bat      tomcat-native.tar.gz
commons-daemon.jar  digest.bat                    shutdown.sh       tool-wrapper.bat
[[email protected] bin]#
[[email protected] bin]#
[[email protected] bin]# ./startup.sh #启动tomcat
Using CATALINA_BASE:   /tomcat/apache-tomcat-7.0.79
Using CATALINA_HOME:   /tomcat/apache-tomcat-7.0.79
Using CATALINA_TMPDIR: /tomcat/apache-tomcat-7.0.79/temp
Using JRE_HOME:        /java/jdk1.8.0_141/jre
Using CLASSPATH:       /tomcat/apache-tomcat-7.0.79/bin/bootstrap.jar:/tomcat/apache-tomcat-7.0.79/bin/tomcat-juli.jar
Tomcat started.
[[email protected] bin]#
[[email protected] bin]#
[[email protected] bin]#
[[email protected] bin]# ./shutdown.sh #关闭tomcat
Using CATALINA_BASE:   /tomcat/apache-tomcat-7.0.79
Using CATALINA_HOME:   /tomcat/apache-tomcat-7.0.79
Using CATALINA_TMPDIR: /tomcat/apache-tomcat-7.0.79/temp
Using JRE_HOME:        /java/jdk1.8.0_141/jre
Using CLASSPATH:       /tomcat/apache-tomcat-7.0.79/bin/bootstrap.jar:/tomcat/apache-tomcat-7.0.79/bin/tomcat-juli.jar
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=512m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=1024m; support was removed in 8.0
[[email protected] bin]#
[[email protected] bin]# 

步骤5:查看tomcat运行日志

[[email protected] ~]#
[[email protected] ~]# cd /tomcat/apache-tomcat-7.0.79/logs/
[[email protected] logs]#
[[email protected] logs]#
[[email protected] logs]# ls
catalina.2017-07-31.log      host-manager.2017-08-01.log          localhost_access_log.2017-08-01.txt
catalina.2017-08-01.log      localhost.2017-07-31.log             manager.2017-07-31.log
catalina.out                 localhost.2017-08-01.log             manager.2017-08-01.log
host-manager.2017-07-31.log  localhost_access_log.2017-07-31.txt
[[email protected] logs]#
[[email protected] logs]#
[[email protected] logs]# tail -f catalina.out

至此,tomcat安装完毕~

时间: 2024-08-07 08:19:39

centos7下安装tomcat的相关文章

Centos7下安装tomcat(详解带图)。

Linux下安装Tomcat.1.首先需要安装他的依赖包jdk并配置Java.我们去浏览器搜索Java,并找到下载页面.然后运用wget进行下载如下图:注:需要把红色箭头标注的地方选中才可以进行复制链接.2.接下来把下载好的安装包解压.我是解压到了/data/server.3.接下来我们修改/etc下的配置文件(配置环境变量)vi /etc/profile然后 :wq退出并保存.保存之后通过source /etc/profile命令使修改的配置生效.然后java -version,检测版本,看是

Centos7下Nginx+Tomcat配置反向代理,使用memcached解决session一致性问题

一.session一致性问题 使用集群方案解决网站高并发问题时,就会部署多台应用服务器.当用户第一次通过客户端(如:浏览器)访问服务器时,服务器会创建对应的session, 使用Nginx反向代理,假如用户A第一次访问站点,被反向代理到服务器一处理,服务器一创建对应sessionA记录信息,用户A再次访问站点时,被反向代理到服务二处理, 而服务器二没有记录用户A的session信息,就会新创建sessionB,导致用户A之前操作丢失. 我们可以通过让多个服务器统一到同一个地方新建session和

centos7下安装Jdk8、Tomcat8小计

申请到一台 三 丰 云 免 费 主 机,安装centos操作系统,记录一下centos7下安装Jdk8.Tomcat8的操作 一.JDK1.8 环境搭建 1.上传文件解压 [[email protected] mysoft]# tar -zxvf jdk-8u161-linux-x64.tar.gz[[email protected] mysoft]# pwd/usr/local/mysoft[[email protected] mysoft]# mv jdk1.8.0_161 jdk1.8 2

Centos7下安装及配置PPTP VPN

说到VPN服务,我们大家都知道,VPN是虚拟专用网络(Virtual Private Network)的缩写,VPN有多种分类方式,包括PPTP.L2TP.IPSec等,本文配置的VPN服务器是采用PPTP协议的,PPTP是在PPP协议基础上开发的一种新的增强型安全协议.当然在windows上和linux上都可以部署服务,我们今天主要介绍一下在Centos7下安装及配置PPTP VPN. 因为PPTP是基于PPP协议基础上的,因此需要系统支持PPP,使用 rpm -qa ppp 检查是否安装了P

Centos7下安装及配置Zabbix3.0

说到Zabbix相信很多管理员都使用过,因为zabbix所提供的功能给广大管理员们及时得知自己所管理的服务器的服务状态,当然有很多软件服务(cacti.ngios等)都可以实现zabbix类似的功能,但是对于zabbix的功能相对更强大一点,具体就不细说了,今天我们主要介绍一下,Centos7下安装及配置Zabbix3.0的介绍,具体见下: 在安装服务器的时候我们需要注意一些问题:比如服务器的防火墙.selinux等都会影响到Zabbix的正常通信 环境介绍: OS:Centos7 Servic

CentOS-7下安装MySQL5.6.22

CentOS7下安装MySQL5.6.22(当前最新版本:2015-01-17) 转载请注明出处:jiq?钦's technical Blog 一  安装环境 (1)CentOS版本:CentOS-7 查看方法: [[email protected] 桌面]# cat /etc/redhat-release CentOS Linux release 7.0.1406 (Core) 来源:官网下载 下载地址:http://www.centos.org/ (2)MySQL版本:MySQL-5.6.2

centos7下安装mariadb

参考: http://www.cnblogs.com/Netsharp/p/5875474.html https://downloads.mariadb.org/mariadb/repositories/#mirror=neusoft&distro=CentOS&distro_release=centos7-amd64--centos7&version=10.1 RDS for MySQL 备份文件恢复到自建数据库 参考: https://help.aliyun.com/knowl

在Windows下安装Tomcat服务器

Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选服务器. 在Windows下安装Tomcat服务器的方式有两种,一种是直接安装,一种是绿色版,解压后就可以直接使用的 这篇博客为大家介绍第二种方式 首先从http://download.csdn.net/detail/u010105970/9493219中下载Tomcat服务器 第一步将Tomcat服务器的压缩包放在D:\dev

CentOS7下安装MySQL并配置远程连接

一.CentOS7下安装MySQL数据库 CentOS7默认的安装包里面已经没有 MySQL-Server安装包了,远程镜像中也没有了. 默认的是MariaDB (MySQL的一个分支,开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险 参照百度.开发基本相似). 参考文章:CentOS7 安装MySQL http://www.centoscn.com/mysql/2016/0315/6844.html 这里主要是安装MyS