国产一级一区二区_segui88久久综合9999_97久久夜色精品国产_欧美色网一区二区

掃一掃
關注微信公眾號

Apache服務器之JSP架構篇
2007-09-24   網絡

本文主要討論在紅帽企業 Linux AS4的環境中使用Apache和 Tomcat服務器軟件來架構JSP網站。
要讓Apache和Tomcat聯合工作,還必需有一個連接器(Connector)把它們聯系起來,目前大致上有JK1.x,JK2,mod_webapp三種connector可以使用。jk 是mod_jserv的替代者,它是Tomcat-Apache插件,處理Tomcat和Apache之間的通信。JK使用比較廣泛,JK2是JK1.x的改進,比較新。這三種Connector的配置方法大相徑庭,另外,Tomcat是用Java寫的,所以我們的操作系統必須有JDK或JRE。

紅帽企業 Linux AS4的已經內置的RPM(Red Hat Package Manager)版的Apache服務器,版本為2.0.52(如圖1);由于我們要在 Apache中整合tomcat,必須要下載Apache的tar.gz文件格式的源代碼版,重新編譯安裝,編譯采用允許動態加載模塊的方式,主要是為了加載mod_jk2這個整合模塊。因為默認的已經編譯好的RPM版的Apache不能加載mod_jk2模塊。


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖1


在這里我們在下載Apache的源代碼版(Linux)為2.0.54版本(如圖2),下載Tomcat 5.5.9的tar.gz文件格式的源代碼版(如圖3), Apache 和 Tomcat整合的連接器在本文中我們選用JK2,下載的版本為2.0.4(如圖4);由于Tomcat需要java的運行環境,下載J2SE 5的升級3版即JDK 1.5.0_03(如圖5)。

將這4個下載文件拷貝到/ghq目錄,下面我們就可以進行安裝了。


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖2


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>

圖3



""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖4



""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖5

軟件的安裝與配置

1、Apache服務器的安裝

打開一個終端,進入到ghq目錄下,解壓httpd-2.0.54.tar.gz,然后編譯安裝。
[root@www ~]#cd /ghq (進入ghq目錄)
[root@www ghq]#tar –zxvf httpd-2.0.54.tar.gz (解開.tar.gz 壓縮文件)
[root@www ghq]#cd httpd-2.0.54 (切換到解開目錄下)
[root@www httpd-2.0.54]#./configure –prefix=/ghq/apache2 –-enable-mods-shared=all –-enable-so (執行組態配置文件,編譯的Apache服務器軟件安裝在/ghq/apache2目錄下,允許動態加載so模塊,選擇所需要的所有模塊,如圖6所示)


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖6
[root@www httpd-2.0.54]#make (編譯Apache服務器的相關文件,如圖7所示)


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖7
[root@www httpd-2.0.54]#make install (將Apache服務器安裝到紅帽企業 Linux AS4系統,如圖8所示)


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖8

2、Tomcat獨立運行環境的安裝與配置

① 安裝JDK

[root@www ~]#cd /ghq (進入ghq目錄)
[root@www ghq]#chmod 711 jdk-1_5_0-03-Linux-i586-1.bin(使JDK具有執行權)
[root@www ghq]#./ jdk-1_5_0-03-Linux-i586-1.bin(運行JDK程序,如圖9和圖10所示)


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖9


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>

圖10

JDK被安裝到/ghq/jdk1.5.0_03目錄下。

② 安裝Tomcat軟件

[root@www ~]#cd /ghq (進入ghq目錄)
[root@www ghq]#tar –zxvf Jakarta-tomcat-5.5.9.tar.gz (解開Tomcat壓縮文件,如圖11所示)


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>

圖11

[root@www ghq]#cd Jakarta-tomcat-5.5.9 (進入tomcat目錄)
[root@www Jakarta-tomcat-5.5.9]#ls (查看tomcat目錄下的文件目錄系統)

③ 設置環境變量

[root@www Jakarta-tomcat-5.5.9]#vi ~/.bash_profile
設置好Java和Tomcat運行的目錄和路徑,以及環境變量,如下圖12所示,然后保存此文件。


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖12

[root@www Jakarta-tomcat-5.5.9]. ~/.bash_profile(執行此文件,讓設置有效)
[root@www Jakarta-tomcat-5.5.9]java –version (查看目前Java運行的版本,如圖13所示)


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖13


3、整合Apache 和 Tomcat 服務器軟件

① 連接器的解壓與配置

[root@www ghq]#tar–zxvf Jakarta-tomcat-connectors-jk2-src-
current.tar.gz (解開connectors壓縮文件,如圖14所示)



""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>

圖14



[root@www ghq]#cd Jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2(進入連接器目錄中)
[root@www native2]#./configure --with-apxs2=/ghq/apache2/bin/apxs --with-apr-lib=/ghq/apache2/bin --with-tomcat-559=/ghq/tomcat5.5.9 --with-java-home=/ghq/jdk1.5.0_03 --with-jni(執行組態配置文件,編譯apache 、Tomcat和JDK的運行目錄和路徑,如圖15所示)


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖15


② Makefile文件的修改與編譯,mod_jk2模塊so文件的生成

[root@www native2]# cd server/apache2 (進入server目錄中apache2目錄)
[root@www apache2]# vi Makefile 文件如下圖16所示,然后保存此文件。




""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖16


[root@www native2]# make (編譯connectors,產生mod_jk2.so文件,如下圖17所示。)



""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>

圖17



將編譯生成的兩個文件(jkjni.so、mod_jk2.so)拷貝到/ghq/apache的modules目錄,這兩個文件就是負責Tomcat和Apache通信的,如下圖18、19所示。



""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>

圖18





""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>


圖19

Apache和Tomcat配置與測試

1、Apache的httpd.conf和workers2.properties文件的配置

打開/ghq/apache2/conf目錄下的httpd.conf文件,首先將監聽端口listen修改為9000,在LoadModule后添加一行,LoadModule jk2_module modules/mod_jk2.so,如圖20所示,然后保存此文件。


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖20

在/ghq/apache2/conf目錄下的創建workers2.properties文件,主要是在Apache服務器里添加Tomcat的虛擬目錄,如圖21所示。


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖21


2、Tomcat的jk2.properties配置

[root@www native2]# cd /ghq/Jakarta-tomcat-5.5.9/conf
[root@www conf]# vi jk2.properties
對Tomcat的jk2.properties進行配置,只需要修改一行,找到shm.file,去掉該行的注釋符,并將路徑改為/ghq/apache2/logs/jk2.shm,如圖22所示。


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖22

3、啟動Apache和Tomcat服務并進行測試

① 啟動Tomcat服務并進行測試

[root@www conf]# cd /ghq/Jakarta-tomcat-5.5.9/bin
[root@www bin]# ./startup.sh
如下圖23所示。


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖23

啟動Tomcat獨立的運行環境,用8080端口進行測試,如圖24所示。


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖24


②啟動Apache服務并進行測試

[root@www bin]# cd /ghq/apache2/bin
[root@www bin]# ./apachectl start
如下圖25所示。


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖25

啟動Apache的運行環境,用9000端口進行測試,如圖26所示。


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖26

③ Apache+Tomcat整合測試

在這里我們就以Tomcat本身帶的jsp-examples中的date.jsp例子來測試。首先我們用Tomcat(8080)來測試,如下圖27所示,說明Tomcat服務器能解析JSP文件;然后將date.jsp文件拷貝到/ghq/apache2/htdocs目錄中,用Apache(9000)來測試,如圖28、29所示,說明Apache服務器單獨不能解析JSP文件;最后采用Apache+Tomcat整合來測試date.jsp例子,如圖30所示,說明整合在一起可以解析JSP文件。


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖27



""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖28



""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖29


""screen.width*0.5) {this.resized=true; this.width=screen.width*0.5;}" border=0>
圖30

至此Apache+Tomcat整合環境架構步驟就已全部完成。

熱詞搜索:

上一篇:Apache服務器學習之PHP應用
下一篇:Xitami Web服務器,比Apache更快捷

分享到: 收藏
主站蜘蛛池模板: 赤壁市| 镇安县| 濉溪县| 吴江市| 辽阳县| 石嘴山市| 洛宁县| 儋州市| 济宁市| 墨江| 安塞县| 凯里市| 赫章县| 光山县| 航空| 孝感市| 且末县| 七台河市| 明星| 寿光市| 南澳县| 从江县| 汉沽区| 专栏| 博爱县| 桓仁| 崇仁县| 田阳县| 高唐县| 海安县| 南京市| 霍邱县| 东平县| 信宜市| 安平县| 岳池县| 南雄市| 麦盖提县| 习水县| 项城市| 池州市|