Nginx Tomcat service deployment and load balancing configuration

A middle button Products

   Now, IBM's WebSphere, Oracle's Weblogic occupy part of the share java language Web site on the market, the two software is commercial software, due to the superior performance and high reliability for large-scale Internet company's Web scene .

   Since Tomcat version 5.x, its performance has been greatly improved properties, open architecture and secondary development, can be fully used in the traffic is not large production environment, most for JSP technology development e-commerce website basically applied Tomcat.

Middle button (JSP provide services software) products:

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

page:

  • html   Apache
  • php  LAMP  LNMP
  • jsp   Tomcat

Two, Tomcat Software Description

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

Three, Tomcat application scenarios

 Tomcat server is a free open source web application server, are lightweight application server, application in small and medium systems and concurrent user access is not a lot of occasions, the development and debugging JSP preferred pages, Tomcat can handle static HTML page but the capacity is less than Apache or Nginx , so Tomcat is usually used as a servlet and JSP container, runs alone at the back end.

Four, JDK Software Description

 

   Installing Tomcat Before you must first install the JDK , the JDK stands for Java Development Kit , is the SUN company provided free java language software development kit, which contains the Java Virtual Machine ( the JVM ), write good java source code compiled to produce java byte code, as long as the installation of the JDK , you can use the JVM interpret the bytecode files, thus ensuring the Java cross-platform nature.

Platform compatibility, the JDK as interpreted byte code file and in accordance with this call the operating system API to realize the corresponding functions java virtual machine, the operating system is closely related to the number of bits, so there are different kinds of versions, the Tomcat also has the above characteristics, CentOS 7 system has been installed by default JDK

JDK in the Java components:

  • javac: compiler, source code, called the suffix .java extension compiled into bytecode called ".class" is

  • java: the running tool, the running bytecode .class
  • jar: packaging tools, the packaging-related class files into one file
  • javadoc: documentation generator, extracted from the source document annotation, the annotation matching specification required
  • jdb debugger: debug tool
  • jps: Displays the current process java running state
  • javap: decompiler
  • appletviewer: run an applet and debugging tools, and do not need to use the browser
  • javah: C header files and generate C source files from a Java class. These files provide connection gluing, so Java and C code can interact.
  • javaws: Run JNLP program
  • extcheck: a tool for conflict detection jar package
  • apt: annotation processing tool
  • jhat: java heap analysis tool
  • jstack: stack trace program
  • jstat: JVM detect statistical tools
  • jstatd: jstat daemon
  • jinfo: java program running or obtain configuration information collapse
  • jmap: get java process memory map information
  • idlj: IDL-to-Java compiler. The IDL language into java file
  • policytool: a GUI policy file creation and management tool
  • jrunscript: command-line script

Fifth, install Tomcat (host 192.168.200.112)

1, turn off the firewall and security mechanisms

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

2, see 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, unloading JDK is installed with rpm

Act I.

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

[the root @ localhost ~] # -e RPM OpenJDK Java-1.8.0- --nodeps    dependent relationship // wean behind relation plus --nodeps 
[the root @ localhost ~] # -e RPM Java openjdk-headless--1.8.0 
[root @ localhost ~] # RPM -qa | grep -i openjdk

 Act II,

[the root @ localhost ~ ] Which Java #
 / usr / bin / Java 

[the root @ localhost ~] # RM -rf / usr / bin / Java 

[the root @ localhost ~] # Java - Version
 -bash: / usr / bin / Java : no such file or directory

 4, the installation JDK

[the root @ localhost ~] # -xf JDK the tar-8u191-Linux- x64.tar.gz 

[the root @ localhost ~] # Music Videos jdk1. . 8 .0_191 / / usr / local / Java   // will move the package to the unpacked the specified directory 

[root @ localhost ~] # / usr / local / java / bin / java -version   // at this point you can only view the java version by absolute path information 

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

Export the JAVA_HOME = / usr / local / java   // set the root java 

Export PATH = PATH $: $ the JAVA_HOME / bin   // add the bin subdirectory of the root directory java PATH environment variable 

[the root @ localhost ~ ] # echo $ PATH   // see when modifying the script does not execute the PATH variable 
/ usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / root /bin   
[root @ localhost ~] # Source / etc / Profile   // reset at the script 
[root @ localhost ~] # echo $ the PATH   // and then 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 (启动文件)
commons-daemon-native.tar.gz tomcat-juli.jar
configtest.bat tomcat-native.tar.gz
configtest.sh tool-wrapper.bat
Tool daemon.sh - wrapper.sh 
digest.bat version.bat 
digest.sh version.sh 
setclasspath.bat 

// .bat version of Windows 

// .sh version of Linus

6, start

[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

 

 Sixth, set the Tomcat web storage location (host 192.168.200.112)

[root @ localhost ~] # mkdir -p / Web / the webapp /      // Create a directory to store the page 
[root @ localhost ~] # vim /web/webapp/index.jsp    // add pages to be stored 
<% @ page language = " Java " Import = " Classes in java.util. * " the pageEncoding = " UTF-. 8 " %> 
<HTML> 
        head <> 
                <title> the JSP Page test2 </ title> 
        </ head> 
        <body> 
                <% OUT .println ( " available for purchase 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>

注释:docBase="/web/webapp"     //web应用的文档基准目录         
         path=" Set the default" class "//"                         
         = Reloadable " flase "        // Set Monitoring "class" is the change 

[the root @ localhost ~] # /usr/local/tomcat8/bin/shutdown.sh      // shut the aircraft 
the Using CATALINA_BASE: / usr / local / tomcat8 
the Using CATALINA_HOME:    / usr / local / tomcat8 
the Using CATALINA_TMPDIR: / usr / local / tomcat8 / the TEMP 
the Using JRE_HOME:         / usr / local / the Java 
the Using the CLASSPATH:        /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin / tomcat- juli.jar 
[root @ localhost ~] # /usr/local/tomcat8/bin/startup.sh    // reopened 
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.

 test

 Seven, nginx load balancing configuration (host 192.168.200.111)

Be sure to install nginx, 80 ports have been opened, directly modify configuration files

[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

 

Guess you like

Origin www.cnblogs.com/tanxiaojuncom/p/11535619.html