锁定老帖子 主题:tomcat的负载均衡问题
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2006-04-05
请问这个问题有什么好的解决办法吗。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2006-04-05
是什么Object, 是保存在session中的么, 这个object有没有被复制呢/?
希望我这片文章对你有帮助 http://spaces.msn.com/dengyin2000/blog/cns!AF4AB52B167D7EE7!178.entry?_c11_blogpart_blogpart=blogview&_c=blogpart#permalink |
|
返回顶楼 | |
发表时间:2006-04-05
谢谢楼上,
object是序列化后通过request传的,什么object其实不重要。我其实也是看了onjava上的这两篇文章来配置的。 我查看了filter的源码,其实就是发现某个rules匹配就redirect到另外一台服务器了。这样原来request里面的东西就丢失了。 我希望负载均衡能够把原来request里面的东西原原本本的传过去。 |
|
返回顶楼 | |
发表时间:2006-04-05
你是说 request 参数掉了么.
<rule className="org.apache.webapp.balancer.rules.RandomRedirectRule" serverInstance="1" maxServerInstances="3" tcpListenAddress="127.0.0.1" tcpListenPort="4001" testWebPage="http://localhost:9080/clusterapp/test.jsp" redirectUrl="http://localhost:9080/clusterapp/sessiondata.jsp" /> <rule className="org.apache.webapp.balancer.rules.RandomRedirectRule" serverInstance="2" maxServerInstances="3" tcpListenAddress="127.0.0.1" tcpListenPort="4002" testWebPage="http://localhost:10080/clusterapp/test.jsp" redirectUrl="http://localhost:10080/clusterapp/sessiondata.jsp" /> <rule className="org.apache.webapp.balancer.rules.RandomRedirectRule" serverInstance="3" maxServerInstances="3" tcpListenAddress="127.0.0.1" tcpListenPort="4003" testWebPage="http://localhost:11080/clusterapp/test.jsp" redirectUrl="http://localhost:11080/clusterapp/sessiondata.jsp" /> <!-- Default redirect if none of the above rules match --> <rule className="org.apache.webapp.balancer.rules.AcceptEverythingRule" redirectUrl="http://localhost:8080/balancer/testLB.jsp" /> 难道redirect之后的request url都变成了clusterapp/sessiondata.jsp 这样的话是掉了. 我也没有真正的测试过那里面的sample. 我觉得正确的应该是把整个request url转到另一台机子上. 你能否贴下Filter的源码 |
|
返回顶楼 | |
发表时间:2006-04-05
我反编译出来的。看doFilter那块,很清楚的用的sendRedirect。
// Decompiled by DJ v3.5.5.77 Copyright 2003 Atanas Neshkov Date: 2006-4-5 16:14:41 // Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version! // Decompiler options: packimports(3); // Source File Name: BalancerFilter.java package org.apache.webapp.balancer; import java.io.IOException; import java.net.URL; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; // Referenced classes of package org.apache.webapp.balancer: // RulesParser, RuleChain public class BalancerFilter implements Filter { public BalancerFilter(); { } protected RuleChain getRuleChain(); { return ruleChain; } public void init(FilterConfig filterConfig); throws ServletException { context = filterConfig.getServletContext();; String configUrlParam = filterConfig.getInitParameter("configUrl");; if(configUrlParam == null); throw new ServletException("configUrl is required.");; try { java.io.InputStream input = context.getResourceAsStream(configUrlParam);; RulesParser parser = new RulesParser(input);; ruleChain = parser.getResult();; context.log(getClass();.getName(); + ": init();: ruleChain: " + ruleChain);; } catch(Exception e); { throw new ServletException(e);; } } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); throws IOException, ServletException { if(response.isCommitted();); { context.log(getClass();.getName(); + ": doFilter();: not inspecting committed response.");; chain.doFilter(request, response);; } else if(!(request instanceof HttpServletRequest);); { context.log(getClass();.getName(); + ": doFilter();: not inspecting non-Http request.");; chain.doFilter(request, response);; } else { HttpServletRequest hreq = (HttpServletRequest);request; HttpServletResponse hres = (HttpServletResponse);response; URL redirectUrl = getRuleChain();.evaluate(hreq);; if(redirectUrl != null); { String encoded = hres.encodeRedirectURL(redirectUrl.toString(););; context.log(getClass();.getName(); + ": doFilter();: redirecting request for " + hreq.getRequestURL();.toString(); + " to " + encoded);; hres.sendRedirect(encoded);; } else { chain.doFilter(request, response);; } } } public void destroy(); { context = null; ruleChain = null; } private RuleChain ruleChain; private ServletContext context; } |
|
返回顶楼 | |
发表时间:2006-04-05
我用jk native connectionor实现了我需要的功能,前面加了一个apache做lb。
问题解决拉:)。就是不知道性能如何。 http://www.nihaoblog.com/1_15630.html |
|
返回顶楼 | |
发表时间:2006-04-05
看了一下, 应该不会有这样的问题才对.
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <!-- BalancerFilter definition --> <filter> <filter-name>BalancerFilter</filter-name> <filter-class>org.apache.webapp.balancer.BalancerFilter</filter-class> <init-param> <param-name>configUrl</param-name> <param-value>/WEB-INF/config/rules.xml</param-value> </init-param> </filter> <!-- BalancerFilter mapping --> <filter-mapping> <filter-name>BalancerFilter</filter-name> <url-pattern>/LoadBalancer</url-pattern> </filter-mapping> </web-app> 这样的话, 也就是第一次这个Filter才有用. 然后就一直request到Balancer后的那台机了. |
|
返回顶楼 | |
发表时间:2006-04-05
redirect是会把request/session里保存的属性值清除的
|
|
返回顶楼 | |
发表时间:2006-04-06
注意, 只是第一次有效, 然后都不会经过这个Filter也就不会有Redirect. 只是进入主页的时候有效, 此时应该是没有什么属性保存的把
|
|
返回顶楼 | |
发表时间:2006-04-06
还是误会我的意思了。我不是访问网页。
我贴个代码吧 HttpURLConnection uc = null; OutputStream conout = null; String strUrl = "http://127.0.0.1/aa.jsp"; Object obj = new Object();; try { URL url = new URL(strUrl);; uc = (HttpURLConnection); url.openConnection();; uc.setRequestMethod("POST");; uc.setRequestProperty("Content-Type", "application/octet-stream");; uc.setDoOutput(true);; ByteArrayOutputStream bout = new ByteArrayOutputStream();; ObjectOutputStream out = new ObjectOutputStream(bout);; out.writeObject(obj);; byte[] mmsBytes = bout.toByteArray();; conout = uc.getOutputStream();; conout.write(mmsBytes);; conout.close();; int code = uc.getResponseCode();; String codeContent = java.net.URLDecoder.decode(uc.getResponseMessage();, "UTF-8");; } catch (Exception e); { e.printStackTrace();; } finally { if (uc != null); { uc.disconnect();; } uc = null; } 我每次都提交一个object到这个网页,所以每次都会经过filter的。 |
|
返回顶楼 | |