`

ubuntu 16.04.1 上tomcat的安装与配置

阅读更多

主机:腾讯云服务器(ubuntu 16.04.1)系统

工具:xshell

 

步骤↓:

  1. 下载所需版本的Tomcat,Tomcat官网:http://tomcat.apache.org/,本文以Tomcat8为例:

     

     
    下载所选版本Tomcat中,core中的tar.gz包。
     
  2. 使用FTP工具上传tar.gz包到主机,本文使用xshell配套的xftp:
  3. 使用xshell登录主机,切换至Redis的管理用户,笔者使用的root用户:
    Shell代码 
    1. ubuntu@VM-202-164-ubuntu:~$ su  
    2. Password:   
    3. root@VM-202-164-ubuntu:/home/ubuntu#   
     说明:如果要使用aaa用户,su - aaa ,再输入密码就好了,或者直接使用aaa登录主机就可以了。
    Shell代码 
    1. root@VM-202-164-ubuntu:/home/ubuntu# su - aaa   #注意-和aaa之间有一个空格  
  4. 创建Tomcat存放目录,并进入:
    root@VM-202-164-ubuntu:/home/ubuntu# mkdir /usr/servers  
    root@VM-202-164-ubuntu:/home/ubuntu# cd /usr/servers  
    root@VM-202-164-ubuntu:/usr/servers# 
     注:笔者将Tomcat放在usr/severs中,依个人习惯而定。
  5. 拷贝tomcat包到目录:
    root@VM-202-164-ubuntu:/usr/servers# cp /home/ubuntu/apache-tomcat-8.5.23.tar.gz ./
     
  6. 解压tar.gz包:
    root@VM-202-164-ubuntu:/usr/servers# tar -xvf apache-tomcat-8.5.23.tar.gz
     
  7. 删除tomcat自带项目:
    root@VM-202-164-ubuntu:/usr/servers# rm -r apache-tomcat-8.5.23/webapps/*
     
  8. 给文件夹改个名:
    root@VM-202-164-ubuntu:/usr/servers# mv apache-tomcat-8.5.23 tomcat
     
  9. 简单配置一下:
    root@VM-202-164-ubuntu:/usr/servers# vi tomcat/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" />
      <!-- 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
             Java AJP  Connector: /docs/config/ajp.html
             APR (HTTP/AJP) Connector: /docs/apr.html
             Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
        --><!-- port:可设置tomcat所用端口,URIEncoding:tomcat处理数据所用编码格式,可用于解决操作中文乱码-->
        <Connector port="8080" protocol="HTTP/1.1" URIEncoding="UTF-8"
                   connectionTimeout="20000"
                   redirectPort="443" /><!-- 此处重定向为SSL所用端口 -->
        <!-- A "Connector" using the shared thread pool-->
        <!--
        <Connector executor="tomcatThreadPool"
                   port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" />
        -->
        <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
             This connector uses the NIO implementation. The default
             SSLImplementation will depend on the presence of the APR/native
             library and the useOpenSSL attribute of the
             AprLifecycleListener.
             Either JSSE or OpenSSL style configuration may be used regardless of
             the SSLImplementation selected. JSSE style configuration is used below.
        -->
       <!-- port:SSL端口,keystoreFile:指向SSL证书文件,keystorePass:SSL证书密码 -->
        <Connector port="443" protocol="HTTP/1.1" SSLEnabled="true" URIEncoding="UTF-8"
       	 maxThreads="150" scheme="https" secure="true"
       	 keystoreFile="conf/aaa.jks"
       	 keystorePass="123456"
       	 clientAuth="false" sslProtocol="TLS" />
        
        <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
             This connector uses the APR/native implementation which always uses
             OpenSSL for TLS.
             Either JSSE or OpenSSL style configuration may be used. OpenSSL style
             configuration is used below.
        -->
        <!--
        <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
                   maxThreads="150" SSLEnabled="true" >
            <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
            <SSLHostConfig>
                <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                             certificateFile="conf/localhost-rsa-cert.pem"
                             certificateChainFile="conf/localhost-rsa-chain.pem"
                             type="RSA" />
            </SSLHostConfig>
        </Connector>
        -->
    
        <!-- 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>      
          <!-- <Context docBase="test" path="/test" /></Host> -->
          <!--部署web项目的一种方法:1、直接将项目丢进webapps目录中,2、用此配置,path指向项目根目录-->
    
        </Engine>
      </Service>
    </Server>
    
     
  10. 启动tomcat:
    root@VM-202-164-ubuntu:/home/ubuntu# /usr/servers/tomcat/bin/startup.sh
     
    root@VM-202-164-ubuntu:/home/ubuntu# ps -aux|grep tomcat|grep -v grep
     说明:ps -aux|grep tomcat|grep -v grep命令可查看已经启动的tomcat进程,如下:
    root@VM-202-164-ubuntu:/usr/servers/tomcat8-server1/bin# ps -aux|grep tomcat|grep -v grep
    root     32087  7.5  6.0 2129240 53780 pts/1   Sl   23:26   0:01 /usr/servers/jdk1.8.0_151//bin/java -Djava.util.logging.config.file=/usr/servers/tomcat8-server1/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -classpath /usr/servers/tomcat8-server1/bin/bootstrap.jar:/usr/servers/tomcat8-server1/bin/tomcat-juli.jar -Dcatalina.base=/usr/servers/tomcat8-server1 -Dcatalina.home=/usr/servers/tomcat8-server1 -Djava.io.tmpdir=/usr/servers/tomcat8-server1/temp org.apache.catalina.startup.Bootstrap start
     
  11. 停止tomcat:
    root@VM-202-164-ubuntu:/home/ubuntu# /usr/servers/tomcat/bin/shutdown.sh
     
    root@VM-202-164-ubuntu:/home/ubuntu# ps -aux|grep tomcat|grep -v grep
     说明:执行关闭脚本,看看是否还有tomcat进程。
  12. 最后删掉tar.gz包,这个文件已经解压过了,留之无用,删了就好。
    root@VM-202-164-ubuntu:~# rm /usr/servers/apache-tomcat-8.5.23.tar.gz
     

 

搞定!酷

  • 大小: 47.2 KB
  • 大小: 40.7 KB
  • 大小: 103 KB
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics