Apache2的配置Apache2.2和resin 3.1,windows平臺單機作負載平衡html
Apache2.2和resin 3.1,windows平臺單機作負載平衡web
apache版本:2.2.6(Win32)
resin版本:3.1.3apache
1.安裝apache.我下載的是apache的windows安裝包,因此直接運行後,apache會自動被安裝成windows服務,這裏服務名我定爲apache2.2windows
2.下載resin3.1.3 windows版,解壓到硬盤上某個目錄中瀏覽器
3.在resin目錄下的win32\apache-2.2中有個文件:mod_caucho.dll,記住這個文件的全路徑和文件名(e.g.:記在notepad中).好比,在我機器上,要記下的內容爲:c:\resin-app
3.1.3\win32\apache-2.2\mod_caucho.dll,而後,把路徑中的反斜槓改成斜槓,因此,最後,要記錄下的內容爲:c:/resin-3.1.3/win32/apache-2.2/mod_caucho.dll負載均衡
4.修改resin的配置文件resin.conf
在resin2中,查看網上的一些資料,發現配置負載平衡是用<srun/>這個配置項,但在resin3中,配置文件已經全面變更,負載平衡改用<server/>
這裏以在一臺機器上運行4個resin實例爲例
a.在resin.conf中找尋內容<!-- define the servers in the cluster -->,在這行的下面一行內容是<server id="" address="127.0.0.1" port="6800"/>,這行其實jsp
就說明運行一個resin實例,因此這裏咱們要改爲四個<server/>,以下:
<server id='a' address='127.0.0.1' port='6801' watchdog-port="6601">
<http port="8081"/>
</server>
<server id='b' address='127.0.0.1' port='6802' watchdog-port="6602">
<http port="8082"/>
</server>
<server id='c' address='127.0.0.1' port='6803' watchdog-port="6603">
<http port="8083"/>
</server>
<server id='d' address='127.0.0.1' port='6804' watchdog-port="6604">
<http port="8084"/>
</server>
id標識了不一樣的server,這裏的四個id能夠隨便改,只要不同就行
port標識了不一樣的監聽端口,apache會把須要resin處理的http請求轉發到此端口(不知道理解得對不對,若是有高人有別的見解,歡迎批評指正),這裏的端口也可ide
以改成別的端口號
watchdog-port是resin watchdog的監聽端口,每啓動一個resin實例,就會伴隨啓動一個resin的watchdog,watchdog也須要分配一個端口,watchdog好像是監視測試
resin服務的,它有自動啓動和中止resin服務的功能,他的默認端口爲6600,若是不指定這些端口,在日誌文件中會看到JVM端口綁定錯誤,並且指明瞭是6600端口綁定錯誤
<http port="端口號"/>,這個指定了每一個resin的http偵聽端口,也須要指定來進行區分,不然也會出現端口綁定錯誤
b.查找行<http address="*" port="8080"/>,這裏指定了默認的resin監聽端口,這裏須要把這行註釋掉
c.接下來,你能夠用<web-app/>按通常方式來配置resin的web應用
5.修改apache的配置文件httpd.conf
在httpd.conf的最後,加上以下的內容:
LoadModule caucho_module C:/resin-3.1.3/win32/apache-2.2/mod_caucho.dll
ResinConfigServer 127.0.0.1 6801
ResinConfigServer 127.0.0.1 6802
ResinConfigServer 127.0.0.1 6803
ResinConfigServer 127.0.0.1 6804
CauchoStatus yes
能夠看到,第3步中記錄的內容就是放在這個地方的
接下來,在httpd.conf加入你在resin.conf配置的web應用的目錄的虛擬目錄配置
通常加在DocumentRoot這行下面
Alias /web-app "D:/work/web-app"
<Directory "D:/work/web-app">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
這裏假設你在resin.conf中也配置了web-app目錄的web應用
這樣,當你訪問http://localhost/web-app時,一些不須要由resin處理的內容,如靜態頁面,jpg等,則由apache處理,而像jsp文件,則apache會交給resin處理.這裏
主要是起到了一個resin應用目錄和apache虛擬目錄相對應的設置。固然,也能夠經過配置虛擬主機來實現
apache默認文檔的配置:
找到DirectoryIndex這個項,在後面寫上你要設置的默認文檔,好比
DirectoryIndex index.jsp
6.把resin安裝成windows服務
這裏把resin安裝成四個服務
進入windows的命令行,進行resin目錄,執行以下命令:
httpd -install-as resin-a -server a //這裏的-server後面的a就和resin.conf中的<server id="a"中的a對應
httpd -install-as resin-b -server b
httpd -install-as resin-c -server c
httpd -install-as resin-d -server d
7.啓動apache和四個resin
進入windows的命令行,執行以下命令:
net start apache2.2
net start resin-a
net start resin-b
net start resin-c
net start resin-d
8.在瀏覽器中輸入http://localhost/caucho-status,若是看到host列的四個都爲綠色,則表求配置成功,
你能夠輸入你web應用的目錄來進行測試了
在項目文件中新建test.jsp測試腳本,內容以下:
2+2=<%=2+2%>
而後訪問http://192.168.1.166/test.jsp輸出的是2+2=4說明apache和rensin整合成功!
文章轉帳自:http://boris-song.iteye.com/blog/1740241