preface

This article describes the basic installation and configuration of Tomcat, and shows how to install Tomcat on different platforms (Windows, Linux, and MacOS). In addition, the Tomcat version file used in this document can be downloaded from the web disk link at the end of this document or from the official website. In addition, there is a brief introduction to port configuration for Tomcat and how to configure HTTPS at the end.

Windows

On Windows, I installed apache-Tomcat-8.5.69-Windows-x64, and used the installation method of compressed package (see the resource link at the end of this article for the compressed package). First, I decompressed the compressed package to the specified folder (you can choose another location here, generally do not recommend the system disk, there may be permission problems. Because OF the virtual machine environment I used for testing, it was arbitrary) :

In the runTomcatBefore you install it, ensure that it has been installed locallyJavaEnvironment and has been configuredJAVA_HOMEEnvironment variables, aboutJDKFor configuration, see this article:JDK Installation and Configuration Summary (Multi-platform), click after the installation is completebinIn the directorystartup.batTo run:

Double click to see a flash black window, and then we can access the test from the browser on the machine, before we look at the IP address:

Then access the test in a browser (Tomcat starts port 8080 by default) :

Linux

On Linux, I installed apache-tomcat-8.5.69 and used the installation method of compressed package (see the resource link at the end of this article). First, I decompressed the compressed package to the specified folder:

Also make sure your JAVA environment has been configured (see the JDK Installation and Configuration Review (multi-platform)) :

Then run the startup.sh file in the bin directory:

Then run the following command to open port 8080:

systemctl start firewalld
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
Copy the code

Then check the local IP:

Then test it natively in the browser:

MacOS

Apache-tomcat-8.5.69 is installed on MacOS and Linux, and the overall steps are similar. First, decompress:

Also make sure your JAVA environment has been configured (see the JDK Installation and Configuration Review (multi-platform)) :

Then run the startup.sh file in the bin directory:

Then check the local IP:

Then use the browser to test the connection on your native computer:

Port configuration

The default Tomcat startup port is 8080, which can be changed by using conf/server.xml in the Tomcat installation directory:

Then test it locally:

To run on multiple ports at the same time, simply configure multiple Connectors:

Then test it:

In addition, you can configure multiple ports for multiple applications by first making a copy of the Webapps folder in the Tomcat installation path and changing the title of ROOT/index.jsp:

Then modify the configuration in config/server.xml:

<! -- Copy the contents of the Service label and configure ports 8001 and 8002 to correspond to WebApps, and ports 8003 and 8004 to correspond to WebAppS1 -->
<Service name="Catalina">
    <Connector port="8001" protocol="HTTP / 1.1"
               connectionTimeout="20000"
               redirectPort="8443" />			   
	<Connector port="8002" protocol="HTTP / 1.1"
               connectionTimeout="20000"
               redirectPort="8443" />			    
    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">        
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">      
        <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>
  <Service name="Catalina">
    <Connector port="8003" protocol="HTTP / 1.1"
               connectionTimeout="20000"
               redirectPort="8443" />			   
	<Connector port="8004" protocol="HTTP / 1.1"
               connectionTimeout="20000"
               redirectPort="8443" />			    
    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">        
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>
      <Host name="localhost"  appBase="webapps1"
            unpackWARs="true" autoDeploy="true">      
        <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>
Copy the code

Then test it locally:

Configure HTTPS

This section describes how to use KeyTool to generate a free test certificate by first executing the following command (make sure your JAVA environment is configured) :

Windows:
"%JAVA_HOME%\bin\keytool" -genkey -alias tomcat -keyalg RSA

Unix:
$JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA
Copy the code

I will use 123456 here, and then according to the prompt input information can be, can also all the way to enter the default value, after all can be found in the specified directory generated file:

Then add the following configuration to a Service tag in conf/server.xml in the Tomcat installation directory:

<! -- keystoreFile value corresponds to the location where the.keystore file is generated. KeystorePass Corresponds to the password set when the.keystore file is generated. -->
<Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" 
			   keystoreFile="C:/Users/butterfly/.keystore" keystorePass="123456"/>
Copy the code

Then test the connection locally:

Links to resources

Link: pan.baidu.com/s/1gZ9UireI… Extract code: 9VRr

The Windows website links: mirror-hk.koddos.net/apache/tomc…

Linux & MAC website links: mirror-hk.koddos.net/apache/tomc…