linux apache tomcat集群与apache和tomcat的整合

linux apache tomcat集群与apache和tomcat的整合(只用一个80端号来访问多个不同端口的tomcat下的应用)

环境:
两台linu,ip分别
192.168.88.29    (安装apache  ,两个tomcat ,jdk,jk) (两个tomcat-个是:8080 这个是与34集群的访问名www.lxp.com,另一个

是:9090安装另的应用,访问名www.test.com )

192.168.88.34    (安装tomcat ,jdk)

下载必须的软件:
httpd-2.2.10.tar.gz  (apache)
http://archive.apache.org/dist/httpd/

jakarta-tomcat-5.5.9.tar.gz (tomcat)
http://archive.apache.org/dist/tomcat/

http://archive.apache.org/dist/tomcat/tomcat-5/

jdk-1_5_0_15-linux-i586.bin  (jdk)
http://java.sun.com/javase/downloads/index_jdk5.jsp

下载地址:http://labs.renren.com/apache-mirror/tomcat/tomcat-connectors/jk/binaries/netware/mod_jk-1.2.32-httpd-2.2.21-nw.zip

mod_jk-1.2.28-httpd-2.2.X.so (apach与tomcat的jk)
http://apache.etoak.com/tomcat/tomcat-connectors/jk/binaries/

2安装所有的软件这个是在29上安装的说明
apache安装
#tar -zxvf httpd-2.2.10.tar.gz
#cd httpd-2.2.10
# mkdir /ucenter/apache2
#./configure  --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-rewirte --enable-so --enable-ssl=static --with-ssl=/usr/local/ssl  --enable-proxy=shared --enable-proxy-balancer=shared --enable-proxy-http=shared --enable-proxy-ajp --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache

# make
# make install
# /ucenter/apache2/bin/apachectl start

把mod_jk-1.2.28-httpd-2.2.X.so放到apache 下面
#cp mod_jk-1.2.28-httpd-2.2.X.so /ucenter/apache2/modules/

tomcat 和jdk安装
#tar -zxvf jakarta-tomcat-5.5.9.tar.gz
#mv jakarta-tomcat-5.5.9 tomcat1

#./jdk-1_5_0_15-linux-i586.bin
#mv jdk-1_5_0_15 jdk1.5
#cd ~
#vi .bash_profile

export JAVA_HOME=/tomcat/jdk1.5
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CLASSPATH

export CATALINA_BASE=/tomcat/tomcat1
export CATALINA_HOME=/tomcat/tomcat1
export TOMCAT_HOME=/tomcat/tomcat1

export CATALINA_1_BASE=/tomcat/tomcat3
export CATALINA_1_HOME=/tomcat/tomcat3
export TOMCAT_1_HOME=/tomcat/tomcat3


到tomcat1/bin下面

#vi catlina.sh

export CATALINA_BASE=/tomcat/tomcat1
export CATALINA_HOME=/tomcat/tomcat1

再到tomcat3/bin下面

#vi catlina.sh

export CATALINA_BASE=/tomcat/tomcat3
export CATALINA_HOME=/tomcat/tomcat3


3.到29上的apach/conf下 http.conf 同目录下新建mod_jk.conf文件,内容如下

#vi mod_jk.conf 

