首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

Apache HttpServer与Tomcat七集群Linux版

2013-11-08 
Apache HttpServer与Tomcat7集群Linux版Apache HttpServer与Tomcat的整合见上篇:http://blog.csdn.net/sup

Apache HttpServer与Tomcat7集群Linux版

Apache HttpServer与Tomcat的整合见上篇:

http://blog.csdn.net/supercrsky/article/details/8295023

 

一.配置Tomcat

这里用两个tomcat,直接在已安装目录再复制一个,命名为tomcat2。

#cp -r /opt/tomcat/ tomcat2

进入tomcat2目录,编辑 conf/server.xml,修改默认端口。

#vi conf/server.xml

1.  将

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

改成

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

2.将

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

修改成:

<Connector port="9090" protocol="HTTP/1.1"               connectionTimeout="20000"               redirectPort="9443" /> 

3. 找到:

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

改成

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

同时把tomcat2中此处内容改成

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

4.找到

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

改成

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

5.找到

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" />

把注释取消掉。

二.配置HTTP Server

1.检查是否启动了https,确保下面这句已经被注释。

#Include conf/extra/httpd-ssl.conf

2.找到我们在最文件最下面添加的VirtualHost节点,将其更改为: 

<VirtualHost *>DocumentRoot /usr/local/www/<Directory "/usr/local/www/composite">    AllowOverride None    Order allow,deny    Allow from all</Directory><Directory "/usr/local/www/composite/WEB-INF">         Order deny,allow         Deny from all</Directory>ServerAdmin localhostDocumentRoot /usr/local/www/ServerName localhostDirectoryIndex index.html index.htm index.jsp index.actionErrorLog logs/shsc-error_log.txtCustomLog logs/shsc-access_log.txt commonJkMount /*WEB-INF controllerJkMount /*j_spring_security_check controllerJkMount /*.action controllerJkMount /servlet/* controllerJkMount /*.jsp controllerJkMount /*.do controller</VirtualHost>

4. 编辑conf/workers.properties将内容修改为:

worker.list = controller#tomcat1worker.tomcat1.port=8009       worker.tomcat1.host=localhostworker.tomcat1.type=ajp13worker.tomcat1.lbfactor=1#tomcat2worker.tomcat2.port=9009     worker.tomcat2.host=localhostworker.tomcat2.type=ajp13worker.tomcat2.lbfactor=1#========controller========worker.controller.type=lbworker.controller.balance_workers=tomcat1,tomcat2worker.lbcontroller.sticky_session=0worker.controller.sticky_session_force=trueworker.connection_pool_size=3000worker.connection_pool_minsize=50worker.connection_pool_timeout=50000

这句非常重要worker.list = controller,如果不加httpd会无法启动,查看日志报错:

Could not find a worker for worker name=controller

如果是横向集群,将worker.tomcat1.host或worker.tomcat2.host更改为对应的机器IP即可。

 

三.部署并测试

 确保项目里的WEB-INF/web.xml文件,在</web-app>之前加入了

 <distributable/>

 将工程分别部署到/usr/local/www,/opt/tomcat/webapps,/opt/tomcat2/webapps

 

 分别启动tomcat1和tomcat2,顺序无所谓,最后启动HTTP Server

#/opt/tomcat/bin/startup.sh

#/opt/tomcat2/bin/startup.sh

#/usr/local/httpd2.2/bin/apachectl start

启两个Firefox,分别访问我们的工程,这里是:http://localhost/composite

观察/opt/tomcat/logs/与/opt/tomcat2/logs/下对应的日志,

 

我们发现tomcat1和tomcat2已经分别处理了一个客户端请求。

热点排行