resin負(fù)載均衡搭構(gòu),全過程呈現(xiàn)
前面的鋪墊工作應(yīng)經(jīng)做好了,那么現(xiàn)在就是真正的resin負(fù)載均衡配置的過程了。在前面我們已經(jīng)介紹了相關(guān)的apache的一些設(shè)置內(nèi)容,不過它結(jié)合的是tomacat,那么其實兩者還有著一些相同之處,如果您感興趣的話可以跟之前文章進(jìn)行一下比較。
resin負(fù)載均衡配置軟件:
目的:用apache和resin做基于域名的虛擬主機,啟用resin自身的負(fù)載均衡的引擎。resin的負(fù)載均衡引擎實際上是可以啟動多個java響應(yīng)進(jìn)程,通過內(nèi)部機制來進(jìn)行負(fù)載均衡。
resin負(fù)載均衡配置1、配置apache:
#vi/usr/local/apache2/conf/httpd.conf
DirctoryIndexindex.htmlindex.jsp
AddDefaultCharsetOff
Usernobody
Groupnobody
NamevirtualHost211.11.11.11
<VirtualHost211.11.11.11:80>;
ServerAdminpeng.zhang@bj.china.com
DocumentRoot/data/web/xcity
ServerNamexcity.chinaunix.com
ErrorLoglogs/xcity.chinaunix.com-error_log
CustomLoglogs/xcity.chinaunix.com-access_logcommon
</VirtualHost>;<VirtualHost211.11.11.11:80>;
ServerAdminpeng.zhang@bj.china.com
DocumentRoot/data/web/sports
ServerNamesports.chinaunix.com
ErrorLoglogs/sports.chinaunix.com-error_log
CustomLoglogs/sports.chinaunix.com-access_logcommon
</VirtualHost>;
#mod_cauchoResinConfiguration
#LoadModulecaucho_module/usr/local/apache2/modules/mod_caucho.so
ResinConfigServer127.0.0.1
#p#resin負(fù)載均衡配置2、resin:
#vi/usr/local/resin/conf/resin.conf
<cluster>;
<srunid="a"host="127.0.0.1"port="6801"index="1"/>;
<srunid="b"host="127.0.0.1"port="6802"index="2"/>;
<srunid="c"host="127.0.0.1"port="6803"index="3"/>;
<srunid="d"host="127.0.0.1"port="6804"index="4"/>;
</cluster>;
注解:(這里面,我用了系統(tǒng)本身的127.0.0.1,綁定了4個端口做伏在均衡。還可以用不同的ip地址和同一端口,來作。例如:
<cluster>;
<srunid="a"host="211.11.11.11"port="6802"index="1"/>;
<srunid="b"host="211.11.11.12"port="6802"index="2"/>;
<srunid="c"host="211.11.11.13"port="6802"index="3"/>;
<srunid="d"host="211.11.11.14"port="6802"index="4"/>;
</cluster>;
還有些人,喜歡在apache中設(shè)置每一個java進(jìn)程服務(wù)一個虛擬,這里我們不推薦,這樣做,就會失去引擎本身的意義。)
<!--configuresthedefaulthost,matchinganyhostname-->;
<hostid='xcity.chinaunix.com'>;
<document-directory>;/data/web/xcity</document-directory>;
<!--configurestherootweb-app-->;
<web-appid='/'>;
<!--addsxsltothesearchpath-->;
<class-loader>;
<simple-loaderpath="$host-root/xsl"/>;
</class-loader>;
<servlet-mappingurl-pattern="/servlet/*"servlet-name="invoker"/>;
</web-app>;
</host>;<hostid='sports.chinaunix.com'>;
<document-directory>;/opt/web/sports</document-directory>;
<!--configurestherootweb-app-->;
<web-appid='/'>;
<!--addsxsltothesearchpath-->;
<class-loader>;
<simple-loaderpath="$host-root/xsl"/>;
</class-loader>;
<servlet-mappingurl-pattern="/servlet/*"servlet-name="invoker"/>;
</web-app>;
</host>;
注:這里面是基于域名的虛擬主機,如果是針對ip的虛擬主機,在<hostid='*.*.*.*'>;中,就應(yīng)該是對應(yīng)虛擬主機的ip了。也就是說,apache和resin關(guān)于虛擬主機的地方要保持一致。還有,在resin中,對于每個虛擬主機所用的web-app目錄,其實是相對于她的家目錄下的/目錄。#p#
resin負(fù)載均衡配置3、pureftp
1、添加用戶:
#pure-pwuseraddxcityr-f/usr/local/pureftp/etc/ftppasswd-unobody-gnobody-d/data/web/xcity-m
#pure-pwuseraddsports-f/usr/local/pureftp/etc/ftppasswd-unobody-gnobody-d/data/web/sports-m
注:xcity:ftp用戶
-fftppasswd:存放用戶密碼信息的文件
-u用戶uid一般是系統(tǒng)的一個用戶,就是你的ftp用戶的家目錄的用戶
-g用戶組id
-d鎖定用戶在家目錄
-m使pureftp.d.passwd寫進(jìn)pureftpd.pdb,使更改生效。
◆修改用戶:#pure-pwusermod--help
◆刪除用戶:#pure-pwuserdel<login>;[-f<passwdfile>;][-m]
◆更改擁護(hù)密碼:#pure-pwpasswd<login>;[-f<passwdfile>;][-m]
◆查看用戶詳細(xì)內(nèi)容:#pure-pwshow<login>;[-f<passwdfile>;]
◆生成db文件,使密碼生效:#pure-pwmkdb[<puredbdatabasefile>;[-f<passwdfile>;]]
◆列出所有用戶:#pure-pwlist[-f<passwdfile>;]#p#
啟動腳本:
當(dāng)系統(tǒng)在solaris下,apache和resin的啟動腳本:
- #vi/etc/rc2.d/S99webapp
- /usr/local/resin/bin/httpd.sh-pidsrun1.pid-serverastart
- /usr/local/resin/bin/httpd.sh-pidsrun2.pid-serverbstart
- /usr/local/resin/bin/httpd.sh-pidsrun3.pid-servercstart
- /usr/local/resin/bin/httpd.sh-pidsrun4.pid-serverdstart
- /usr/local/apache2/bin/apachectlstart
pureftp啟動腳本:
- #!/bin/sh
- /usr/local/pureftpd/sbin/pure-ftpd-j-lpuredb:/usr/local/pureftpd/etc/pureftpd.pdb&
在linux下,直接放到響應(yīng)的開機啟動等級目錄下就ok了。
resin負(fù)載均衡配置總結(jié)
apache+resin應(yīng)該是個很好的java應(yīng)用平臺了。實際使用中,還是有很多技巧。看了resin官方論壇的一些資料,說resin3.x以上的版本,對image和html的支持,比apache響應(yīng)更快。我對此測試過,感覺還是有所欠缺。所以說,在大型一點的發(fā)布平臺上,還是要apache和resin結(jié)合比較好。對于resin的負(fù)載均衡使用上啟動的進(jìn)程數(shù),我認(rèn)為還是要根據(jù)自己的機器實際情況來考慮的。少了達(dá)不到效果,多了會機器系統(tǒng)也是一個負(fù)載。個人認(rèn)為,4個可以作為一個默認(rèn)的選擇來考慮。