#加载mod_jk Module
LoadModule jk_module modules/mod_jk-1.2.28-httpd-2.2.X.so
#指定 workers.properties文件路径
JkWorkersFile conf/workers.properties
#指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器
JkMount /*.jsp controller



4.到29上的apach/conf在http.conf同目录下新建 workers.properties文件,内容如下

#vi workers.properties

worker.list = controller,tomcat1,tomcat2,tomcat3  #server 列表
#========tomcat1========
worker.tomcat1.port=8009         #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.host=localhost  #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1   #server的加权比重,值越高,分得的请求越多

#========tomcat2========
worker.tomcat2.port=8009       #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.host=192.168.88.34  #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1   #server的加权比重,值越高,分得的请求越多


#========tomcat3========
worker.tomcat3.port=9009       #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat3.host=localhost  #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat3.type=ajp13
worker.tomcat3.lbfactor = 1   #server的加权比重,值越高,分得的请求越多


#========controller,负载均衡控制器========
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2,tomcat3   #指定分担请求的tomcat
worker.controller.sticky_session=1


5到29上的apach/conf在http.conf同目录下新建vhost.conf文件,内容如下

#vi vhost.conf

#因为是80端口所以只写以下内容就行了
DocumentRoot /tomcat/tomcat1/webapps/ROOT
ServerName www.lxp.com


DocumentRoot /tomcat/tomcat3/webapps/ROOT
ServerName www.test.com

5.到apache下的conf到httpd.conf的最底下写入两句话

#vi httpd.conf
include /ucenter/apache/conf/mod_jk.conf
include /ucenter/apache/conf/vhost.conf


6到29上的/tomcat/tomcat1/conf下的server.xml写入
#vi server.xml

#把jvmRoute="tomcat1"加入下面和把localhost改为www.lxp.com
<Engine name="Catalina" defaultHost="www.lxp.com" jvmRoute="tomcat1">

#把localhost改为www.lxp.com
<Host name="www.lxp.com" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

# 把<Cluster 前面的<!-- 和 </Cluster>后面的 -->去掉

<Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
                 managerClassName="org.apache.catalina.cluster.session.DeltaManager"
                 expireSessionsOnShutdown="false"
                 useDirtyFlag="true"
                 notifyListenersOnReplication="true">

            <Membership
                className="org.apache.catalina.cluster.mcast.McastService"
                mcastAddr="228.0.0.4"
                mcastPort="45564"
                mcastFrequency="500"
                mcastDropTime="3000"/>

            <Receiver
                className="org.apache.catalina.cluster.tcp.ReplicationListener"
                tcpListenAddress="auto"
                tcpListenPort="4001"
                tcpSelectorTimeout="100"
                tcpThreadCount="6"/>

            <Sender
                className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
                replicationMode="pooled"
                ackTimeout="15000"/>

            <Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
                   filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
                 
            <Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
                      tempDir="/tmp/war-temp/"
                      deployDir="/tmp/war-deploy/"
                      watchDir="/tmp/war-listen/"
                      watchEnabled="false"/>
        </Cluster>


由于29上只是安装一个tomcat作为集群,所以tcpListenPort="4001" 这个端口不用改,如果是两个tomcat在一台机作集群那就要改

tcpListenPort这个端口


7再到/tomcat/tomcat3/conf/server.xml

#vi server.xml

#把port="8005"改为9005
<Server port="9005" shutdown="SHUTDOWN">

#把Connector port="8080"改为9090
<Connector port="9090" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />

#把Connector port="8009"改为9009
<Connector port="9009"
               enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />

#把jvmRoute="tomcat3"加入下面和把localhost改为www.test.com
<Engine name="Catalina" defaultHost="www.test.com" jvmRoute="tomcat3">

#把localhost改为www.test.com
<Host name="www.test.com" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

这样29上的安装和配置就基本上是完成的了

34上就是只安装tomcat和jdk再和29上的第6步安装修一下就行了

全部完成后,检验:

打开ie  www.lxp.com是出来集群的应用

    www.test.com是打开29上别外的一个应用

再把29上tomcat1关掉
ie www.lxp.com看看还有没有集群应用,有就说明集群成了


实践证明正确
转载源:http://space.itpub.net/16111659/viewspace-664792


ubuntu apche2+tomcat6 整合(ajp) 收藏
1 安装tomcat:

sudo apt-get install tomcat6

当然你也可以直接下载免安装版。不过ubuntu直接安装的会自动给你建立tomat用户组和用户。

2安装apache。默认已经安装。

sudo apt-get install apche2

3 启动两个代理模块

sudo a2enmod proxy_ajp

sudo a2enmod proxy

你也可以在/etc/apache2/conf下的httpd.conf输入下面几句:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

接着在httpd.conf输入

ProxyPass / ajp://127.0.0.1:8009/
ProxyPassReverse / ajp://127.0.0.1:8009/

重启

sudo /etc/init.d/apache2 restart

打开tomcat的server.xml(路径应该为与/usr/share/tomcat6 你可以用whereis tomcat6查看)

将含有 define a Coyote/JK2 AJP 1.3 Connector on port 8009

注释掉即可。

重启tomcat。

over.

note:

我在配置的时候出现403问题。

根据网上的建议:

在/etc/apache2/module-available/proxy.conf内容修改为:

<IfModule mod_proxy.c>

  ProxyRequests Off

  <Proxy *>

    Order deny,allow

    Deny from all

   # Allow from localhost 127.0.0.1 192.168.139.2

    Allow from all

  </Proxy>

  ProxyVia On

</IfModule>

当然该文件说不推荐使用allow from all.不过它说的是不要同时将ProxyRequests on 也设置上。

你可能感兴趣的:(apache,jdk,tomcat,linux,ubuntu)