JBoss Clustering 和 Lighttpd 负载平衡显示不一致的行为

JBoss Clustering and Lighttpd Load Balancing displaying inconsistent behaviour

问题

我们在不同的机器上安装了两个 JBossAS 4.2.3,它们是集群的。我们还使用 Lighttpd 作为负载平衡器,并放置在我们的 Tomcat 服务器(Tomcat 服务器没有集群)和 JBoss 服务器之间。一旦所有服务器都启动并运行,应用程序就会完美运行。如果我关闭了一台 JBoss 服务器,请求将按预期重定向到另一台服务器。注销应用程序后,我的问题就开始了。在尝试重新登录应用程序时,我收到一个异常,提示 Tomcat 无法连接到已关闭的服务器。

服务器设置

  • Machine01 - Tomcat7
  • Machine02 - Tomcat7
  • Machine03 - JBoss 4.2.3
  • Machine04 - JBoss 4.2.3
  • Machine05 - Lighttpd 1.4.28
  • 其他信息

    • 所有机器都使用 Ubuntu 12.04 操作系统。
    • JBoss 机器是集群的。
    • EAR 被放置在 all/deploy 文件夹中。
    • JBossAS 使用以下命令启动 - ./run.sh -b 0.0.0.0 -c all --partition=SomePartitionName &> /dev/null &
    • Tomcat7 作为服务运行,因此它们作为 sudo service tomcat7 start 启动。
    • Lighttpd 被配置为 JBoss 机器的负载平衡器。
    • lighttpd 上的 mod_proxy 配置如下:

      server.modules += ("mod_proxy" )
      
      proxy.balance ="fair"
      
      proxy.server = ("" => (("host" =>"Machine03","port" => 1100 ),
      
                 ("host" =>"Machine04","port" => 1100 ))
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      
      java.naming.provider.url=Machine05:80
        // Some where at class level we have the following map declared
      
        private static final Map remoteEJBHashMap = new HashMap(100, 0.9f);
      
      
      
      public static final < T > T getEJBInterface(String jndiLookupName) {
      
        String jndiName = jndiLookupMap.get(jndiLookupName);
      
        T ejbInterface = null;
      
        //T ejbInterface = (T) remoteEJBHashMap.get(jndiLookupName);
      
        //if (ejbInterface == null) {
      
          try {
      
            ejbInterface = (T) ctx.lookup(jndiName);
      
          } catch (NamingException e) {
      
            throw new RuntimeException(e);
      
          }
      
          //remoteEJBHashMap.put(jndiLookupName, ejbInterface);
      
        //}
      
        return ejbInterface;
      
      }
    • jndi.properties 有以下条目

      server.modules += ("mod_proxy" )
      
      proxy.balance ="fair"
      
      proxy.server = ("" => (("host" =>"Machine03","port" => 1100 ),
      
                 ("host" =>"Machine04","port" => 1100 ))
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      
      java.naming.provider.url=Machine05:80
        // Some where at class level we have the following map declared
      
        private static final Map remoteEJBHashMap = new HashMap(100, 0.9f);
      
      
      
      public static final < T > T getEJBInterface(String jndiLookupName) {
      
        String jndiName = jndiLookupMap.get(jndiLookupName);
      
        T ejbInterface = null;
      
        //T ejbInterface = (T) remoteEJBHashMap.get(jndiLookupName);
      
        //if (ejbInterface == null) {
      
          try {
      
            ejbInterface = (T) ctx.lookup(jndiName);
      
          } catch (NamingException e) {
      
            throw new RuntimeException(e);
      
          }
      
          //remoteEJBHashMap.put(jndiLookupName, ejbInterface);
      
        //}
      
        return ejbInterface;
      
      }

    无法弄清楚为什么,在我关闭机器并从应用程序中注销后,Tomcat 不再具有对 JBoss 机器的代理引用。


    我现在已经解决了。感谢 smallworld 为我指明了正确的方向。

    发生的事情是我们正在缓存从 jndi 查找中获得的远程接口。现在据我了解,此远程接口仅指向集群中的一个特定服务器。 (我们认为远程接口足够智能以识别服务器已关闭。看起来智能在您进行查找时与初始上下文有关)。因此,一旦服务器关闭,对该远程接口进行的任何 ejb 调用都会连接到被关闭的服务器。因此,为了解决这个问题,我们停止缓存远程接口,并在每次需要该 EJB 的服务时进行查找。如果任何服务器关闭,查找将返回启动并运行的服务器的远程接口。有了这个,集群可以完美运行!所以,伙计们,你的代码应该是这样的:

    server.modules += ("mod_proxy" )
    
    proxy.balance ="fair"
    
    proxy.server = ("" => (("host" =>"Machine03","port" => 1100 ),
    
               ("host" =>"Machine04","port" => 1100 ))
    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
    
    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
    
    java.naming.provider.url=Machine05:80
      // Some where at class level we have the following map declared
    
      private static final Map remoteEJBHashMap = new HashMap(100, 0.9f);
    
    
    
    public static final < T > T getEJBInterface(String jndiLookupName) {
    
      String jndiName = jndiLookupMap.get(jndiLookupName);
    
      T ejbInterface = null;
    
      //T ejbInterface = (T) remoteEJBHashMap.get(jndiLookupName);
    
      //if (ejbInterface == null) {
    
        try {
    
          ejbInterface = (T) ctx.lookup(jndiName);
    
        } catch (NamingException e) {
    
          throw new RuntimeException(e);
    
        }
    
        //remoteEJBHashMap.put(jndiLookupName, ejbInterface);
    
      //}
    
      return ejbInterface;
    
    }

    注释行是导致问题的行。现在唯一留给我研究的是如果有更好的解决方案。


相关推荐

  • Spring部署设置openshift

    Springdeploymentsettingsopenshift我有一个问题让我抓狂了三天。我根据OpenShift帐户上的教程部署了spring-eap6-quickstart代码。我已配置调试选项,并且已将Eclipse工作区与OpehShift服务器同步-服务器上的一切工作正常,但在Eclipse中出现无法消除的错误。我有这个错误:cvc-complex-type.2.4.a:Invali…
    2025-04-161
  • 检查Java中正则表达式中模式的第n次出现

    CheckfornthoccurrenceofpatterninregularexpressioninJava本问题已经有最佳答案,请猛点这里访问。我想使用Java正则表达式检查输入字符串中特定模式的第n次出现。你能建议怎么做吗?这应该可以工作:MatchResultfindNthOccurance(intn,Patternp,CharSequencesrc){Matcherm=p.matcher…
    2025-04-161
  • 如何让 JTable 停留在已编辑的单元格上

    HowtohaveJTablestayingontheeditedcell如果有人编辑JTable的单元格内容并按Enter,则内容会被修改并且表格选择会移动到下一行。是否可以禁止JTable在单元格编辑后转到下一行?原因是我的程序使用ListSelectionListener在单元格选择上同步了其他一些小部件,并且我不想在编辑当前单元格后选择下一行。Enter的默认绑定是名为selectNext…
    2025-04-161
  • Weblogic 12c 部署

    Weblogic12cdeploy我正在尝试将我的应用程序从Tomcat迁移到Weblogic12.2.1.3.0。我能够毫无错误地部署应用程序,但我遇到了与持久性提供程序相关的运行时错误。这是堆栈跟踪:javax.validation.ValidationException:CalltoTraversableResolver.isReachable()threwanexceptionatorg.…
    2025-04-161
  • Resteasy Content-Type 默认值

    ResteasyContent-Typedefaults我正在使用Resteasy编写一个可以返回JSON和XML的应用程序,但可以选择默认为XML。这是我的方法:@GET@Path("/content")@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})publicStringcontentListRequestXm…
    2025-04-161
  • 代码不会停止运行,在 Java 中

    thecodedoesn'tstoprunning,inJava我正在用Java解决项目Euler中的问题10,即"Thesumoftheprimesbelow10is2+3+5+7=17.Findthesumofalltheprimesbelowtwomillion."我的代码是packageprojecteuler_1;importjava.math.BigInteger;importjava…
    2025-04-161
  • Out of memory java heap space

    Outofmemoryjavaheapspace我正在尝试将大量文件从服务器发送到多个客户端。当我尝试发送大小为700mb的文件时,它显示了"OutOfMemoryjavaheapspace"错误。我正在使用Netbeans7.1.2版本。我还在属性中尝试了VMoption。但仍然发生同样的错误。我认为阅读整个文件存在一些问题。下面的代码最多可用于300mb。请给我一些建议。提前致谢publicc…
    2025-04-161
  • Log4j 记录到共享日志文件

    Log4jLoggingtoaSharedLogFile有没有办法将log4j日志记录事件写入也被其他应用程序写入的日志文件。其他应用程序可以是非Java应用程序。有什么缺点?锁定问题?格式化?Log4j有一个SocketAppender,它将向服务发送事件,您可以自己实现或使用与Log4j捆绑的简单实现。它还支持syslogd和Windows事件日志,这对于尝试将日志输出与来自非Java应用程序…
    2025-04-161