这种通过一台apache的服务器把客户请求分别传递给两台tomcat叫负载均衡
========================================= ========================
材料:准备两台Tomcat主机
第一台tomcat主机配置:IP为192.168.200.130
[root@localhost ~]# mkdir -pv /web/webapp
mkdir: 已创建目录 "/web"
mkdir: 已创建目录 "/web/webapp"
[root@localhost ~]# vim /web/webapp/index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <html> <head> <title>JSP test page</title> </head> <body> <% out.println("Welcome to test site,http://www.test.com");%> </body> </html>
[root@localhost ~]# cd /usr/local/tomcat8/conf/
[root@localhost conf]# cp server.xml server.xml.bak //备份一份主配置文件
[root@localhost conf]# vim server.xml
在150行左右的Host下添加Context文件
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context docBase="/web/webapp" path="" reloadable="flase"> </Context>
[root@localhost conf]# /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 conf]# netstat -anpt | grep :8080
tcp6 0 0 :::8080 :::* LISTEN 61263/java
[root@localhost conf]# systemctl stop firewalld
[root@localhost conf]# iptables -F
[root@localhost conf]# setenforce 0
测试:
第二台Tomcat主机配置:IP为192.168.200.122
[root@localhost ~]# mkdir -pv /web/webapp1
mkdir: 已创建目录 "/web"
mkdir: 已创建目录 "/web/webapp1"
[root@localhost ~]# vim /web/webapp1/index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <html> <head> <title>JSP test page</title> </head> <body> <% out.println("Welcome to test site,http://www.test1.com");%> </body> </html>
[root@localhost ~]# cd /usr/local/tomcat8/conf/
[root@localhost conf]# cp server.xml server.xml.bak //备份一份主配置文件
[root@localhost conf]# vim server.xml
在150行左右的Host下添加Context文件
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="/web/webapp1" path="" reloadable="flase">
</Context>
[root@localhost conf]# /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 conf]# netstat -anpt | grep :8080
tcp6 0 0 :::8080 :::* LISTEN 61263/java
[root@localhost conf]# systemctl stop firewalld
[root@localhost conf]# iptables -F
[root@localhost conf]# setenforce 0
测试: