|
參考資料: 通常,將Apache與Tomcat整合主要出于以下幾個原因: 而關(guān)于Apache與Tomcat整合,有3種方式可以實現(xiàn): 2. http_proxy 3. ajp_proxy 下面是具體的配置過程: 1. 安裝配置Apache # tar xjvf httpd-2.2.18.tar.bz2 # cd httpd-2.2.18 # make 創(chuàng)建apache用戶 修改apache配置文件,讓它以用戶apache身份運行 2. 通過 Apache mod_jk 方式實現(xiàn)與Tomcat整合 # cp ./apache-2.0/mod_jk.so /opt/apache2/modules/ # cd /opt/apache2/conf/ # Load the jk module LoadModule jk_module modules/mod_jk.so # The location of workers.properties JkWorkersFile conf/extra/httpd-jk-workers.properties # The location of jk logs JkLogFile logs/httpd-jk.log # The location of jk mount file JkMountFile conf/extra/httpd-jk-uriworkermap.properties # The jk log level [debug/error/info] JkLogLevel info # The log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y]" # JkOptions indicate to send SSL KEY SIZE, JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories # JkRequestLogFormat set the request format JkRequestLogFormat "%w %V %T" 創(chuàng)建 mod_jk 集群參數(shù)配置文件 # list the workers by name worker.list=DLOG4J, status #創(chuàng)建名為DLOG4J與status的worker # localhost server 1 # ------------------------ worker.s1.port=8009 #后端Tomcat服務(wù)器的默認(rèn)AJP端口 worker.s1.host=192.168.203.133 #后端Tomcat服務(wù)器的IP worker.s1.type=ajp13 #采用AJP協(xié)議進(jìn)行通信 # localhost server 2 # ------------------------ worker.s2.port=8009 #后端Tomcat服務(wù)器的默認(rèn)AJP端口 worker.s2.host=192.168.203.135 #后端Tomcat服務(wù)器的IP worker.s2.type=ajp13 #采用AJP協(xié)議進(jìn)行通信 #worker.s2.stopped=1 #是否暫停該服務(wù)器的開關(guān) worker.DLOG4J.type=lb #采用負(fù)載均衡的方式 worker.retries=3 worker.DLOG4J.balanced_workers=s1, s2 #負(fù)載均衡中包括server 1與server 2兩臺Tomcat服務(wù)器 worker.DLOG4J.sticky_session=1 worker.status.type=status #在worker status中對集群狀態(tài)進(jìn)行監(jiān)控 創(chuàng)建 mod_jk URL參數(shù)文件 /*=DLOG4J #所有的請求都交給DLOG4J處理 /jkstatus=status #在/jkstatus頁面中監(jiān)控集群狀態(tài) !/*.gif=DLOG4J #過濾gif !/*.jpg=DLOG4J #過濾jpg !/*.png=DLOG4J #過濾png !/*.css=DLOG4J #過濾css !/*.js=DLOG4J #過濾js !/*.htm=DLOG4J #過濾htm !/*.html=DLOG4J #過濾html 修改Apache主配置文件,使其關(guān)聯(lián)mod_jk主配置文件 # The JK connector settings Include conf/extra/httpd-jk.conf 啟動Apache 通過統(tǒng)計監(jiān)聽頁面,可以看到后端服務(wù)器的狀態(tài),如下圖所示: 通過瀏覽器訪問http://192.168.203.134/index.jsp,可以發(fā)現(xiàn),在多次刷新之后,請求會隨機(jī)分配到后端的Tomcat服務(wù)器上。 2. 通過 Apache mod_proxy 方式實現(xiàn)與Tomcat整合 添加完成后,在httpd.conf中可以看到以下配置: # cd /opt/apache2/conf/ 創(chuàng)建 mod_proxy 主配置文件 ProxyPassMatch /*.gif$ ! #過濾gif ProxyPassMatch /*.jpg$ ! #過濾jpg ProxyPassMatch /*.png$ ! #過濾png ProxyPassMatch /*.css$ ! #過濾css ProxyPassMatch /*.js$ ! #過濾js ProxyPassMatch /*.htm$ ! #過濾htm ProxyPassMatch /*.html$ ! #過濾html ProxyPass /server-status ! #過濾server-stauts監(jiān)控頁面 ProxyPass /balancer-manager ! #過濾balancer-manager監(jiān)控頁面 ProxyPass / balancer://cluster/ #創(chuàng)建集群cluster <Proxy balancer://cluster/> BalancerMember http://192.168.203.133:8080/ #設(shè)置cluster成員 BalancerMember http://192.168.203.135:8080/ #設(shè)置cluster成員 </Proxy> <Location /server-status> #設(shè)置server-stauts監(jiān)控頁面 SetHandler server-status Order Deny,Allow Deny from all Allow from all </Location> <Location /balancer-manager> #設(shè)置balancer-manager監(jiān)控頁面 SetHandler balancer-manager Order Deny,Allow Deny from all Allow from all </Location> 修改Apache主配置文件,使其關(guān)聯(lián)mod_proxy主配置文件 # The Proxy settings Include conf/extra/httpd-proxy.conf 啟動Apache 通過監(jiān)控頁面,可以看到后端服務(wù)器的狀態(tài),如下圖所示: 通過瀏覽器訪問http://192.168.203.134/index.jsp,可以發(fā)現(xiàn),在多次刷新之后,請求會隨機(jī)分配到后端的Tomcat服務(wù)器上。 3. 通過 Apache mod_proxy_ajp 方式實現(xiàn)與Tomcat整合 ... ProxyPass / balancer://cluster/ <Proxy balancer://cluster/> BalancerMember ajp://192.168.203.133:8009/ BalancerMember ajp://192.168.203.135:8009/ </Proxy> ... 4. 其它 |
|
|