我是Jboss和EJB的新手。我正在尝试与2个实例组成一个Jboss集群,并从tomcat连接集群,所有Jboss实例和tomcat在一台机器上运行。 问题是Jboss的2个实例可以组成一个集群,但是tomcat只关闭集群中的一个节点,当我扼杀由tomcat连接的节点时, tomcat 仍尝试连接它并且无法尝试连接其他节点。因此它始终显示连接被拒绝。
Below is the detail:
**1. About the environment**
|------Jboss1
uses ------> apache(https port443)---->tomcat---|
|------Jboss2
Apache is a loadbanlancer with AJP, tomcat work as EJB client to call Jboss. Jboss1 and Jboss2 run on different ports (changed default ports one by one, ie jnp ports are 1199 and 1299,ha-jndi ports are 1200 and 1300)
and formed a cluter with DefaultPartition. All the applications are good, cause they are copied from production system. And the tomcat can connect jboss1 and jboss2 sepratedly with
the respective jndi url(standalone, not for cluster)
**2. Configurations**
**A.Tomcat jndi configuration:**
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1200,localhost:1300
java.naming.factory.url.pkgs=org.jboss.naming
**B.Jboss configurations**
cluster conf:
I just use the default configuration for cluster with DefaultPartition, jgroups work in default UDP stack .
**jndi configuration (no ports are defined):**
# DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
#
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
**jboss.xml for EJB**
<jboss>
<enterprise-beans>
<session>
<ejb-name>DBNFacade</ejb-name>
<jndi-name>dbn/DBNFacadeBean</jndi-name>
<clustered>True</clustered>
</session>
I add "**<clustered>True</clustered>**" for every section os session in jboss.xml of the EJB.
**3.Logs**
**jboss cluster:**
when I start the 2 instances of jboss, it shows in log like this:
Node1:
GMS: address is 127.0.0.1:58279
-------------------------------------------------------
02:42:35,064 INFO [DefaultPartition] State could not be retrieved (we are the first member in group)
02:42:35,143 INFO [HANamingService] Started ha-jndi bootstrap jnpPort=1200, backlog=50, bindAddress=localhost/127.0.0.1
02:42:35,155 INFO [DetachedHANamingService$AutomaticDiscovery] **Listening on /127.0.0.1:1102, group=230.0.0.4, HA-JNDI address=127.0.0.1:1200**
02:42:44,881 INFO [DefaultPartition] **New cluster view for partition** DefaultPartition (id: 1, delta: 1) : [127.0.0.1:1199, 127.0.0.1:1299]
02:42:44,888 INFO [DefaultPartition] I am (127.0.0.1:1199) received membershipChanged event:
02:42:44,912 INFO [DefaultPartition] Dead members: 0 ([])
02:42:44,913 INFO [DefaultPartition] New Members : 1 ([127.0.0.1:1299])
02:42:44,914 INFO [DefaultPartition] **All Members : 2** ([127.0.0.1:1199, 127.0.0.1:1299])
Node2:
-------------------------------------------------------
GMS: address is 127.0.0.1:39298
-------------------------------------------------------
02:42:44,932 INFO [DefaultPartition] **Number of cluster members: 2**
02:42:44,932 INFO [DefaultPartition] Other members: 1
02:42:44,933 INFO [DefaultPartition] Fetching state (will wait for 30000 milliseconds):
02:42:45,137 INFO [DefaultPartition] state was retrieved successfully (in 204 milliseconds)
02:42:45,278 INFO [HANamingService] Started ha-jndi bootstrap jnpPort=1300, backlog=50, bindAddress=localhost/127.0.0.1
02:42:45,290 INFO [DetachedHANamingService$AutomaticDiscovery] **Listening on /127.0.0.1:1102, group=230.0.0.4, HA-JNDI address=127.0.0.1:1300**
02:42:45,655 INFO [TreeCache] No transaction manager lookup class has been defined. Transactions cannot be used
02:42:45,804 INFO [InterceptorChainFactory] interceptor chain is:
**when shutdown Jboss1:**
logs on Jboss2----**(it can detect the dead of Jboss1)**
02:50:44,935 INFO [DefaultPartition] **New cluster view for partition DefaultPartition (id: 2, delta: -1) : [127.0.0.1:1299]**
02:50:44,965 INFO [DefaultPartition] I am (127.0.0.1:1299) received membershipChanged event:
02:50:44,965 INFO [DefaultPartition] **Dead members**: 1 ([127.0.0.1:1199])
02:50:44,965 INFO [DefaultPartition] New Members : 0 ([])
02:50:44,965 INFO [DefaultPartition] All Members : 1 ([127.0.0.1:1299])
**errors on tomcat:**
ExceptionHandler] URL=[https://192.168.1.232/np/security/signIn.do], QueryString=[null], Referer=[https://192.168.1.232/np/clients/testzfc/login.jsp], SessionId=[7F3DA2CC9AA76C66C091448DEB3EDD7E], orgCode=[testzfc], Exception type=[org.jboss.remoting.CannotConnectException], message=[Can not get connection to server. Problem establishing socket connection for InvokerLocator [socket://**localhost:5446**/?clientMaxPoolSize=300&dataType=invocation&enableTcpNoDelay=true&marshaller=org.jboss.invocation.unified.marshall.InvocationMarshaller&socketTimeout=600000&unmarshaller=org.jboss.invocation.unified.marshall.InvocationUnMarshaller]]
- org.jboss.remoting.CannotConnectException: Can not get connection to server. Problem establishing socket connection for InvokerLocator [socket://**localhost:5446**/?clientMaxPoolSize=300&dataType=invocation&enableTcpNoDelay=true&marshaller=org.jboss.invocation.unified.marshall.InvocationMarshaller&socketTimeout=600000&unmarshaller=org.jboss.invocation.unified.marshall.InvocationUnMarshaller]
the url "localhost:5446" in error log of tomcat is just the port of Jboss1.
What's more, sometimes when I started the 2 instances of Jboss, the tomcat connects Jboss2 instead, I do not know the rule. But the resule is the same, tomcat can only recongnize and connect one member of Jboss cluster, unless I restart the tomcat after shuting down the one instance of jboss that was connected successfully by the tomcat.
Could someone tell me what's wrong with this? Thanks in advance!