hello osgi servlet

0

源起

在 OSGi 原始的 R1 時代,Framework/Http/Log/Device Access 的部份就已經上場,這裡將試做 Http/Log 的部份,並使用 R4 的 Declarative Services 規格 org.osgi.service.component 來試驗。

規格書的 R4 Compendium V4.0.1 Specification 中 102 Http Service Specification 指的就是 org.osgi.service.http 這個部份,該部分實做可以參考 org.eclipse.equinox.http.HttpService。

如何用 Http Service

這裡建議使用 eclipse 來做,先建立一個空白標準 OSGi 專案,然後需要動到三個檔案,因為 eclipse PDE 尚未支援 Service-Component 的標籤,所以要自行到 MANIFEST 去填寫。

  1. META-INF/MANIFEST.MF (修改檔案 Service-Component point to component.xml)
  2. OSGI-INF/component.xml (新增檔案 implementation point to Component.java)
  3. Component.java (新增檔案 activate and deactivate methods)

META-INF/MANIFEST.MF

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: HelloHttp Plug-in
Bundle-SymbolicName: HelloHttp
Bundle-Version: 1.0.0
Bundle-Localization: plugin
Import-Package: javax.servlet;version="2.3.0",
 javax.servlet.http;version="2.3.0",
 org.osgi.framework;version="1.3.0",
 org.osgi.service.component;version="1.0.0",
 org.osgi.service.http;version="1.2.0",
 org.osgi.service.log;version="1.3.0" 
Service-Component: OSGI-INF/component.xml

OSGI-INF/component.xml

<?xml version="1.0" encoding="UTF-8"?>
<component name="hello.component">
  <implementation class="hello.Component"/>
  <reference name="LOG" 
    interface="org.osgi.service.log.LogService" 
    cardinality="1..1" 
    policy="static"/>
  <reference name="HTTP" 
    interface="org.osgi.service.http.HttpService" 
    cardinality="0..1" 
    policy="dynamic" 
    bind="setHttp" 
    unbind="unsetHttp"/>
</component>

hello/Component.java

package hello;

import java.io.IOException;
import java.util.Date;
import java.util.Hashtable;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
import org.osgi.service.log.LogService;

