|
|
| apache+resin+pureftp的虚拟主机和负载均衡 |
作者:peng
文章来源:bbs.chinaunix.net
访问次数:15482次
加入时间:2004年09月18日
|
|
apache+resin来做想来大家都比较熟悉了,一般的配置都是很熟悉的了,我查看了一些论坛上的文章,这方便的文章比较多。在这里,我只要写写apache+resin实现独立的虚拟主机和resin自带的负载均衡。
2、系统和环境: redhat9 and solaris9 httpd-2.50 resin-3.06 pure-ftpd-1.0.17a.tar.gz 3、安装软件:
3.1、安装apache:
# tar zxvf httpd-2.49.tar.gz # cd httpd-2.49 # ./configure --prefix=/usr/local/apache2 --enable-so --with-mpm=worker # make # make install
3.2、安装resin:
# tar zxvf resin-3.06.tar.gz # cd resin03.06 # ./configure --prefix=/usr/local/resin --with-apxs=/usr/local/apache2/bin/apxs # make # make install
3.3、安装pureftp
# tar zxvf pure-ftpd-1.0.17a.tar.gz # cd pure-ftpd-1.0.17a # ./configure --prefix=/usr/local/pureftpd --without-inetd --with-puredb --with-cookie --with-throttling --with-ratios --with-quotas --with-ftpwho --with-largefile --with-welcomemsg # make # make install # mkdir /usr/local/pureftpd/etc
4、配置软件:
目的:用apache和resin做基于域名的虚拟主机,启用resin自身的负载均衡的引擎。resin的负载均衡引擎实际上是可以启动多个java响应进程,通过内部机制来进行负载均衡。
4.1、配置apache:
# vi /usr/local/apache2/conf/httpd.conf --------------------------------------- DirctoryIndex index.html index.jsp AddDefaultCharset Off User nobody Group nobody NamevirtualHost 211.11.11.11 <VirtualHost 211.11.11.11:80> ServerAdmin peng.zhang@bj.china.com DocumentRoot /data/web/xcity ServerName xcity.chinaunix.com ErrorLog logs/xcity.chinaunix.com-error_log CustomLog logs/xcity.chinaunix.com-access_log common </VirtualHost>
<VirtualHost 211.11.11.11:80> ServerAdmin peng.zhang@bj.china.com DocumentRoot /data/web/sports ServerName sports.chinaunix.com ErrorLog logs/sports.chinaunix.com-error_log CustomLog logs/sports.chinaunix.com-access_log common </VirtualHost> ........ .... # mod_caucho Resin Configuration #
LoadModule caucho_module /usr/local/apache2/modules/mod_caucho.so
ResinConfigServer 127.0.0.1 ---------------------------------------
4.2、配置resin:
# vi /usr/local/resin/conf/resin.conf ----------------------------------------
<cluster> <srun id="a" host="127.0.0.1" port="6801" index="1"/> <srun id="b" host="127.0.0.1" port="6802" index="2"/> <srun id="c" host="127.0.0.1" port="6803" index="3"/> <srun id="d" host="127.0.0.1" port="6804" index="4"/> </cluster>
---注解: (这里面,我用了系统本身的127.0.0.1,绑定了4个端口做伏在均衡。还可以用不同的ip地址和同一端口,来作。例如: <cluster> <srun id="a" host="211.11.11.11" port="6802" index="1"/> <srun id="b" host="211.11.11.12" port="6802" index="2"/> <srun id="c" host="211.11.11.13" port="6802" index="3"/> <srun id="d" host="211.11.11.14" port="6802" index="4"/> </cluster> 还有些人,喜欢在apache中设置每一个java进程服务一个虚拟,这里我们不推荐,这样做,就会失去引擎本身的意义。)
<!-- configures the default host, matching any host name --> <host id='xcity.chinaunix.com'> <document-directory>/data/web/xcity</document-directory> <!-- configures the root web-app --> <web-app id='/'> <!-- adds xsl to the search path --> <class-loader> <simple-loader path="$host-root/xsl"/> </class-loader> <servlet-mapping url-pattern="/servlet/*" servlet-name="invoker"/> </web-app> </host>
<host id='sports.chinaunix.com'> <document-directory>/opt/web/sports</document-directory> <!-- configures the root web-app --> <web-app id='/'> <!-- adds xsl to the search path --> <class-loader> <simple-loader path="$host-root/xsl"/> </class-loader> <servlet-mapping url-pattern="/servlet/*" servlet-name="invoker"/> </web-app> </host> ........ ....
--------------------------------------------------
---注:这里面是基于域名的虚拟主机,如果是针对ip的虚拟主机,在<host id='*.*.*.*'>中,就应该是对应虚拟主机的ip了。也就是说,apache和resin关于虚拟主机的地方要保持一致。还有,在resin中,对于每个虚拟主机所用的web-app目录,其实是相对于她的家目录下的/目录。
4.3、配置pureftp 1、添加用户: # pure-pw useradd xcityr -f /usr/local/pureftp/etc/ftppasswd -u nobody -g nobody -d /data/web/xcity -m
# pure-pw useradd sports -f /usr/local/pureftp/etc/ftppasswd -u nobody -g nobody -d /data/web/sports -m
---注:xcity :ftp用户 -f ftppasswd:存放用户密码信息的文件 -u 用户uid 一般是系统的一个用户,就是你的ftp用户的家目录的用户 -g 用户组id -d 锁定用户在家目录 -m 使pureftp.d.passwd写进pureftpd.pdb,使更改生效。
*修改用户: # pure-pw usermod --help
*删除用户: # pure-pw userdel <login> [-f <passwd file>] [-m]
*更改拥护密码:
# pure-pw passwd <login> [-f <passwd file>] [-m]
*查看用户详细内容:
# pure-pw show <login> [-f <passwd file>]
*生成db文件,使密码生效: # pure-pw mkdb [<puredb database file> [-f <passwd file>]]
*列出所有用户: # pure-pw list [-f <passwd file>]
5、启动脚本:
当系统在solaris下:
apache和resin的启动脚本: # vi /etc/rc2.d/S99webapp ------------------------------- /usr/local/resin/bin/httpd.sh -pid srun1.pid -server a start /usr/local/resin/bin/httpd.sh -pid srun2.pid -server b start /usr/local/resin/bin/httpd.sh -pid srun3.pid -server c start /usr/local/resin/bin/httpd.sh -pid srun4.pid -server d start /usr/local/apache2/bin/apachectl start --------------------------------
pureftp启动脚本: -------------------------------- #!/bin/sh
/usr/local/pureftpd/sbin/pure-ftpd -j -lpuredb:/usr/local/pureftpd/etc/pureftpd.pdb & -----------------------------------
在linux下,直接放到响应的开机启动等级目录下就ok了。
6、总结 apache+resin应该是个很好的java应用平台了。实际使用中,还是有很多技巧。看了resin官方论坛的一些资料,说resin3.x以上的版本,对image和html的支持,比apache响应更快。我对此测试过,感觉还是有所欠缺。所以说,在大型一点的发布平台上,还是要apache和resin结合比较好。 对于resin的负载均衡使用上启动的进程数,我认为还是要根据自己的机器实际情况来考虑的。少了达不到效果,多了会机器系统也是一个负载。个人认为,4个可以作为一个默认的选择来考虑。
|
|
|