2009-04-19 43 views
3

我有一個Tomcat 6實例,經常需要在多個WAR部署之後由於PermGen問題而重新啓動。使用Apache HTTP實例備份Tomcat的最簡單方法

在生產環境中,拆除網站顯然是不好的做法,只留下任何連接失敗的訪問者。總的來說,設置一個故障轉移的Tomcat集羣有一兩個實例,但現在我想要一個簡單的解決方案:

當Tomcat關閉時,所有請求都被轉發到運行的Apache HTTP服務器1個簡單的「網站正在維護」類型頁面。

我假設我需要一些小型超快速代理來坐在Tomcat前面,爲它提供請求並監視它的健康狀況。如果它死了,它只是將這些請求發送到Apache HTTP。

想法?

回答

4

你可以通常在你的tomcat安裝前使用Apache。設置一個重定向代理規則到你的tomcat。如果這不起作用,apache會發送一個「503服務暫時不可用」,您可以將其配置爲您的維護頁面。

的Apache應用程序文件看起來有點像這個

<VirtualHost *> 
    ServerName example.com 
    ServerAlias *.example.com 
    ServerAdmin [email protected] 

    RewriteEngine on 
    RewriteRule ^/static/(.*) /some/path/for/static/files/static/$1 [L] 
    RewriteRule ^(.*) http://127.0.0.1:8080$1 [P] 

    ErrorLog /var/log/apache2/example/error.log 

    # Possible values include: debug, info, notice, warn, error, crit, 
    # alert, emerg. 
    LogLevel warn 

    CustomLog /var/log/apache2/example/access.log combined 
    ServerSignature On 

    ErrorDocument 503 /static/site_down.html 
</VirtualHost> 

第一重寫規則變化低於一定的URI從這些靜態文件直接提供無代理的所有文件(/靜態/)到一個目錄。你也可以使用它來爲你的網站提供所有的靜態資源,這可以彌補在你的tomcat前面有一個apache的一般(小)性能損失。

ErrorDocument指令更改位於此靜態路徑中的文檔site_down.html的普通503響應。

對於這個工作,你需要啓用了mod_rewrite和mod_proxy的/ mod_proxy_http和 啓用代理在您的Apache2配置

<Proxy *> 
     Order Deny,Allow 
     Deny from all 
     Allow from all 
</Proxy>