Tomcat installation and deployment, security hardening optimization and reverse proxy application

1. Introduction to Tomcat

Tomcat is a core project in the Jakarta project of the Apache Software Foundation, developed jointly by Apache, Sun and some other companies and individuals.

Tomcat server is a free and open source web application server, which is a lightweight application server. It is widely used in small and medium-sized systems and occasions where there are not many concurrent access users. It is the first choice for developing and debugging JSP programs.

Tomcat, like Nginx, Apache (httpd), lighttpd and other web servers, has the function of processing HTML pages. In addition, it is also a Servlet and JSP container. The independent Servlet container is the default mode of Tomcat. However, Tomcat is not as good at handling static HTML as Nginx/Apache servers.

2. Tomcat installation, deployment and configuration

(1) Tomcat download and decompression

[root@linux-node1 ~]# ll apache-tomcat-8.0.50.tar.gz jdk-8u161-linux-x64.tar.gz
-rw-r - r-- 1 root root 9417189 3 月 17 11:27 apache-tomcat-8.0.50.tar.gz
-rw-r - r-- 1 root root 189756259 3 月 17 11:51 jdk-8u161-linux-x64.tar.gz
[root@linux-node1 ~]# mv apache-tomcat-8.0.50 /usr/local/
[root@linux-node1 ~]# ln -s /usr/local/apache-tomcat-8.0.50/ /usr/local/tomcat
[root@linux-node1 ~]# mv jdk1.8.0_161 /usr/local/
[root@linux-node1 ~]# ln -s /usr/local/jdk1.8.0_161 /usr/local/jdk

(2) jdk environment variable configuration

[root@linux-node1 ~]# vim /etc/profile
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
TOMCAT_HOME=/usr/local/tomcat
[root@linux-node1 ~]# source /etc/profile
[root@linux-node1 ~]# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

(3) Set tomcat to start as a normal user

[root@linux-node1 ~]# useradd -u 601 tomcat
[root@linux-node1 ~]# chown -R tomcat.tomcat /usr/local/jdk
[root@linux-node1 ~]# chown -R tomcat.tomcat /usr/local/tomcat
[root@linux-node1 ~]# su - tomcat
[tomcat@linux-node1 ~]$ /usr/local/tomcat/bin/startup.sh

(4) View the configuration of tomcat

[tomcat@linux-node1 logs]$ pwd
/usr/local/tomcat/logs
[tomcat@linux-node1 logs]$ ll
Total dosage 20
-rw-rw-r-- 1 tomcat tomcat 6449 3月  17 13:49 catalina.2018-03-17.log
-rw-rw-r-- 1 tomcat tomcat 6449 March 17 13:49 catalina.out ==> start log view, any tomcat startup related can be viewed
-rw-rw-r-- 1 tomcat tomcat    0 3月  17 13:49 host-manager.2018-03-17.log
-rw-rw-r-- 1 tomcat tomcat  465 3月  17 13:49 localhost.2018-03-17.log
-rw-rw-r-- 1 tomcat tomcat    0 3月  17 13:49 localhost_access_log.2018-03-17.txt
-rw-rw-r-- 1 tomcat tomcat    0 3月  17 13:49 manager.2018-03-17.log

[tomcat@linux-node1 conf]$ pwd
/usr/local/tomcat/conf
[tomcat@linux-node1 conf]$ vim server.xml #tomcat's main configuration file

    <Connector port="8080" protocol="HTTP/1.1" HTTP protocol connects tomcat, the connection timeout is 20000ms, and port 8443 is used for redirection
               connectionTimeout="20000"
               redirectPort="8443" />

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />    AJP协议连接tomcat

[root@linux-node1 tomcat]# tree -L 1
.
├── bin #→Scripts (.bat files and .sh files) to start, shut down Tomcat or other functions
├── conf #→XML and DTD files used to configure Tomcat
├── lib #→Stores JAR packages that can be accessed by web applications
├── LICENSE
├── logs #→Log files for Catalina and other web applications
├── NOTICE
├── RELEASE-NOTES
├── RUNNING.txt
├── temp #→temp file
├── webapps #→Web application root directory
└── work #→Used to generate .java and .class files for servlets compiled with JSP

7 directories, 4 files

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325887713&siteId=291194637