tomcat集群配置

httpd-2.2.21.tar.gz

apache-tomcat-6.0.32.tar.gz

jdk-6u26-linux-i586.bin

jdk,和tomcat 环境配置忽略

a.在 /opt目录新增apache目录并将httpd-2.2.21.tar.gz copy到改目录中.

cd /opt 

mkdir apache

tar zxf  httpd-2.2.21.tar.gz 

cd httpd-2.2.21

 

【注意:安装APR
cd srclib/apr

#./configure --prefix=/usr/local/apr
#make
#make install

安装APR-util
cd srclib/apr-util

#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#make
#make install

# ./configure --prefix=/usr/local/apache
--enable-so --enable-mods-shared=all
--enable-cgi
--with-apr=/usr/local/apr
--with-apr-util=/usr/local/apr-util/bin

# make
#make install 】

 

然后配置 httped prefix

./configure --prefix=/opt/web/apache2 --enable-mods-shared=most # --prefix后面的红色路径可以根据实际情况自定义

然后屏幕会显示一大堆配置信息,完成后

make #开始编译

make install #编译后,进入安装阶段

cd /opt/solft/apache2/bin

./apachectl -k start #启动apache服务 

如果如下提示信息,代表成功了

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

在浏览器中输入http://127.0.0.1/ 就可以看到 It works!
b.开始安装 mod_proxy.so和mod_proxy_ajp.so,mod_proxy_balancer.so模块
cd /opt/apache/httpd-2.2.21/modules/proxy
/opt/web/apache2/ bin/apxs -i -a -c mod_proxy.c proxy_util.c
/opt/web/apache2/ bin/apxs -i -a -c mod_proxy_ajp.c ajp*.c
/opt/web/apache2/ bin/apxs -i -a -c mod_proxy_balancer.c
c.配置httpd.conf
vim /opt/web/apache2/conf/httpd.conf
ProxyPass /images ! 
ProxyPass /css ! 
ProxyPass /js !

ProxyRequests Off
ProxyPass /examples balancer://mycluster/ stickysession=JSESSIONID

ProxyPassReverse /examples balancer://mycluster/ stickysession=JSESSIONID
<Proxy balancer://mycluster>
     BalancerMember ajp://192.168.1.102:8009 /examples/ route=worker1 loadfactor=1
     BalancerMember ajp://192.168.1.102:8909 /examples/ route=worker2 loadfactor=1
</Proxy>
SetHandler balancer-manager

#上面ip端口红色部分与apache-tomcat-x.x.x/config/server.xml  中<Connector port="8009 " protocol="AJP/1.3" redirectPort="8443" /> 中的端口保持一直

d.编辑tomcat1/apache-tomcat-6.0.32/config/server.xml

server.xml文件,如果tomcat在不同机器上,则不需要修改,本人环境是本机上测试.所以其中的一个tomcat的端口一定要修改

需要修改的地方(红色部分)

<Connector port="8080 " protocol="HTTP/1.1"
             connectionTimeout="20000"
             redirectPort="8443" />

<Server port="8005 " shutdown="SHUTDOWN">

<Connector port="8009 " protocol="AJP/1.3" redirectPort="8443" />

把这段信息<Engine name="Catalina" defaultHost="localhost"/>

用下面的配置信息覆盖,如果在本机中红色端口需要修改,jvmRoute参数不能一样

<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1" >

 <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
          <Manager className="org.apache.catalina.ha.session.DeltaManager"
                   expireSessionsOnShutdown="false"
                   notifyListenersOnReplication="true"/>

          <Channel className="org.apache.catalina.tribes.group.GroupChannel">
            <Membership className="org.apache.catalina.tribes.membership.McastService"
                        address="228.0.0.4"
                        port="45564"
                        frequency="500"
                        dropTime="3000"/>
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                      address="192.168.1.102"
                      port="4000 "
                      autoBind="100"
                      selectorTimeout="5000"
                      maxThreads="6"/>

            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
              <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
            </Sender>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
          </Channel>

          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

    <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                    tempDir="/tmp/war-temp/"
                    deployDir="/tmp/war-deploy/"
                    watchDir="/tmp/war-listen/"
                    watchEnabled="false"/>
          <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
     </Cluster>

e.配置tomcat.x.x.x/webapps/examples/WEB-INF/web.xml,加上红色部分,以支持seesion复制

在<webapp>

   ...........

.........

<distributable/>

</webapp>

最后.复制tomcat下webapps下的文件到 /opt/web/apache2/htdocs

cp –R  /opt/web/tomcat1/apache-tomcat-6.0.32/webapps/* /opt/web/apache2/htdocs

到这里负载均衡和session复配置已经完成

开始启动 apache2

cd /opt/web/apache2/bin

./apachectl -k start

启动2个tomcat

cd /opt/web/tomcat2/apache-tomcat-6.0.32/bin

./start.sh

cd /opt/web/tomcat1/apache-tomcat-6.0.32/bin

./start.sh

测试session 复制

http://192.168.1.102/examples/servlets/servlet/SessionExample

查看负载均衡

http://192.168.1.102/balancer-manager

但是有个问题,如果session有很多对象,而对象又不停的变化,这就使得 seesion会消耗很大性能.

网上查了下,可以用memcached来做缓存应用.有时间再把这个整理下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值