Tomcat Service Deployment and Nginx Load Balancing Configuration

Introduction of Intermediate Key Products

At present, IBM's WebSphere and Oracle's Weblogic occupy a part of the market share of the java language Web sites. Both of these two software are commercial software, which are applied to the Web scenarios of large Internet companies due to their superior performance and high reliability.

Since version 5.x, Tomcat has been greatly improved in performance, open architecture and secondary development. Tomcat can be fully used in production environment with little visits. At present, most e-commerce websites for JSP technology development basically use Tomcat.

Intermediate key (software that provides JSP services) products:

  • RedHat  JBoss
  • Oracle   Tuxedo
  • Oracle   Weblogic
  • caucho Resin
  • IBM  WebSphere
  • JSP  Tomcat

Page:

  • html   Apache
  • php  LAMP  LNMP
  • jsp   Tomcat

Introduction of Tomcat Software

Tomcat is a core project of Apache Software Foundation's Jakarta project, developed by Apache, Sun and other companies and individuals. Tomcat was originally developed by Sun's software architect James Duncan Davidson. Later, he turned it into an open source project and Sun contributed to the Apache Software Foundation.

3. Tomcat application scenario

Tomcat server is a free open source web application server, which belongs to lightweight application server. It is the first choice for developing and debugging JSP pages when there are not many small and medium-sized systems and users accessing concurrently. Tomcat can also handle static HTML pages, but its capability is not as good as Apache or Nginx, so Tomcat is the best choice for developing and debugging JSP pages. Usually as a servlet and JSP container, running separately in the back end.

IV. Brief Introduction of JDK Software

 

Before Tomcat is installed, JDK must be installed. JDK is Java Development Kit. It is a free software development kit of Java language provided by SUN company. It contains Java Virtual Machine (JVM). The compiled Java source program can produce Java bytecode. Once JDK is installed, these words can be interpreted by JVM. Save the code file, thus guaranteeing the cross-platform nature of Java.

In terms of platform compatibility, JDK is a java virtual machine that interprets bytecode files and implements corresponding functions by calling API of operating system. It is closely related to the number of operating system bits. Therefore, there are different versions of JDK. Tomcat also has the above characteristics. By default, JDK has been installed in CentOS 7 system.

Java components in JDK:

  • javac: Compiler that compiles source code with a suffix of. java into bytecode with a suffix of ". class"

  • java: Running tool, running. class bytecode
  • jar: Packaging tool that packages related class files into one file
  • javadoc: Document generator that extracts documents from source comments that match specifications
  • jdb debugger: debugging tool
  • jps: Displays the process status of the current java program running
  • javap: Decompiler
  • Applet viewer: Tool to run and debug applet programs without using a browser
  • javah: Generate C header files and C source files from Java classes. These files provide connection gluing to enable Java and C code to interact.
  • javaws: Run the JNLP program
  • extcheck: a tool for detecting jar package conflicts
  • apt: Annotation Processing Tool
  • jhat: java heap analysis tool
  • jstack: stack tracer
  • jstat: JVM Detection and Statistics Tool
  • jstatd: jstat daemon
  • jinfo: Get configuration information for running or crashing java programs
  • jmap: Get memory mapping information for java processes
  • idlj: IDL-to-Java compiler. Converting IDL Language into java Files
  • policytool: A GUI Policy File Creation and Management Tool
  • jrunscript: command line script run

5. Install Tomcat (host 192.168.200.112)

1. Closing firewalls and security mechanisms

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0

2. Check whether JDK is installed

[root@localhost ~]# java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

3. Unload JDK installed in rpm mode

Method 1

[root@localhost ~]# rpm -qa | grep -i openjdk
java-1.8.0-openjdk-headless-1.8.0.222.b10-0.el7_6.x86_64
java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64

[root@localhost ~]# rpm -e java-1.8.0-openjdk --nodeps   //There is a dependency relationship, after which the dependency relationship is relieved. --nodeps
[root@localhost ~]# rpm -e java-1.8.0-openjdk-headless
[root@localhost ~]# rpm -qa | grep -i openjdk

Method two

[root@localhost ~]# which java
/usr/bin/java

[root@localhost ~]# rm -rf /usr/bin/java

