paulwong

JBOSS集群安装

软件及环境:
jboss-5.1.0.GA
nginx-0.8.15
centos5.5
nginx:192.168.1.251
tomat1:192.168.1.251
tomat2:192.168.1.252
jboss安装目录为:/usr/local/jboss
nginx安装目录为:/usr/local/nginx

JDK、JBOSS、nginx安装略过!

Jboss1配置:

/opt/jboss4.3/jboss-as/server/node2/deploy/jboss-web.deployer/server.xml

<!--由于在LINUX环境下,会有多个IP,address不能改成${0.0.0.0},这样会对127.0.0.1也会进行监听,导致启动出错-->
<Connector protocol="HTTP/1.1" port="8080" address="${ jboss.bind.address}">

<!--将<Engine name="jboss.web" defaultHost="localhost">修改为-->
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="jboss1">

/opt/jboss4.3/jboss-as/server/node2/deploy/jboss-messaging.sar/messaging-service.xml
<!--将20行的<attribute name="ServerPeerID">${jboss.messaging.ServerPeerID:0}</attribute>修改-->
<attribute name="ServerPeerID">${jboss.messaging.ServerPeerID:1}</attribute>

Jboss2配置:

/opt/jboss4.3/jboss-as/server/node2/deploy/jboss-web.deployer/server.xml

<!--由于在LINUX环境下,会有多个IP,address不能改成${0.0.0.0},这样会对127.0.0.1也会进行监听,导致启动出错-->
<Connector protocol="HTTP/1.1" port="8080" address="${ jboss.bind.address}">

<!--将<Engine name="jboss.web" defaultHost="localhost">修改为-->
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="jboss2">

/opt/jboss4.3/jboss-as/server/node2/deploy/jboss-messaging.sar/messaging-service.xml
<!--将20行的<attribute name="ServerPeerID">${jboss.messaging.ServerPeerID:0}</attribute>修改-->
<attribute name="ServerPeerID">${jboss.messaging.ServerPeerID:2}</attribute>

如果想要session同步的话,要在站点的web.xml里面加入<distributable/>

测试文件index.jsp内容如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
     pageEncoding
="UTF-8"%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
<%@page import="java.util.*"%>
 
<%@page import="java.net.InetAddress;"%>
 
<html>
 
<head>
 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 
<title>Cluster App Test</title>
 
</head>
 
<body>
 
<%
 InetAddress ip 
= InetAddress.getLocalHost();
 
//out.println(ip.getHostAddress());
 
%>
 This is responsed by 
<font color="red"> <%=ip.getHostAddress() %></font><br>
 Host Name : 
<font color="red"><%=ip.getHostName() %></font><br>
 Time : 
<font color="red"><%=new Date() %></font><br>
 
<%
 ip 
= null;
 
%>
<br/> <br/> <br/> <br/>
Server Info:
<%
out.println(request.getLocalAddr() 
+ " : " + request.getLocalPort()+"<br>");%>
<%
  out.println(
"<br>Session ID " + session.getId()+"<br>");
 
// 如果有新的 Session 属性设置
 
String dataName = request.getParameter("dataName");
 
if (dataName != null && dataName.length() > 0) {
    
String dataValue = request.getParameter("dataValue");
     session.setAttribute(dataName, dataValue);
  }
  out.print(
"<br/> <b>Session 列表</b>");
  Enumeration e 
= session.getAttributeNames();
 
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>
   
&nbsp;&nbsp;值:<input type=text size=20 name="dataValue">
    
<br>
   
<input type=submit>
  
</form>
 
</body>
 
</html>

Jboss动好像没什么要求,,可以两个同时启动,等启动完之后再启动NGINX就OK了!

Jboss的启动命令为(必须加参数-b ,很多配置文件都依赖于${ jboss.bind.address}这个值,也就是命令行输入的IP地址):
/usr/local/jboss/bin/run.sh -c all -b 192.168.1.251


等都启动完成,就可以防问http://192.168.1.251/cluster-test/

写一个session,刷新,如果session在不同的机器上保持不变,那就集成功了!如下图:

posted on 2012-02-13 16:18 paulwong 阅读(1971) 评论(0)  编辑  收藏 所属分类: JBOSS


只有注册用户登录后才能发表评论。


网站导航: