Apache-2.2

Apache Tomcat + Apache2 + mod_proxy:關於集群的問題

  • January 15, 2015

我在usingTomcat 7.0.57後面有一個集群設置。 Apache2:192.168.2.139 Tomcat Node1:ajp://192.168.2.166:8010(http 連接器也在埠 8082 上定義)Tomcat Node2:ajp://192.168.2.166:8011(http 連接器也在埠 8083 上定義) 我有一個使用. _ _ 部署工作正常,呼叫應用程序也是如此(使用 Apache2 作為代理,意思是)。前端顯示很好 。應用程序: Apache2``mod_proxy

Setup:

Jersey``ExtJS``Parallel Deploymenthttp://http_proxy_ip/WebAppContext/app.htmlExtJS

WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://java.sun.com/xml/ns/javaee"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   id="WebApp_ID" version="2.5">
   <distributable />
   <servlet>
       <servlet-name>FGJobServlet</servlet-name>
       <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
       <init-param>
           <param-name>com.sun.jersey.config.property.packages</param-name>
           <param-value>com.freightgate.quartz.servlet</param-value>
       </init-param>
       <init-param>
           <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
           <param-value>true</param-value>
       </init-param>
       <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
       <servlet-name>FGJobServlet</servlet-name>
       <url-pattern>/scheduler/*</url-pattern>
   </servlet-mapping>
</web-app>

mod_proxy.conf

<VirtualHost *:80>
   DocumentRoot /var/www/html/
   ProxyRequests Off
   ProxyPreserveHost On

   <Proxy balancer://testcluster>
     BalancerMember ajp://192.168.2.166:8010/ route=acd11-node01
     BalancerMember ajp://192.168.2.166:8011/ route=acd11-node02
     ProxySet lbmethod=byrequests
   </Proxy>

   # Excluding balancer-manager app to make it available on master
   ProxyPass /balancer-manager !

   ProxyPass / balancer://testcluster/ stickysession=JSESSIONID|jsessionid
   ProxyPassReverse / balancer://testcluster/ stickysession=JSESSIONID|jsessionid

   <Location /balancer-manager>
     SetHandler balancer-manager
   </Location>

   <Directory "/var/www/html">
     AllowOverride AuthConfig
   </Directory>
</VirtualHost>

**proxy**ExtJS 模型中的定義:

proxy : {
       type : 'rest',
       url : '/J_reportScheduler/scheduler/remotehost/scheduler',
       noCache: false,
       reader : {
           type : 'json',
           successProperty : 'success',
           messageProperty : 'message',
       },
       writer : {
           type : 'json',
       }
}

Servlet definition in Java:

@Path("/{system}")
public class FGJobServlet extends HttpServlet {

   @POST
   @Path("/scheduler")
   @Produces(MediaType.APPLICATION_JSON)
   @Consumes(MediaType.APPLICATION_JSON)
   public Response createJSON(
           JSONObject json,
           @PathParam("system") String system,
           @PathParam("cleanup") String cleanUp) {
      // logic goes here
   }
}

因此,當按鈕被點擊時,它會觸發一個**HTTP Post使用 URL 將 JSON 對象發送到 Java 後端的操作/J_reportScheduler/scheduler/remotehost/scheduler**。

當我從 Eclipse 本地執行它時,它執行良好(並返回 Tomcat 實例的 URL)。在集群中執行它會給我以下**404 Not found**資訊,並從 HTTP 伺服器返回 URL:

Remote Address:192.168.2.139:80
Request URL:http://192.168.2.139/J_reportScheduler/scheduler/remotehost/scheduler
Request Method:POST
Status Code:404 Not Found
Request Headersview source
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:193
Content-Type:application/json
Host:192.168.2.139
Origin:http://192.168.2.139
Referer:http://192.168.2.139/J_reportScheduler/app.html
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
X-Requested-With:XMLHttpRequest
Request Payloadview source
{jobname: "ui101", description: "awd", startdate: "2015-01-21T00:00:00",…}
Response Headersview source
Connection:Keep-Alive
Content-Length:0
Date:Wed, 14 Jan 2015 23:32:56 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.4.6 (CentOS)

直接在其中一個集群節點上呼叫應用程序也可以http connector正常工作。所以,我認為這與我的mod_proxy設置有關。

我已經為此苦苦掙扎了 2 天,但我似乎無法讓它發揮作用。任何幫助深表感謝!

編輯#1:是的,我檢查了 Apache 和 Tomcat 日誌,只有 Apache 顯示 404。應用程序日誌也沒有顯示任何內容。

編輯#2:以防萬一不是很明顯:**HTTP Get**請求工作得很好。

嘗試從以下位置刪除斜杠balancermember

<Proxy balancer://testcluster>
 BalancerMember ajp://192.168.2.166:8010 route=acd11-node01
 BalancerMember ajp://192.168.2.166:8011 route=acd11-node02
 ProxySet lbmethod=byrequests
</Proxy>

引用自:https://serverfault.com/questions/659601