1 环境说明
1. 服务器有4台,一台内核的linux2.6.9安装apache,三台安装Tomcat。
2. apache2.2.4、apache-tomcat-5.5.17、jdk-6u1-linux-i586-rpm.bin或者jdk1.5.6
ip配置,一台安装apache的ip为180.200.1.189,三台安装tomcat的服务器ip分别为180.200.1.111/136/42。当然需要修改成你自己的IP地址。
3. 下载地址为
下载tomcat and apache
下载jdk
2 Tomcat安装
1. 在三台要安装tomcat的服务器上先安装jdk
2. 配置jdk的安装路径,在环境变量path中加入jdk的bin路径,新建环境变量JAVA_HOME指向jdk的安装路径
3. 在三台要安装tomcat的服务器上分别安装tomcat,调试三个tomcat到能够正常启动
3 Apache安装
解压httpd-2.2.4.tar.gz
在那台要安装apache的服务器上安装apache2.2.4。在home下建立apache目录,把httpd-2.2.4.tar.gz上传到该目录下
[root@localhost apache]# tar xvzf httpd-2.2.4.tar.gz
[root@localhost apache]# cd httpd-2.2.4
配置APACHE安装文件
这里需要注意编译前一定要将proxy proxy_http proxy_ftp proxy_connect headers这些参数加进去,以便编译出下面的so文件
mod_proxy.so
mod_proxy_connect.so
mod_proxy_http.so
mod_proxy_ftp.so
mod_proxy_ajp.so
mod_proxy_balancer.so
配置编译参数
[root@localhost apache]#./configure --prefix=/usr/local/apache224 --enable-so --enable-mods-shared="proxy proxy_http proxy_ftp proxy_connect headers"
编译
[root@localhost apache]# make
检查编译后的是否有编译出so文件
[root@localhost apache]# cd /usr/local/apache224/modules
[root@localhost modules]#]# ls
httpd.exp mod_proxy_ajp.so mod_proxy_connect.so mod_proxy_http.so
mod_headers.so mod_proxy_balancer.so mod_proxy_ftp.so mod_proxy.so
如果存在以上文件则说明编译成功
安装
[root@localhost apache]# make install
启动APACHE
[root@localhost apache]# /usr/local/apache224/bin/httpd -k start
测试
如果输出IT works那么就ok了
4 配置负载均衡
4.1. Tomcat配置
分别修改三个tomcat的配置文件conf/server.xml以便测试
修改内容如下:
修改前
<!-- An Engine represents the entry point (within Catalina) that processes<br /> every request. The Engine implementation for Tomcat stand alone<br /> analyzes the HTTP headers included with the request, and passes them<br /> on to the appropriate Host (virtual host). -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :<br /> <Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1"> <br /> -->
<!-- Define the top level container in our container hierarchy -->
修改后
<!-- An Engine represents the entry point (within Catalina) that processes<br /> every request. The Engine implementation for Tomcat stand alone<br /> analyzes the HTTP headers included with the request, and passes them<br /> on to the appropriate Host (virtual host). -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :-->
<!-- Define the top level container in our container hierarchy <br /> <Engine name="Catalina" defaultHost="localhost"><br /> -->
将其中的jvmRoute="jvm1"分别修改为jvmRoute="worker1"和jvmRoute=" worker2"和jvmRoute=" worker3"
然后重启三个tomcat,调试是否能够正常启动。
4.2. Apache配置
4.2.1. 启用代理
1. 配置代理模块
[root@localhost ~]#vi /usr/local/apache224/conf/httpd.conf
查找代理是否打开
/LoadModule proxy_module
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
如果被注释则需要打开注释,如果不存在则需要添加进去
查找httpd-vhosts.conf
/httpd-vhosts.conf
# Include conf/extra/httpd-vhosts.conf
打开注释
保存退出
:wq
4.2.2. 配置代理主机
[root@localhost ~]#vi /usr/local/apache224/conf/extra/httpd-vhosts.conf
#注释掉以下所有行
ServerAdmin webmaster@dummy-host.www.serviceapache.com
DocumentRoot /www/docs/dummy-host.www.serviceapache.com
ServerName dummy-host.www.serviceapache.com
ServerAlias www.dummy-host.www.serviceapache.com
ErrorLog logs/dummy-host.www.serviceapache.com-error_log
CustomLog logs/dummy-host.www.serviceapache.com-access_log common
ServerAdmin webmaster@dummy-host2.www.serviceapache.com
DocumentRoot /www/docs/dummy-host2.www.serviceapache.com
ServerName dummy-host2.www.serviceapache.com
ErrorLog logs/dummy-host2.www.serviceapache.com-error_log
CustomLog logs/dummy-host2.www.serviceapache.com-access_log common
#添加以下信息
ServerName localhost
CustomLog logs/dmim_log combined
BalancerMember ajp://180.200.1.111:9109
BalancerMember ajp://180.200.0.42:8009
BalancerMember ajp://180.200.0.136:9309
BalancerMember ajp://180.200.1.189:8009
ProxyPass balancer://localhost/
#保存退出
:wq
5 部署
5.1. 编写测试代码
在三个tomcat的安装目录中的webapps建立相同的应用,我和应用目录名为apa,在三个应用目录中建立相同 WEB-INF目录和页面index.jsp,index.jsp的页面内容如下
<!--page contentType="text/html; charset=GBK"-->
<!--page import="java.util.*"-->
posted on 2007-08-02 21:54
有猫相伴的日子 阅读(1347)
评论(1) 编辑 收藏 所属分类:
linux/unix应用