Apache2(http.2.4.6) + Tomcat 7.0 集群安装与配置

2022-06-28 16:11:18 浏览数 (1)

最近由于工作需要,公司需要部署 tomcat 集群,忙活了几天,终于配置了好了,做个笔记以后备用。

1. 下载 apache2 源码 http2.4.6

2. 配置 apache2 ./configure --prefix=/usr/local/apache2 --enable-modules=shared --enable-mods-shared=all --enable-proxy --enable-proxy-connect --enable-proxy-ftp --enable-proxy-http --enable-proxy-ajp --enable-proxy-balancer --enable-rewrite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre

其中 apr ,apr-util, pcre 是安装依赖包,需要提前安装

3. 安装 apache2 root@qlserver03:/home/ryanwang/http2.4.6# make && make install

4 配置 load balance 修改 httpd.conf,文件末尾插入如下内容  ProxyRequests Off <Proxy balancer://mycluster>     BalancerMember http://192.168.1.202:8080  loadfactor=1 route=jvm1     BalancerMember http://192.168.1.203:8080  loadfactor=1 route=jvm2 </Proxy> ProxyPass / balancer://mycluster/

正向代理需要关闭,主要是为了安全,“ProxyPass / balancer://mycluster/”

表示所有请求都交给 mycluster 来处理。

5 配置 tomcat7 修改 tomcat/conf/server.xml

<!-- You should set jvmRoute to support load-balancing via AJP ie : <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1"> <Engine name="Catalina" defaultHost="localhost">--> <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">

另外一台服务器配置成 jvmRoute="jvm2"

6 应用的web.xml 文件需要增加一个元素 <distributable/>

到此 tomcat集群load balance 已经配置完成。下面配置 session 复制

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"         channelSendOptions="8">         <Manager className="org.apache.catalina.ha.session.BackupManager"           expireSessionsOnShutdown="false"           notifyListenersOnReplication="true"           mapSendOptions="6"/>   <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.202"               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>

其中修改把 manager元素的 <Manager className="org.apache.catalina.ha.session.DeltaManager" 修改为 <Manager className="org.apache.catalina.ha.session.BackupManager" 表示只有相同应用的tomcat之间才复制session。 <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"           address="192.168.1.202"           port="4000"           autoBind="100"           selectorTimeout="5000"           maxThreads="6"/>

修改 receiver IP 地址和端口。

Tomcat 的详细介绍:请点这里 Tomcat 的下载地址:请点这里

0 人点赞