[root@localhost ~]# java -version
-bash: /usr/bin/java: No file or directory

4. Installing JDK

[root@localhost ~]# tar -xf jdk-8u191-linux-x64.tar.gz

[root@localhost ~]# mv jdk1.8.0_191/ /usr/local/java  //Move the decompressed package to the specified directory

[root@localhost ~]# /usr/local/java/bin/java -version  //At this point, only through the absolute path can you view java Version number information

[root@localhost ~]# vim /etc/profile  //modify

export JAVA_HOME=/usr/local/java  //Set up java Root directory

export PATH=$PATH:$JAVA_HOME/bin  //stay PATH Adding environment variables java Under the root directory bin Subdirectory

[root@localhost ~]# echo $PATH  //View when the modified script is not executed PATH variable
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin  
[root@localhost ~]# source /etc/profile  //Reset the script
[root@localhost ~]# echo $PATH  //Check it again.
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/java/bin

5. Tomcat Installation

[root@localhost ~]# tar -xf apache-tomcat-8.5.16.tar.gz

[root@localhost ~]# mv apache-tomcat-8.5.16 /usr/local/tomcat8

[root@localhost ~]# ls /usr/local/tomcat8/bin
bootstrap.jar setclasspath.sh
catalina.bat shutdown.bat
catalina.sh shutdown.sh
catalina-tasks.xml startup.bat
commons-daemon.jar startup.sh (Start file)
commons-daemon-native.tar.gz tomcat-juli.jar
configtest.bat tomcat-native.tar.gz
configtest.sh tool-wrapper.bat
daemon.sh tool-wrapper.sh
digest.bat version.bat
digest.sh version.sh
setclasspath.bat

//.bat  Windows Edition

//.sh   Linus Edition

6. Start up

[root@localhost ~]# /usr/local/tomcat8/bin/startup.sh 
Using CATALINA_BASE: /usr/local/tomcat8
Using CATALINA_HOME: /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME: /usr/local/java
Using CLASSPATH: /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
Tomcat started.

[root@localhost ~]# netstat -anpt | grep :8080
tcp6 0 0 :::8080 :::* LISTEN 3226/java

7, test

 

Setting up Tomcat Web Page Storage Location (host 192.168.200.112)

[root@localhost ~]# mkdir -p /web/webapp/     //Create a directory to store web pages
[root@localhost ~]# vim /web/webapp/index.jsp   //Add pages to store
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
        <head>
                <title>JSP test2 page</title>
        </head>
        <body>
                <% out.println("Welcome to test site,http://www.test2.com");%>
        </body>
</html>

[root@localhost ~]# vim /usr/local/tomcat8/conf/server.xml
<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        <Context docBase="/web/webapp" path="" reloadable="flash"></Context>

//Note: docBase="/web/webapp"     //web Application Document Reference Catalog         
         path=" "                         //set default"class"
         reloadable="flase"       //Set up monitoring"class"Whether change 

[root@localhost ~]# /usr/local/tomcat8/bin/shutdown.sh     //Turn off the machine.
Using CATALINA_BASE:   /usr/local/tomcat8
Using CATALINA_HOME:   /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME:        /usr/local/java
Using CLASSPATH:       /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
[root@localhost ~]# /usr/local/tomcat8/bin/startup.sh   //Reopen
Using CATALINA_BASE:   /usr/local/tomcat8
Using CATALINA_HOME:   /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME:        /usr/local/java
Using CLASSPATH:       /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
Tomcat started.

Testing


7. nginx load balancing configuration (host 192.168.200.111)

Make sure that nginx is installed, port 80 is open, modify the configuration file directly

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
upstream tomcat_server {
                server 192.168.200.112:8080 weight=1;
        }

     server {
        listen       80;
        server_name  localhost;
        location / {
                rewrite ^(.*)$ https://$host$1 permanent;
        }
        location ~ \.jsp$ {
                proxy_pass http://tomcat_server;
        }

        charset utf-8;

[root@localhost ~]# nginx -t 
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@localhost ~]# nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

[root@localhost ~]# nginx -s reload

test

Keywords: Linux Java Tomcat Nginx JDK

Added by friday_13 on Tue, 17 Sep 2019 15:43:06 +0300