public class Component {
    LogService log;
    HttpService http;
    protected void activate(ComponentContext context) {
        log = (LogService) context.locateService("LOG");
        log.log(LogService.LOG_INFO, "#### Hello World");
    }
    protected void deactivate(ComponentContext context) {
        log.log(LogService.LOG_INFO, "#### Goodbye World");
    }
    protected void setHttp(HttpService h) {
        this.http = h;
        this.registerServlet();
    }
    protected void unsetHttp(HttpService h) {
        this.http.unregister("/haha");
        this.http = null;
    }
    private void registerServlet() {

        Hashtable initparams = new Hashtable();
        initparams.put("name", "value");

        Servlet myServlet = new HttpServlet() {

            String name = "foo";

            public void init(ServletConfig config) {
                this.name = (String) config.getInitParameter("name");
            }

            public void doGet(HttpServletRequest req, HttpServletResponse rsp)
                    throws IOException {
                String foo = req.getParameter("foo");
                rsp.setContentType("text/html;charset=UTF-8");
                StringBuilder sb = new StringBuilder();
                sb.append("The init parameter : " + this.name);
                sb.append("<BR/>");
                sb.append("The foo parameter : " + foo);
                sb.append("<BR/>");
                sb.append("日期 : " + new Date());
                sb.append("<BR/>");

                // servlet 2.3 only
                //Locale reqLocal = req.getLocale();
                //sb.append("The country is :" + reqLocal.getCountry()).append("<BR/>");
                //sb.append("The language is :" + reqLocal.getLanguage());    
                rsp.getWriter().println(sb.toString());

            }
        };

        try {

            http.registerServlet("/haha", myServlet, initparams,null);

        } catch (ServletException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NamespaceException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

測試

先看看 bundle 以及 log 服務是否運作。 然後開 http://127.0.0.1/haha?foo=abc 看看,之後再關掉 http service。

osgi> ss

Framework is launched.

id    State       Bundle
0    ACTIVE      system.bundle_3.3.0.v20060919
2    ACTIVE      org.eclipse.equinox.ds_1.0.0.v20060828
4    ACTIVE      org.eclipse.equinox.log_1.0.100.v20060717
6    ACTIVE      org.eclipse.osgi.services_3.1.100.v20060918
12    ACTIVE      HelloHttp_1.0.0
13    ACTIVE      org.eclipse.equinox.http_1.0.100.v20060821
14    ACTIVE      org.eclipse.equinox.servlet.api_1.0.0.v20060717

osgi> log
>Info [4] Log created; Log Size=100; Log Threshold=4 initial@reference:file:org.eclipse.equinox.log_1.0.100.v20060717.jar/
>Info [4] ServiceEvent REGISTERED {service.id=21}
>Info [4] ServiceEvent REGISTERED {service.id=22}
>Info [4] ServiceEvent REGISTERED {service.id=23}
>Info [4] BundleEvent STARTED initial@reference:file:org.eclipse.equinox.log_1.0.100.v20060717.jar/
>Info [6] BundleEvent STARTED initial@reference:file:org.eclipse.osgi.services_3.1.100.v20060918.jar/
>Info [12] #### Hello World initial@reference:file:../HelloLog/
>Info [12] BundleEvent STARTED initial@reference:file:../HelloLog/
>Info [13] ServiceEvent REGISTERED {service.id=24}
>Info [13] ServiceEvent REGISTERED {service.id=25}
>Info [13] ServiceEvent REGISTERED {service.id=26}
>Info [13] BundleEvent STARTED initial@reference:file:org.eclipse.equinox.http_1.0.100.v20060821.jar/
>Info [14] BundleEvent STARTED initial@reference:file:org.eclipse.equinox.servlet.api_1.0.0.v20060717.jar/
>Info [0] FrameworkEvent STARTLEVEL CHANGED System Bundle

osgi> stop 13

osgi> log

>Info [13] ServiceEvent UNREGISTERING {service.id=25}
>Info [13] ServiceEvent UNREGISTERING {service.id=26}
>Info [13] ServiceEvent UNREGISTERING {service.id=24}
>Info [13] BundleEvent STOPPED initial@reference:file:org.eclipse.equinox.http_1.0.100.v20060821.jar/

網路上找個新的 Http Service 來換。

osgi> install http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
Bundle id is 15

osgi> ss

Framework is launched.

id    State       Bundle
0    ACTIVE      system.bundle_3.3.0.v20060919
2    ACTIVE      org.eclipse.equinox.ds_1.0.0.v20060828
4    ACTIVE      org.eclipse.equinox.log_1.0.100.v20060717
6    ACTIVE      org.eclipse.osgi.services_3.1.100.v20060918
12    ACTIVE      HelloHttp_1.0.0
13    RESOLVED    org.eclipse.equinox.http_1.0.100.v20060821
14    ACTIVE      org.eclipse.equinox.servlet.api_1.0.0.v20060717
15    INSTALLED   org.knopflerfish.bundle.http_2.0.0

osgi> start 15

osgi> ss

Framework is launched.

id    State       Bundle
0    ACTIVE      system.bundle_3.3.0.v20060919
2    ACTIVE      org.eclipse.equinox.ds_1.0.0.v20060828
4    ACTIVE      org.eclipse.equinox.log_1.0.100.v20060717
6    ACTIVE      org.eclipse.osgi.services_3.1.100.v20060918
12    ACTIVE      HelloHttp_1.0.0
13    RESOLVED    org.eclipse.equinox.http_1.0.100.v20060821
14    ACTIVE      org.eclipse.equinox.servlet.api_1.0.0.v20060717
15    ACTIVE   org.knopflerfish.bundle.http_2.0.0

osgi> log
>Info [15] BundleEvent INSTALLED http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Info [15] BundleEvent RESOLVED http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Info [15] ServiceEvent REGISTERED {service.id=27}
>Info [15] No CM present, using default configuration http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Debug [15] Updated pid=org.knopflerfish.bundle.http.factory.HttpServer.default http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Debug [15] create pid=org.knopflerfish.bundle.http.factory.HttpServer.default http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Debug [15] Creating socket http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Info [15] HTTP server started on port 8080 http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Info [15] ServiceEvent REGISTERED {service.id=28}
>Info [15] BundleEvent STARTED http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Debug [15] Alias "/haha" was registered by bundle 12 http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar

再測一次看看。

eclipse and OSGi

0

源起

想開發基於 RCP 之上的應用,就需要了解其底層使用的 OSGi 運作機制。OSGi 基本上希望軟體可以像現在 USB 一樣熱插拔,既然 USB 需要 OS 支援,應用程式就需要 OSGi 來做這個事,讓符合規格的應用程式可以直接熱插拔,甚至可以挑版本插拔,聽起來好像不錯。

What’s New

  1. 2006-09-23 新增螢幕展示 screencast

Open Services Gateway in Eclipse

大部分的 Java 開發者都直接用 IDE,並不太會去動到 eclipse 的內部,eclispe IDE 本身由一堆 plug-ins 組成,同時提供一個 OSGi 的環境供 plug-ins 運作,提供整個開發所需的功能。

慢慢地有人覺得 minimum eclipse plug-ins 可以方便再利用來開發 eclipse IDE 類似桌面型軟體,所以 Eclipse Rich Client Platform (RCP) 慢慢成形,RCP 牽涉到 plug-ins 取捨,選哪些 eclipse plug-ins 可以方便以後大家使用,當然 OSGi 也要一起包起來帶走。

RCP 包起來的環境中都可以找到這個實作 rcp/plugins/org.eclipse.osgi_3.x.x.jar。

osgi console

先進入 console 狀態

C:\Downloads\EclipseInstall\OSGi>java -Dosgi.install.area=file://c:/downloads/ 
-cp org.eclipse.osgi_3.2.0.v20060601.jar
org.eclipse.osgi.framework.launcher.Launcher -console

launch 後到 http://www.knopflerfish.org/repo/index.html 找一些下載。

osgi> ss

Framework is shutdown.

id      State       Bundle
0       RESOLVED    system.bundle_3.2.0.v20060601

osgi> launch

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601

osgi> install http://www.knopflerfish.org/repo/jars/log/log_all-2.0.0.jar
Bundle id is 1

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       INSTALLED   org.knopflerfish.log_2.0.0

osgi> start 1

啟動失敗,會告知缺少 org.osgi.service.cm,換一個不相依commons-logging_all-2.0.0.jar 試過,可以啟動。

osgi> install http://www.knopflerfish.org/repo/jars/commons-logging/commons-logging_all-2.0.0.jar
Bundle id is 2

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       INSTALLED   org.knopflerfish.log_2.0.0
2       INSTALLED   org.knopflerfish.bundle.commons-logging_2.0.0

osgi> start 2

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       INSTALLED   org.knopflerfish.log_2.0.0
2       ACTIVE      org.knopflerfish.bundle.commons-logging_2.0.0

加上 cm 看看。

osgi> install http://www.knopflerfish.org/repo/jars/cm/cm_all-2.0.0.jar
Bundle id is 4

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       INSTALLED   org.knopflerfish.log_2.0.0
2       ACTIVE      org.knopflerfish.bundle.commons-logging_2.0.0
4       INSTALLED   org.knopflerfish.bundle.cm_2.0.0

osgi> start 4

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       RESOLVED    org.knopflerfish.log_2.0.0
2       ACTIVE      org.knopflerfish.bundle.commons-logging_2.0.0
4       ACTIVE      org.knopflerfish.bundle.cm_2.0.0

osgi> start 1

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       ACTIVE      org.knopflerfish.log_2.0.0
2       ACTIVE      org.knopflerfish.bundle.commons-logging_2.0.0
4       ACTIVE      org.knopflerfish.bundle.cm_2.0.0

screencast 螢幕展示

覺得手動太麻煩 ? 可以用 eclipse 來玩,非常簡單,幾分鐘就可以。

screencast

  1. 用 3.2 版
  2. 只有選 plug-in 專案,沒有 Bundle 專案,以後也許會改比較 OSGi 的說法。
  3. 用 Equinox 當底層
  4. 都幫你出好了,雖然應該用 Bundle 比較適合
  5. 直接用範本,連程式碼都不用打
  6. 直接就可以跑
  7. 檢視一下
  8. 匯出 jar
  9. 順便匯出 ant 的 build.xml 參考
  10. 看一下成果
  11. 建立一個純的 osgi 環境,只取 org.eclipse.osgi 一個 jar
  12. 直接吃剛才編出的 jar 看看。

產出的 ant build.xml 可是好東西,對於需要 自動化產出 Bundle 的人來說,用起來會很方便。

small osgi 螢幕展示

關於 eclipse 開發的螢幕展示還可以參考下面連結,將 OSGi 環境建立在改造過小型 NAS 裝置上面,在遠端用 eclipse 開發。

Coding bundles on the Slug demo movie

Remote debugging on the Slug demo movie

OSGi 移植到小裝置上的做法,也許 gcj 也是一種可以考慮的做法。

OpenSlug Gateway Installation – OSGi on the NSLU2

OSGi on the Slug

將 OSGi 真的變成 Open Services Gateway 似乎需要一點時間,目前 IBM 在這個領域推蠻久的。

Managed mobile clients with OSGi: Managed smart clients

IBM Workplace Client Technology, Micro Edition and Open Services Gateway Initiative

links 參考

Developing Eclipse/OSGi Web Applications

OSGi Everywhere

Spring and OSGi, A Perfect Match?

Spring and OSGi

Understanding how Eclipse plug-ins work with OSGi

Launching Eclipse OSGi Framework from the command line

OSGi Open Source Market

Knopflerfish – Open Source OSGi

Java: 淺談 OSGi 標準

httperf and autobench in Slax

0

源起

下面內容可能出現之前做過而省略或是疏漏現象,如有問題請告訴我或是參考之前本站的 Native Tomcat in Slax 一文,也許可以找到相關提示。

my_7_crash.svg

網站要掛了嗎 ?

網站的效能往往需要測試才知道可以跑到哪種程度,平常就應該要測看看,在掛掉之前趕快解決。

關於測試工具 httperf 與 autobench 的部份,請閱讀 HTTP performance testing 一文,有非常詳細的內容可以參考,這裡是要轉化為 slax 可以用的 mo,方便在 vmplayer 之中運行。

一開始要做的是取得檔案後開始安裝 httperf 與 autobench 。

checkinstall httperf

  1. cd /mnt/hda1
  2. wget httperf-0.8.tar.gz
  3. uselivemod Official_Development_module_5_1_4.mo
  4. tar zxvf httperf-0.8.tar.gz
  5. cd httperf-0.8
  6. ./configure
  7. make
  8. checkinstall
  9. mv httperf-0.8-i386-1.tgz /mnt/hda1

checkinstall autobench

  1. cd /mnt/hda1
  2. wget autobench-2.1.2.tar.gz
  3. tar zxvf autobench-2.1.2.tar.gz
  4. cd autobench-2.1.2
  5. ./configure
  6. make
  7. checkinstall
  8. mv autobench-2.1.2-i386-1.tgz /mnt/hda1/

開始測試之前需要網站,這裡用本機的 Tomcat 來測。

start tomcat

  1. uselivemod jre-1_5_0_08-linux.mo
  2. uselivemod apache-tomcat-5.5.15.mo
  3. /usr/local/tomcat/bin/startup.sh
  4. netstat -at

httperf first run

第一次跑用比較少的人數,只用 10 個。

httperf—server=192.168.213.131—port=8080—rate=10—num-conns=500

httperf --client=0/1 --server=192.168.213.131 --port=8080 
--uri=/ --rate=10 --send-buffer=4096 --recv-buffer=16384 
--num-conns=500 --num-calls=1

Maximum connect burst length: 1

Total: connections 500 requests 500 replies 500 test-duration 49.909 s

Connection rate: 10.0 conn/s (99.8 ms/conn, <=2 concurrent connections)
Connection time [ms]: min 1.0 avg 2.0 max 184.5 median 1.5 stddev 8.3
Connection time [ms]: connect 0.0
Connection length [replies/conn]: 1.000

Request rate: 10.0 req/s (99.8 ms/req)
Request size [B]: 66.0

Reply rate [replies/s]: min 10.0 avg 10.0 max 10.0 stddev 0.0 (9 samples)
Reply time [ms]: response 2.0 transfer 0.0
Reply size [B]: header 149.0 content 8132.0 footer 0.0 (total 8281.0)
Reply status: 1xx=0 2xx=500 3xx=0 4xx=0 5xx=0

CPU time [s]: user 0.55 system 48.17 (user 1.1% system 96.5% total 97.6%)
Net I/O: 81.7 KB/s (0.7*10^6 bps)

Errors: total 0 client-timo 0 socket-timo 0 connrefused 0 connreset 0
Errors: fd-unavail 0 addrunavail 0 ftab-full 0 other 0

換個動態 JSP 試看看,加上—uri=/jsp-examples/jsp2/el/basic-arithmetic.jsp 跑起來,沒太大差異,都還沒到瓶頸。

問題在於要找到極限需要不斷加大設定值來測試,手動當然可以,不過這工具已經有人寫好了。

autobench first test

轉用 autobench 來跑多次的結果方便找出掛掉的地方。

autobench --single_host --host1 192.168.213.131 --port1 8080 --uri1 / --quiet \
--low_rate 10 --high_rate 50 --rate_step 10 --num_call 1 \
--num_conn 1000 --timeout 5 --file results.tsv 

結果如下,大致還是可以看出 req_rate 都可以跟上。

dem_req_rate    req_rate_192.168.213.131        con_rate_192.168.213.131       
min_rep_rate_192.168.213.131     avg_rep_rate_192.168.213.131    
max_rep_rate_192.168.213.131    stddev_rep_rate_192.168.213.131 
resp_time_192.168.213.131      net_io_192.168.213.131   errors_192.168.213.131
10      10.0    10.0    10.0    10.0    10.0    0.0     1.1     81.6    0
20      20.0    20.0    20.0    20.0    20.0    0.0     1.1     163.2   0
30      30.0    30.0    30.0    30.0    30.0    0.0     1.0     244.8   0
40      40.0    40.0    40.0    40.0    40.0    0.0     1.1     326.4   0
50      50.0    50.0    50.0    50.0    50.0    0.0     1.0     408.0   0

文字檔很難看出正確的趨勢,還是轉圖出來看比較方便找出關鍵。

download gnuplot

輸出圖案來判讀簡單了解,不過需要先下載 gnuplot mo 來裝。

  1. cd /mnt/hda1
  2. wget gnuplot_4_0.mo
  3. uselivemod gnuplot_4_0.mo

裝好就可以用 bench2graph 跑看看。

bench2png

autobench 附的 bench2graph 會輸出 postscript 格式,這裡換成 PNG 格式。改成 echo set terminal png small color 的命令。

  1. cd /usr/local/bin
  2. cp bench2graph bench2png
  3. vi bench2png
  4. cd to autobench results dir
  5. bench2png results.tsv result.png

上圖可以看到整個線性上升,尚未到底,再加點負荷,跑一次看看,同時為了避免流量飆高,整個 Y 軸都是流量,會導致其他數值看起來躺在 X 軸上,所以採用指定欄位的做法,避掉 net_io 這一欄。

# autobench --single_host --host1 192.168.213.131 --port1 8080 --uri1 / --quiet \
--low_rate 10 --high_rate 100 --rate_step 10 --num_call 10 \
--num_conn 1000 --timeout 5 --file results2.tsv
bench2png results2.tsv results2.png 4 5 6 7 8

圖中可以看到卡在800-900 請求/秒 (80-90 連線/秒) 的時候,急速墜落。

道這裡完成基本安裝與測試,接下來可以包個 mo 出來用了,免得關機完要再來一次。

dir2mo autobench mo

為求以後測試方便,將 httperf 與 autobench 包成一個 mo,同時加上改的 bench2png。

  1. cd /mnt/hda1/work
  2. mkdir autobench
  3. installpkg -root autobench ../autobench-2.1.2-i386-1.tgz
  4. installpkg -root autobench ../httperf-0.8-i386-1.tgz
  5. cp /usr/local/bin/bench2png autobench/usr/local/bin/
  6. dir2mo autobench autobench-2.1.2.mo
  7. reboot for test.

包完後開機一次做完整測試。

uselivemod autobench-2.1.2.mo

  1. cd /mnt/hda1/work
  2. uselivemod jre-1_5_0_08-linux.mo
  3. uselivemod apache-tomcat-5.5.15.mo
  4. uselivemod gnuplot_4_0.mo
  5. uselivemod autobench-2.1.2.mo
  6. /usr/local/tomcat/bin/startup.sh
  7. cd /tmp
  8. autobench again
  9. bench2png results.tsv results.png 4 5 6 7 8

這裡可以用更細的方式試看看,改取每次加五個方式。

autobench --single_host --host1 192.168.213.131 --port1 8080 --uri1 / --quiet \
--low_rate 50 --high_rate 100 --rate_step 5 --num_call 10 \
--num_conn 1000 --timeout 5 --file results.tsv 

看起來 750需求 (75連線) 左右就開始不穩。奇怪的是後來又線性上揚,不清楚是不是 JVM 的 GC 運作導致 Tomcat 一口氣喘不過來,有機會再多做些測試。

download autobench-2.1.2.mo

autobench-2.1.2.mo

links

The Linux HTTP Benchmarking HOWTO

httperf—-A Tool for Measuring Web Server Performance

Native Tomcat in SLAX

0

緣起

年初做了個簡易測試 Tomcat 的 APR 連接器簡易測試 發布在 javaworld@TW 網站,現在想在 SLAX popcorn 上面跑看看,這裡將先作編譯與環境準備工作,也就是產出相對的 mo 檔。

下圖為本文產出的 mo 安裝之後,用 firefox 跑出來的部份畫面。

更新紀錄 Changelog

  1. 2006-09-26 APR 本身編譯時可能以為系統有 sendfile 支援,但是執行時候卻發現沒有這樣支援,可能是檔案系統的支援問題 ? 待查,這個現象在 Apache in Slax 一文 中有遇到,可以在設定檔關掉這個行為,Tomcat 也可以設定 useSendfile 參數來關掉,預設是有開啟的。所以說下面做法如果沒有做到修正檔案系統或是關掉設定的輔助,很可能會導致更慘的效率,白忙一場。但是這在一般 ext2/ext3 應該都沒問題,不過這裡畢竟是談 SLAX 環境,特此加上說明。

準備

有些步驟可能之前做過而出現省略或是疏漏現象,請告訴我或是請參考之前本站的 gcin in slax popcorn 一文,也許可以找到相關提示。

編譯需要準備一些工具,當然要跑 tomcat 之前須先有 JRE。一開始先到 Apache Tomcat 5.5.17 下載,然後主要參考 Apache Portable Runtime and Tomcat 的說明來進行。

Create jre mo

先裝安裝檔,再加連結到 /usr/local/bin/java 執行檔與 /usr/local/java 目錄,接著用 dir2mo 包成 mo 檔,並裝上去測看看。

  1. cd /mnt/hda1
  2. wget jre-1_5_0_08-linux-i586.bin
  3. chmod +x jre-1_5_0_08-linux-i586.bin
  4. cd /mnt/hda1/work
  5. mkdir -p java/usr/local
  6. cd java/usr/local/
  7. /mnt/hda1/jre-1_5_0_08-linux-i586.bin
  8. yes
  9. ls
  10. jre1.5.0_08/bin/java -version
  11. mkdir bin
  12. cd bin
  13. ln -s ../jre1.5.0_08/bin/java java
  14. ./java -version
  15. cd /mnt/hda1/work/java/usr/local
  16. ln -s jre1.5.0_08 java
  17. java/bin/java -version
  18. cd /mnt/hda1/work
  19. dir2mo java jre-1_5_0_08-linux.mo
  20. uselivemod jre-1_5_0_08-linux.mo
  21. java -version

Tomcat test run

tomcat 後來預設用 eclipse 的編譯器,所以目前只要裝 JRE 1.5 版,並不需要裝到 JDK 版本,但是編譯 tcnative 需要 JDK,等一下會談到。

  1. cd /mnt/hda1
  2. wget apache-tomcat-5.5.17.tar.gz
  3. tar zxvf apache-tomcat-5.5.17.tar.gz
  4. export JAVA_HOME=/usr/local/java
  5. apache-tomcat-5.5.17/bin/startup.sh
  6. netstat -at | grep 8080
  7. more apache-tomcat-5.5.17/logs/catalina.out

一開頭部份可以看到 APR 沒有載入。

INFO: The Apache Tomcat Native library which allows optimal performance 
in production environments was not found on the java.library.path:....

Create the jdk mo

編譯 tomcat-native-1.1.3 需要 JDK 的一些檔案,所以建立需要的 jdk mo 檔,這個檔約需要 130M 的空間來解開,所以要注意一下空間。

  1. cd /mnt/hda1
  2. wget jdk-1_5_0_08-linux-i586.bin
  3. chmod +x jdk-1_5_0_08-linux-i586.bin
  4. cd /mnt/hda1/work
  5. mkdir -p jdk/usr/local
  6. cd jdk/usr/local/
  7. /mnt/hda1/jdk-1_5_0_08-linux-i586.bin
  8. jdk1.5.0_08/bin/java -version
  9. cd /mnt/hda1/work
  10. dir2mo jdk jdk-1_5_0_08-linux.mo
  11. uselivemod jdk-1_5_0_08-linux.mo
  12. /usr/local/jdk1.5.0_08/bin/java -version

Create the openssl mo

另外也需要 openssl,爆米花只有裝精簡版,換上完整版。

  1. search openssl in http://slackware.it/en/pb/
  2. wget openssl-0.9.8b-i486-1.tgz
  3. cd /mnt/hda1/work
  4. mkdir openssl
  5. installpkg -root openssl /mnt/hda1/openssl-0.9.8b-i486-1.tgz
  6. dir2mo openssl openssl-0.9.8b.mo
  7. uselivemod openssl-0.9.8b.mo

install Apache Portable Runtime

編譯之前需要 Apache Portable Runtime

  1. apache-tomcat-5.5.17/bin/shutdown.sh
  2. uselivemod /mnt/hda1/Official_Development_module_5_1_4.mo
  3. cd /mnt/hda1
  4. wget apr-1.2.7.tar.bz2
  5. tar jxvf apr-1.2.7.tar.bz2
  6. cd apr-1.2.7
  7. ./configure
  8. make
  9. make install

預設會裝到 /usr/local/apr/

install tomcat native

  1. cd apache-tomcat-5.5.17/bin/
  2. tar zxvf tomcat-native.tar.gz
  3. cd tomcat-native-1.1.3/jni/native
  4. ./configure—with-apr=/usr/local/apr—with-java-home=/usr/local/jdk1.5.0_08
  5. make
  6. make install
  7. ls /usr/local/apr/lib

關鍵在於環境變數 LD_LIBRARY_PATH,只要設對,tomcat 就會啟動 APR

  1. export LD_LIBRARY_PATH=/usr/local/apr/lib
  2. cd /mnt/hda1/apache-tomcat-5.5.17
  3. bin/startup.sh
  4. tail -100 logs/catalina.out
  5. bin/shutdown.sh

catalina.out 可以看出差異,非 APR 的版本可以找到 Http11BaseProtocol start 字眼,有 APR 的版本可以找出 Http11AprProtocol start。

make apr-tcnative.mo

既然直接編譯可以裝,必須轉成 mo 測看看,這裡將 apr-1.2.7 與 tomcat-native-1.1.3 兩個安裝一起後包成 apr-tcnative-1.1.3.mo 來用。

  1. cd /mnt/hda1/apr-1.2.7
  2. checkinstall
  3. mv apr-1.2.7-i386-1.tgz /mnt/hda1
  4. cd /mnt/hda1/apache-tomcat-5.5.17/
  5. cd bin/tomcat-native-1.1.3/jni/native/
  6. checkinstall
  7. mv native-native-i386-1.tgz /mnt/hda1/tomcat-native-i386-1.tgz
  8. cd /mnt/hda1/work
  9. mkdir apr-tcnative
  10. installpkg -root apr-tcnative ../apr-1.2.7-i386-1.tgz
  11. installpkg -root apr-tcnative ../tomcat-native-i386-1.tgz
  12. dir2mo apr-tcnative apr-tcnative-1.1.3.mo
  13. reboot for test

make tomcat.mo

重開後測試 apr-tcnative-1.1.3.mo 可以的話,就準備改一下 tomcat 來包 apache-tomcat-5.5.15.mo,讓啟動 APR 模式比較簡單。

  1. cd /mnt/hda1/work
  2. mkdir -p tomcat/usr/local
  3. cd tomcat/usr/local
  4. tar zxvf ../apache-tomcat-5.5.17.tar.gz
  5. cd apache-tomcat-5.5.17
  6. vi bin/catalina.sh

這裡有個考量,必須指名 JAVA_HOME 的位置,而這個位置卻是每次裝新的 JRE 都會更換的,所以設到 /usr/local/java,加上下面一行。

export JAVA_HOME=/usr/local/java

  1. uselivemod jre-1_5_0_08-linux.mo
  2. uselivemod apr-tcnative-1.1.3.mo
  3. cd bin
  4. cp startup.sh startapr.sh
  5. vi startapr.sh

主要是把環境變數寫入,不用每次輸入,加上下面一行。

export LD_LIBRARY_PATH=/usr/local/apr/lib

開始測看看。

  1. ./startapr.sh
  2. tail -100 logs/catalina.out
  3. ./shutdown.sh

可以跑就準備包起來,同時做個捷徑 /usr/local/tomcat。

  1. cd /mnt/hda1/work
  2. cd tomcat/usr/local
  3. ln -s apache-tomcat-5.5.17 tomcat
  4. cd /mnt/hda1/work
  5. dir2mo tomcat apache-tomcat-5.5.17.mo
  6. reboot

final tomcat-native mo test run

重開後就可以把需要的 mo 載入跑看看。

  1. cd /mnt/hda1/work
  2. uselivemod jre-1_5_0_08-linux.mo
  3. uselivemod apr-tcnative-1.1.3.mo
  4. uselivemod apache-tomcat-5.5.17.mo
  5. /usr/local/tomcat/bin/startapr.sh
  6. netstat -at
  7. tail -100 /usr/local/tomcat/logs/catalina.out
  8. uselivemod ttf-arphic-uming-0.1.mo
  9. uselivemod firefox-1.5.0.6-zh_TW.mo
  10. uselivemod gcin-1.2.5.mo
  11. ldconfig
  12. startx
  13. firefox to http://127.0.0.1:8080/

Download

下面軟體都是 Apache 改作,所以採 Apache License 釋出,非本站慣用 授權

apr-tcnative-1.1.3.mo [860K]

apache-tomcat-5.5.17.mo [5964K]

dsl-n with java extension

0

dsl-n

主要差別是核心 2.6 與 gtk2 內建。

READ FIRST : dsl in vmware player

create vm

  1. wget dsl-n-01RC4.iso
  2. cp dsl.vmx from dsl-3.0.1-vmx
  3. cp qemu-img.500mb
  4. modify dsl.vmx with hda info.
  5. vmplayer dsl.vmx

setup network

  1. make sure vmplayer’s nat network address.
  2. sudo su
  3. netcardconfig
  4. ifconfig
  5. ping gateway

mount vmdk file and upload jre_xxx.bin

  1. sudo su
  2. dmesg | grep hd
  3. fdisk /dev/hda
  4. mke2fs /dev/hda1
  5. mount /dev/hda1 /mnt/hda
  6. passwd
  7. /etc/init.d/ssh start
  8. netstat -at
  9. scp jre_xxx.bin in guest os from host os.

install java to /opt

  1. cd /opt
  2. chmod +x /mnt/hda/jre_xxx.bin
  3. sh /mnt/hda/jre_xxx.bin
  4. /opt/jre_xxx/bin/java -version

mk dsl extension

  1. mkdir -p /mnt/hda/work/opt
  2. cd /mnt/hda/work
  3. cp -Pr /opt/jre_xxx ./opt/
  4. chown -R 0.0 ./opt/
  5. find . > files.txt
  6. vi files.txt with many dd work (. and ./files.txt and some man page)
  7. tar cvf java.tar—no-recursion—numeric-owner -T files.txt
  8. gzip -9 java.tar
  9. ls
  10. shutdown -h now

test load java dsl extension

  1. vmplayer dsl.vmx
  2. click and F2 to setup bios boot order (cdrom first and one time job)
  3. mount /mnt/hda1
  4. su dsl
  5. mydsl-load /mnt/hda1/work/java.tar.gz
  6. /opt/java_xxx/bin/java -version

links

wiki about extension

Creating a Compressed Extension from Source

Older posts: 1 ... 5 6 7 8