tomcat集群

目录

安装http

cd /opt
tar -zxvf httpd-2.2.22.tar.gz
在当前路径会生成httpd-2.2.22文件夹

安装apr

cd /opt/httpd-2.2.22/srclib/apr
./configure --prefix=/opt/apr
make
make install

安装apr-util

cd /opt/httpd-2.2.22/srclib/apr-util
./configure --prefix=/opt/apr-util --with-apr=/opt/apr/
make
make install

安装http

cd /opt/httpd-2.2.22
./configure --prefix=/opt/httpd/ --with-apr=/opt/apr/ --with-apr-util=/opt/apr-util/  --enable-so --enable-cache --enable-disk-cache --enable-mem-cache --enable-rewrite --enable-info --enable-proxy  --enable-proxy-http --enable-proxy-connect  --enable-proxy-balancer --enable-headers --enable-deflate --enable-modules=all
make
make install

在2.4.4版本中,无需安装apr和util-apr。只需将这两个包解压后,文件夹分别更名为“apr”和“util-apr”放到安装文件的srclib目录下。然后用一下参数进行编译即可。
./configure --prefix=/opt/httpd --with-included-apr --with-included-apr-util --with-pcre=/opt/pcre/ --enable-modules=all
make
make install

启动测试

完成后,可以测试安装是否正常运行
cd /opt/httpd/bin
./apachectl start
打开IE,输入IP地址,如果显示“it works!”则表示正常工作
./apachectl stop

安装mod\_jk

解包tomcat-connectors-1.2.33-src.tar.gz
cd /opt
tar -zxvf tomcat-connectors-1.2.33-src.tar.gz
cd /opt/tomcat-connectors-1.2.33-src/native

在当前路径生成tomcat-connectors-1.2.33-src文件夹


cd /opt/tomcat-connectors-1.2.33-src/native
./configure --with-apxs=/opt/httpd/bin/apxs
make
make install
完成后会在/opt/httpd/modules目录下生成mod_jk.so文件

安装tomcat

解包apache-tomcat-6.0.35.tar.gz
cd /opt
tar -zxvf apache-tomcat-6.0.35.tar.gz
在当前路径生成apache-tomcat-6.0.35文件夹,该压缩包已经编译完成,解压后可直接使用。

配置

配置目标:
一台物理机器192.9.200.187,上面安装4个tomcat,tomcat1和tomcat2运行应用cms,tomcat3和tomcat4运行应用cmstest。
编辑/opt/httpd/conf/httpd.conf文件,在其中加入
# LoadModule foo_module modules/mod_foo.so
#
LoadModule jk_module modules/mod_jk.so
#
# Configure mod_jk
#
JkWorkersFile conf/workers.properties
JkMountFile conf/uriworkermap.properties
JkLogFile logs/mod_jk.log
JkLogLevel warn

在/opt/httpd/conf/新建workers.properties和uriworkermap.properties两个文件。
workers.properties定义转发属性。uriworkermap.properties定义哪些地址可以转发。
workers.properties文件内容如下:
#
# workers.properties
#
# list the workers by name
worker.list=cms,cmstest,jkstatus
# ------------------------
worker.cms1.port=8009
worker.cms1.host=192.9.200.187
worker.cms1.type=ajp13
worker.cms1.lbfactor = 1  #负载权值,数字越大,分得的数量越多
# ------------------------
worker.cms2.port=8010
worker.cms2.host=192.9.200.187
worker.cms2.type=ajp13
worker.cms2.lbfactor = 1
# ------------------------
worker.cms3.port=8011
worker.cms3.host=192.9.200.187
worker.cms3.type=ajp13
worker.cms3.lbfactor = 1
# ------------------------
worker.cms4.port=8012
worker.cms4.host=192.9.200.187
worker.cms4.type=ajp13
worker.cms4.lbfactor = 1

#定义cms应用负载到哪个虚拟机
worker.cms.type=lb
worker.cms.balanced_workers=cms1,cms2
worker.cms.sticky_session=1
#worker.cms.socket_keepalive=true
#worker.cms.socket_connect_timeout=5000
#定义cmstest应用负载到哪个虚拟机
worker.cmstest.type=lb
worker.cmstest.balanced_workers=cms3,cms4
worker.cmstest.sticky_session=1
worker.jkstatus.type=status

uriworkermap.properties文件内容如下:
/cms=cms
/cms/*=cms
/cmstest=cmstest
/cmstest/*=cmstest
#定义jk监控台
/jkstatus=jkstatus

修改tomcat1配置,文件位置为/opt/tomcat1/conf/server.xml
<Server port="8005" shutdown="SHUTDOWN">
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="cms1">

修改tomcat2配置,文件位置为/opt/tomcat2/conf/server.xml
<Server port="8006" shutdown="SHUTDOWN">
<Connector port="8090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8444" />
<Connector port="8010" protocol="AJP/1.3" redirectPort="8444" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="cms2">

修改tomcat3配置,文件位置为/opt/tomcat3/conf/server.xml
<Server port="8007" shutdown="SHUTDOWN">
<Connector port="8100" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8445" />
<Connector port="8011" protocol="AJP/1.3" redirectPort="8445" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="cms3">

修改tomcat4配置,文件位置为/opt/tomcat4/conf/server.xml
<Server port="8008" shutdown="SHUTDOWN">
<Connector port="8110" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8446" />
<Connector port="8012" protocol="AJP/1.3" redirectPort="8446" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="cms4">

至此即可启动所有服务。
http://IP/jkstatus为jk监控地址。

目录