Load balancing based on Apache and tomcat

First, the need for three hosts, one to install apache, two installed tomcat

Two, with tomcat2 tomcat1 mounted Tomcat tomcat-8.5.16 (tomcat1 used for convenience to distinguish the default page, using the test page tomcat2)

       Before installing tomcat you need to install the java jdk, version: jdk-8u191-linux-x64.tar.gz

1, the first tomcat host tomcat1 (page default installation)

Turn off the firewall

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

View 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)

Uninstall the JDK installed with rpm

[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

Install the 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

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

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

2, a second tomcat host tomcat2 (page test installation)

During the installation of the mounting tomcat as the first, the process will be omitted

The main set tomcat web storage location

[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 test1 </ title> 
        </ head> 
        <body> 
                <% OUT .println ( " available for purchase to Test Site, HTTP: //www.test1.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.

Page test

 

 

 

 

Three, apache installation, Apache httpd-2.2.15, yum mounted directly httpd

[root@localhost ~]# yum -y install httpd

Modify the configuration file

[root @ localhost ~] # vim /etc/httpd/conf/httpd.conf 
added to the file
<Proxy balancer: // tomcat />

  BalancerMember ajp://192.168.200.111:8009/ loadfactor=1
  BalancerMember ajp://192.168.200.112:8009/ loadfactor=1
  proxyset lbmethod=byrequests
  </Proxy>
  proxyrequests off
  ProxyPass / balancer://tomcat/
  proxypassreverse / balancer://tomcats/
  ProxyPass /server-status !
  ProxyPass /balancer-manager !

  [Root @ localhost ~] # systemctl restart httpd // restart the service

Page test

 

 

 

Guess you like

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