参考文章:
http://liujintao.blog.51cto.com/413051/86242
http://www.vvcha.cn/c.aspx?id=142036
http://keriny.javaeye.com/blog/814050
http://keriny.javaeye.com/blog/814029
研究在linux系统中安装apache和resin实现负载均衡
(1)实现环境和效果
本机IP:192.168.160.1
在虚拟机上安装两个linux系统,IP分别为:192.168.160.11和192.168.160.12
在192.168.160.11上安装apache和resin,在192.168.160.12中只安装resin
在apache上进行相关配置,实现负载均衡,访问http://192.168.160.11/a.jsp时,将处理分发给11或12。
软件版本httpd-2.2.4.tar.gz和resin-3.1.10.tar.gz
(2)安装apache
./configure --prefix=/usr/local/apache --enable-so --enable-dav --enable-dav-fs --enable-mods-shared=most
make
make install
(3)安装resin
./configure --prefix= /usr/local/ resin3.1 --with-apxs= /usr/local/apache /bin/apxs --with-apache= /usr/local/apache
make
make install
上述操作编译安装完后,会自动修改apache ,包括:
1.copy mod_caucho.so 到apache 目录(就是前面指定的--with-apache=/data/aoxj/artest/apache )的modules
2. 修改apache 的配置文件conf/httpd.conf ,自动增加以下内容
LoadModule caucho_module ***/modules/mod_caucho.so
ResinConfigServer localhost 6800
CauchoConfigCacheDirectory /tmp
CauchoStatus yes
(4)配置resin
# vi /usr/local/resin3.1/conf/resin.conf
在 <!-- define the servers in the cluster -->部分
192.168.160.11的设置如下 <server id="a" address="192.168.160.11" port="6800"/> 192.168.160.12的设置如下: <server id="a" address="192.168.160.12" port="6800"/> (5)配置apache 需要对192.168.160.11的apache配置文件httpd.conf进行修改 # vi /homel/apache/conf/httpd.conf (a)修改DirectoryIndex 找到配置文件中的DirectoryIndex配置: DirectoryIndex index.html index.html.var 增加index.jsp(动态页面),修改为: DirectoryIndex index.jsp index.html index.html.var (b)修改resin相关配置 在apache的配置文件httpd.conf最后增加以下内容 LoadModule caucho_module /home/apache/modules/mod_caucho.so ResinConfigServer 192.168.160.11 6800 ResinConfigServer 192.168.160.12 6800 CauchoConfigCacheDirectory /tmp CauchoStatus yes ResinConfigServer配置的是调用resin负载均衡器的IP地址和端口号, 192.168.160.11的apache前端服务器,分别调用了192.168.160.11和192.168.160.12两个Resin后端服务器 访问http://192.168.160.11/caucho-status,查看是否配置成功。 如图: (6)测试 在resin的webapps/ROOT目录下添加a.jsp文件。 192.168.160.11中的a.jsp <%System.out.println("server 192.168.160.11");%> 192.168.160.12中的a.jsp <%System.out.println("server 192.168.160.12");%> (a)启动apache: # /usr/local/apache/bin/apachectl start (b)启动resin IP:192.168.160.11 # cd /usr/local/resin3.1/bin # ./httpd.sh -server a start #-server后接参数a,为服务名。对应resin配置文件resin.conf中的 <server id="a" address="192.168.160.11" port="6800"/> IP:192.168.160.12 操作与192.168.160.11相同 访问apache(默认端口:80):http://192.168.160.11/a.jsp 分别查看192.168.160.11/192.168.160.12中的resin日志。是否都输出日志。 关闭其中一个resin服务查看是否正常。