Lab Environment: CentOS7
#两台tomcat的基本配置如下: [[email protected] localhost] #setenforce0[email protected] localhost] #iptables-f[[email protected] localhost] #yum-y install java-1.8.0-openjdk-devel tomcat Tomcat-webapps tomcat-admin-webapps[[email protected] localhost] #chown tomcat.tomcat/usr/share/tomcat/webapps/test/*[email protected] localhost] #chown tomcat.tomcat test[[email protected] localhost] #vim/etc/tomcat/server.xml <connector port= "8081" protocol= "http/1.1" maxthreads= "$" enablelookups= "False"ConnectionTimeout= "60000" address= "172.16.252.142"Redirectport= "8443"/>[email protected] localhost] #vim/usr/share/tomcat/webapps/test/index.jsp<%@ page language= "Java"%><%@ page import= "java.util.*"%>Out.println ("Tomcat1 Mini"); %> </body>[email protected] localhost] #vim/usr/share/tomcat/conf/tomcat-users.xml<role rolename= "Manager-gui"/><user username= "Tomcat" password= " 123456 "roles=" Manager-gui "/>
#第三台主机安装Nginx: 172.16.253.177
#ngixn做负载均衡:
[email protected]~ localhost] #setenforce 0[[Email protected]~ localhost] #iptables-F[[email protected]~ localhost] #yum-y install nginx-1.10.2-1. el7.ngx.x86_64.rpm [[email protected]~ localhost] #vim/etc/nginx/nginx.confhttp {#定义: Cluster tomcatsrupstream TOMCATSR {server172.16.252.142:8081; Server172.16.254.47:8081;} Include/etc/nginx/conf.d/*. conf;} #引用 [[Email protected]~ localhost] #vim/etc/nginx/conf.d/default. confserver { location/{proxy_pass http://TOMCATSR;root/usr/share/nginx/html; Index index.html index.htm; }
#httpd做负载均衡:
[email protected]~ localhost] #yum-y install httpd
[email protected]~ localhost] #httpd-m
Proxy_balancer_module (shared) #负载均衡模块
[email protected]~ localhost] #vi/etc/httpd/conf.d/tomcat-httpd.conf<proxy Balancer://tomcatsr>Balancermember http://172.16.252.142:8081Balancermember http://172.16.254.47:8081Proxyset lbmethod=byrequests</proxy><virtualhost *:80>ServerName Linux.io Proxyvia on proxyrequests Off proxypreservehost on<proxy *>Require All granted</Proxy> Proxypass/balancer://tomcatsr/Proxypassreverse/balancer://tomcatsr/<location/>Require All granted</Location></VirtualHost>
#测试:
[[Email protected]~ localhost]# forIinch{1..10}; DoCurl http://172.16.253.177/test/;d OneTOMCAT2 Mini1</body>TOMCAT1 Mini</body>TOMCAT2 Mini1</body>TOMCAT1 Mini</body>TOMCAT2 Mini1</body>TOMCAT1 Mini</body>TOMCAT2 Mini1</body>TOMCAT1 Mini</body>TOMCAT2 Mini1</body>TOMCAT1 Mini</body>httpd or Nginx load balancing tomcat