http://502245466.blog.51cto.com/7559397/1304050 Apache+Tomcat构建Tomcat负载均衡集群(keepalived)
http://502245466.blog.51cto.com/7559397/1304712Apache代理Tomcat实现session共享构建网上商城系统
http://502245466.blog.51cto.com/7559397/1302343 LVS+Keepalived实现高可用负载均衡
――――――――――――――――――
192.168.1.123/192.168.1.121为后端tomcat,mysql在192.168.1.121上,192.168.1.123没有mysql。启动121的mysql,121/123http不用启动
192.168.1.122/192.168.1.23上安装apache和keepalived
――――――――――――
配置apache反向代理tomcat时的mod_proxy.conf内容
vim /usr/local/apache/conf/extra/mod_proxy.conf
ProxyVia on
ProxyRequests Off
ProxyPreserveHost Off
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / ajp://192.168.1.123:8009/(或者)
ProxyPassReverse / ajp://192.168.1.123:8009/
――――――――――――
配置apache负载均衡时的mod_proxy.conf内容
vim /usr/local/apache/conf/extra/mod_proxy.conf
ProxyVia Off
ProxyRequests Off
ProxyPreserveHost Off
<Proxy balancer://nba>
BalancerMember http://192.168.1.121:8080 loadfactor=1
BalancerMember http://192.168.1.123:8080 loadfactor=1
ProxySet lbmethod=bytraffic
</Proxy>
ProxyPass / balancer://nba/ stickysession=JSESSIONID
ProxyPassReverse / balancer://nba/
――――――――――――
配置Apache使用mod_jk模块实现代理
配置apache反向代理tomcat时的mod_jk.conf内容
JkWorkersFile /tomcat/conf/workers.properties
JkLogFile /var/log/mod_jk.log
JkLogLevel info
JkMount /* tomcat1
另:配置apache反向代理tomcat时的workers.properties内容
worker.list=tomcat1
worker.tomcat1.port=8009
worker.tomcat1.host=192.168.1.121
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
――――――――――――
配置Apache使用mod_jk模块实现负载均衡
配置apache负载均衡tomcat时的mod_jk.conf内容
JkWorkersFile /tomcat/conf/workers.properties
JkLogFile /var/log/mod_jk.log
JkLogLevel info
JkMount /* controller
另:配置apache负载均衡tomcat时的workers.properties内容
worker.list=controller
#========tomcat1========
worker.tomcat1.port=8009
worker.tomcat1.host=192.168.1.121
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
#========tomcat2========
worker.tomcat2.port=8009
worker.tomcat2.host=192.168.1.123
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
#========controller=======
worker.controller.type=lb
worker.controller.balance_workers=tomcat1,tomcat2
worker.controller.sticky_session=1
――――――――――――
测试jsp内容
<%@ page language="java" %>
<html>
<head><title>Tomcat1</title></head>
<body>
<h1><font color="red">Tomcat1 </font></h1>
<table align="centre" border="1">
<tr>
<td>Session ID</td>
<% session.setAttribute("abc","abc"); %>
<td><%= session.getId() %></td>
</tr>
<tr>
<td>Created on</td>
<td><%= session.getCreationTime() %></td>
</tr>
</table>
</body>
</html>
――――――――――――
解决ProxySet: unknown lbmethod lbmethod=bytraffic; balancer://nba
httpd.conf里有下面2个选项
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
――――――――――――
常用命令:
ps aux|grep java
netstat -an|grep 80
killall -9 httpd
cd /usr/local/apache/bin/
./startup.sh;tail -f /tomcat/logs/catalina.out
vim /usr/local/apache/conf/httpd.conf
/etc/init.d/iptables stop