Apache +Jetty的负载均衡与集群配置

smallwhale 2011-07-13

一.搭配环境

(一).jetty的安装和配置

Jetty_a: 192.168.55.229

Jetty_b: 192.168.55.231

Apache +Jetty的负载均衡与集群配置

(1)安装jdk

下载将jdk加压后放到/usr/local目录下:

建立/usr/local/下的jdk软链接方便以后版本升级 :

(2)安装apache-maven,并设置环境变量

添加以下内容:

JAVA_HOME=/usr/local/jdk1.6.0_05

JAVA_BIN=/usr/local/jdk1.6.0_05/bin

PATH=$PATH:$JAVA_BIN:/usr/local/maven/bin

CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

JETTY_HOME=/usr/local/jetty

export JAVA_HOME JAVA_BIN PATH CLASSPATH JETTY_HOME

Apache Maven 2.2.1 (r801777; 2009-08-07 03:16:01+0800)

Java version: 1.6.0_05

Java home: /usr/local/jdk1.6.0_05/jre

Default locale: en_US, platform encoding: UTF-8

OS name: "linux" version: "2.6.18-238.el5" arch: "amd64" Family: "unix"

(3)安装启动jetty

Starting Jetty: STARTED Jetty Mon Jul 11 11:54:03 CST 2011

 

在浏览器中输入 http://192.168.55.229:8080/remote.html(这里加上remote.html的原因是避免和tomcat冲突,实际上http://192.168.55.229:8080也能够访问到,但是前提是必须把tomcat给禁掉。或者在jetty.xml中将端口改成9009,此时我们就可以直接访问http://192.168.55.229:9009)

(4)简单部署一个应用

Fgw

[root@node2 webapps]# cd fgw/

<%@ page contentType="text/html; charset=GBK" %>

<%@ page import="java.util.*" %>

<html><head><title>Cluster Test</title></head>

<body>

<%

  //HttpSession session = request.getSession(true);

  System.out.println(session.getCreationTime());

  out.println("<br> SESSION ID:" + session.getId()+"<br>");

  out.println("Session serviced by jetty_a"+"<br>");

  out.println("Session created time is :"+session.getCreationTime()+"<br>");

%>

</body>

</html>

测试:http://192.168.55.229:9009/fgw/

Apache +Jetty的负载均衡与集群配置

同样方法的配置jetty_b,测试结果为:

Apache +Jetty的负载均衡与集群配置

(二)Apache的安装和配置(采用源码编译安装的方式)

Apache的地址为:192.168.50.50

#tar xzvf httpd-2.2.17.tar.gz

            #cd  httpd-2.2.17

            # ./configure --with-ldap --enable-mods-shared="all ssl ldap cache proxy authn_alias mem_cache file_cache authnz_ldap charset_lite dav_lock disk_cache"【此选项为编译所有的模块】

1.  测试

/usr/local/apache2/conf/httpd.conf 中 设置 ServerName  localhost

#cd  /usr/local/apache2/bin

#./apachectl  start

将出现类似httpd (pid 17040) already running的输出

访问地址:http://192.168.50.50

It works!hehe...

说明已经成功~\(≧▽≦)/~啦啦啦,(~ o ~)~zZ

相关推荐