第一部分:負載均衡
下載安裝apche,tomcat
http://download.csdn.net/detail/qm4050/3891699 下載Apache 2.0.64
http://download.csdn.net/detail/qm4050/3891714下載tomcat5.5 zip版本(解壓即可,綠色版)
http://download.csdn.net/detail/qm4050/3891688下載mod_jk,注意和 apache版本匹配
1.修改Apache配置文件http.conf
在apache安裝目錄下conf目錄中找到http.conf
在文件最後加上下面一句話就可以了
include "E:\ide\apache\Apache2\conf\mod_jk.conf"
LoadModule jk_module modules/mod_jk-apache-2.0.55.so
JkWorkersFile conf/workers.properties
worker.tomcat1.host=localhost #tomcat的主機地址,如不爲本機,請填寫ip地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1 #server的加權比重,值越高,分得的請求越多
worker.tomcat2.host=localhost #tomcat的主機地址,如不爲本機,請填寫ip地址
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1 #server的加權比重,值越高,分得的請求越多
#========controller,負載均衡控制器========
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2 #指定分擔請求的tomcat
worker.controller.sticky_session=1
System.out.println("===========================");
%>
<%@ page import="java.util.*" %>
<html><head><title>Cluster App Test</title></head>
<body>
Server Info:
<%
out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"<br>");%>
<%
out.println("<br> ID " + session.getId()+"<br>");
String dataName = request.getParameter("dataName");
if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue);
}
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println( name + " = " + value+"<br>");
System.out.println( name + " = " + value);
}
%>
<form action="index.jsp" method="POST">
名稱:<input type=text size=20 name="dataName">
<br>
值:<input type=text size=20 name="dataValue">
<br>
<input type=submit>
</form>
</body>
</html>
<display-name>TomcatDemo</display-name>
<distributable/>
</web-app>
以上內容是從http://hi.baidu.com/luodaijun/blog/item/5bbe4cfb5ffef864034f56a1.html 引用了部分圖文及評論,經個人測試相關配置效果不錯。