httpd(proxy_http_module)+tomcat cluster,

httpd(proxy_ajp_module)+tomcat cluster;

httpd(proxy_http_module)+tomcat cluster,

配置Tomcat集群

在Tomcat服务器上分别创建index.jsp作为负载均衡的页面;

~]# mkdir /var/lib/tomcat/webapps/test/{classes,lib,WEB-INF} -pv
~]# cp /webapps/ROOT/index.jsp /var/lib/tomcat/webapps/test/

安装置httpd代理服务

~]# yum -y install httpd

安装完成后需要确保安装proxy_balancer_module (shared)

配置httpd服务器

~]# cd /etc/httpd/conf.d/
]# vim tomcat.conf 
<Proxy balancer://tomcat>
    BalancerMember  http://172.16.100.7:8080 loadfactor=1
    BalancerMember  http://172.16.100.8:8080 loadfactor=1
    ProxySet  lbmethod=byrequests
</Proxy>

ProxyVia Off
ProxyRequests Off
ProxyPass / balancer://tomcat/ProxyPa***everse / balancer://tomcat/<Proxy *>
    Order Allow,Deny
    Allow From all
</Proxy>

<Location />
    Order Allow,Deny
    Allow From all
</Location>

测试:

p_w_picpath p_w_picpath
依据测试,可正常使用httpd proxy_httpd_module进行负载;

会话粘性的实现方法:

对Tomcat主机的配置分别进行标识;

172.16.80.7
p_w_picpath
172.16.80.8
p_w_picpath

对httpd进行配置

配置其/etc/httpd/conf.d/tomcat.conf
第一行用于设定表明用户访问时是需要cookie;
Header add :添加header 首部
Set-Cookie :设置Cookie 
route=TomcatA :于172.16.80.7中的JvmRoute保持一致
route=TomcatB :于172.16.80.8中的JvmRoute保持一致 ProxySet stickysession=ROUTEID中的ROUTEID和Set-cookie的值保持一致;

Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED    			<proxy balancer://tcsrvs>
				BalancerMember http://172.18.100.67:8080 route=TomcatA loadfactor=1
				BalancerMember http://172.18.100.68:8080 route=TomcatB loadfactor=2
				ProxySet lbmethod=byrequests				
				ProxySet stickysession=ROUTEID			</Proxy>
				
			<VirtualHost *:80>
				ServerName lb.magedu.com
				ProxyVia On
				ProxyRequests Off
				ProxyPreserveHost On
				<Proxy *>
					Require all granted				
				</Proxy>
				ProxyPass / balancer://tcsrvs/				
				ProxyPa***everse / balancer://tcsrvs/				
				<Location />
					Require all granted				
				</Location>
			</VirtualHost>

管理接口,新建一个balancer-manager.conf;

<Location /balancer-manager>
    SetHandler balancer-manager
    ProxyPass !
    Require all granted
</Location>

测试

在访问172.16.80.6/test/时将一直是TomcatB;
p_w_picpath
在stop掉TomcatB的tomcat服务后访问才变为TomcatA;
p_w_picpath

balancer-manager管理 p_w_picpath

httpd(proxy_ajp_module)+tomcat cluster;

将http更改为ajp,并将端口更改为8009; <proxy balancer://tcsrvs> BalancerMember ajp://172.18.100.67:8009 BalancerMember ajp://172.18.100.68:8009 ProxySet lbmethod=byrequests </Proxy>

<VirtualHost *:80>
				ServerName lb.magedu.com				
				ProxyVia On
				ProxyRequests Off
				ProxyPreserveHost On
				<Proxy *>
					Require all granted				
				</Proxy>
				ProxyPass / balancer://tcsrvs/				
				ProxyPa***everse / balancer://tcsrvs/				
				<Location />
					Require all granted				
				</Location>
				<Location /balancer-manager>
					SetHandler balancer-manager					
					ProxyPass !					
					Require all granted				
				</Location>
			</VirtualHost>