操作系统:Debian6.0 (192.168.225.129 虚拟机1台)
软件版本:Apache-2.2.16, Tomcat-6.0.35
1.安装软件
>apt-get install update
*安装Apache
>apt-get install apache2
*安装Tomcat
>wget http://apache.etoak.com/tomcat/tomcat-6/v6.0.35/bin/apache-tomcat-6.0.35.tar.gz
>tar zxvf apache-tomcat-6.0.35.tar.gz
>mv apache-tomcat-6.0.35 /user/local/tomcat
>cp /usr/local/tomcat /usr/local/tomcat2
*安装mod_jk
>apt-get install libapache2-mod-jk
2.配置2个Tomcat
现在/usr/local目录中已经有2个tomcat目录了,需要更改tomcat2的端口,防止端口冲突。
>nano /usr/local/tomcat/conf/server.xml
有3处的默认端口需要更改:
1.
2.
redirectPort="8443" />
更改为7080
3.
更改为7009,其中redirectPort 8443不需要更改
o.另外还需要在
channelSendOptiOns="8">
notifyListenersOnReplication="true"/>
address="228.0.0.4"
port="45564"
frequency="500"
dropTime="3000"/>
address="auto"
port="4001"
selectorTimeout="5000"
maxThreads="6"/>
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
x.最后2个tomcat都需要改变
3.配置Apache以jk方式和tomcat集群
安装完成后apache的主目录为/etc/apache2,安装完mod-jk之后,mods-enabled里面会多一个jk.load
创建文件 /etc/apache2/mods-enabled/jk.conf
>nano /etc/apache2/mods-enabled/jk.conf
JkWorkersFile /etc/apache2/workers.properties
创建文件 /etc/apache2/workers.properties
>nano /etc/apache2/workers.properties
worker.list=controller1
worker.tomcat1.port=8009
worker.tomcat2.port=7009
worker.controller1.type=lb
更改/etc/apache2/sites-enabled/000-default文件
在之前添加
JkMount /* controller1
(controller1对应workers.properties中的名字)
配置完成之后先后启动tomcat和apache。
测试:
2个tomcat部署相同的应用:即首页index.jsp显示各自tomcat名称tomcat1和tomcat2
通过80端口访问应用,刷新几次,tomcat1和tomcat2轮流显示。
JkShmFile /var/log/apache2/mod_jk.shm
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel info
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
worker.controller1.sticky_session=1 #可选项0,1
worker.controller1.balance_workers=tomcat1,tomcat2