apache2.4+tomcat8+jk1.2.40集群配置
由于目前很多apache+tomcat集群都是在apache2.2上配置的,Apache2.4的教程几乎没有,这里写一篇记录下来。
环境:apache2.4.12(Apache Haus编译版本)、tomcat8.0.15、1.2.40版本的mod_jk.so、jdk-7u71、操作系统winxp
关于这几个软件的下载安装,这里就不多说,注意apache2.4必须安装在根目录,mod_jk必须下载Apache对应的版本
软件
笔者环境
三台xp虚拟机
1.Apache服务器,IP:192.168.116.132
2.tomcat服务器一,IP:192.168.116.133
3.tomcat服务器二,IP:192.168.116.134
一、Apache服务器配置
笔者将Apache安装在了C盘根目录下
1.将mod_jk.so复制到Apache的modules目录(笔者为C:\Apache24\modules)
2.在Apache的conf目录(笔者为C:\Apache24\conf)找到httpd.conf,在文件最后添加
include "C:\Apache24\conf\mod_jk.conf"
3.在Apache的conf目录(笔者为C:\Apache24\conf)新建文件mod_jk.conf,添加如下内容
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel debug
JkMount /*.jsp controller
这里强烈建议把JkLogLevel debug加上,否则出错找不到原因
4.在Apache的conf目录(笔者为C:\Apache24\conf)新建文件workers.properties,添加如下内容
#server
worker.list = controller
#========tomcat1========
worker.tomcat1.port=
worker.tomcat1.host=192.168.116.133
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor= #========tomcat2========
worker.tomcat2.port=
worker.tomcat2.host=192.168.116.134
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor= #========controller,负载均衡控制器========
worker.controller.type=lb
worker.controller.retries=
worker.controller.balance_workers=tomcat1,tomcat2
worker.controller.sticky_session=false
worker.controller.sticky_session_force=false
二、tomcat服务器配置
打开tomcat的conf目录下的server.xml,找到AJP/1.3连接器,端口与workers.properties的worker.[名称].port设置成一致,默认是8009,在Engine里面添加jvmRoute,名称与worker.后面的名称一致,最后去掉<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>两边的注释,两个服务器配置文件大致一样,仅jvmRoute设置不一样。
tomcat服务器一:
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/> <!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html --> <!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1"> <!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
--> <!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm> <Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
--> <!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" /> </Host>
</Engine>
tomcat服务器二:
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/> <!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html --> <!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2"> <!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
--> <!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm> <Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
--> <!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" /> </Host>
</Engine>
编写文件部署到tomcat,笔者也懒得写,大家都抄来抄去的
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.Enumeration"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Cluster App Test</title>
</head>
<body>
Server Info:
<%
out.println(request.getLocalAddr() + " : " + request.getLocalPort()
+ "<br>");
%>
<%
out.println("<br> ID " + session.getId() + "<br>");
// 如果有新的 Session 属性设置
String dataName = request.getParameter("dataName");
if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue);
}
out.println("<b>Session 列表</b><br>");
System.out.println("============================");
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String) e.nextElement();
String value = session.getAttribute(name).toString();
out.println(name + " = " + value + "<br>");
System.out.println(name + " = " + value);
}
%>
<form action="index.jsp" method="POST">
名称:<input type=text size=20 name="dataName"> <br> 值:<input
type=text size=20 name="dataValue"> <br> <input
type=submit>
</form>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>testc</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<distributable/>
</web-app>
需要注意的是web.xml里面的必须要加上<distributable/>,然后部署到两个tomcat服务器中
三、启动测试运行
先启动apache服务器,然后启动2个tomcat服务器
浏览器打开http://192.168.116.132/test/index.jsp
然而奇迹并没有出现,而是出现了404页面,提示文字为
Not Found
The requested URL /test/index.jsp was not found on this server.
接下来我们要看日志文件,看看问题出在哪里
找到jk的日志文件(C:\Apache24\logs\mod_jk.log)
直接看最后几行
[Sat May ::38.718 ] [:] [debug] extension_fix_activation::jk_uri_worker_map.c (): Checking extension for worker controller of type lb ()
[Sat May ::38.718 ] [:] [debug] uri_worker_map_dump::jk_uri_worker_map.c (): uri map dump after extension stripping: id=, index= file='(null)' reject_unsafe= reload= modified= checked=
[Sat May ::38.718 ] [:] [debug] uri_worker_map_dump::jk_uri_worker_map.c (): generation : size= nosize= capacity=
[Sat May ::38.718 ] [:] [debug] uri_worker_map_dump::jk_uri_worker_map.c (): generation : size= nosize= capacity=
[Sat May ::38.718 ] [:] [debug] uri_worker_map_dump::jk_uri_worker_map.c (): NEXT () map #: uri=/*.jsp worker=controller context=/*.jsp source=JkMount type=Wildchar len=6
[Sat May 16 20:12:38.718 2015] [2176:1048] [debug] uri_worker_map_switch::jk_uri_worker_map.c (600): Switching uri worker map from index 0 to index 1
[Sat May 16 20:12:38.718 2015] [2176:1048] [debug] jk_shm_open::jk_shm.c (168): Shared memory is already opened
[Sat May 16 20:12:38.718 2015] [2176:1048] [debug] jk_shm_attach::jk_shm.c (337): Attached shared memory memory [1] size=2560 free=0 addr=0x32bb30
[Sat May 16 20:12:38.718 2015] [2176:1048] [debug] jk_child_init::mod_jk.c (3266): Initialized mod_jk/1.2.40
[Sat May 16 20:12:38.750 2015] [2176:3584] [debug] jk_translate::mod_jk.c (3623): missing uri map for localhost:/test/index.jsp
[Sat May 16 20:12:38.750 2015] [2176:3584] [debug] jk_map_to_storage::mod_jk.c (3791): missing uri map for localhost:/test/index.jsp
通过搜索关键字missing uri map for localhost:/找到一篇文章
http://blog.csdn.net/bluecy/article/details/5897103
具体意思是在<VirtualHost>标签中添加JkMountCopy On,然而作者并没有说是哪个文件......
笔者也上谷歌搜了,也是添加这个,但就是找不到
笔者最后还是找到了这个文件,文件在C:\Apache24\conf\extra的httpd-vhosts.conf,为什么大家都不说这个啊。。。。。。笔者很是郁闷
默认情况下已经配置了一个虚拟主机
<VirtualHost _default_:80>
DocumentRoot "${SRVROOT}/htdocs"
#ServerName www.example.com:80
</VirtualHost>
然后在中间添加JkMountCopy On就行了(如果有多个要配置多个)
<VirtualHost _default_:80>
DocumentRoot "${SRVROOT}/htdocs"
#ServerName www.example.com:80
JkMountCopy On
</VirtualHost>
如果读者用的2.2版本,应该不会遇到要配置虚拟主机参数的问题。
保存之后重启apache服务器,然后在浏览器重新打开
http://192.168.116.132/test/index.jsp
F5刷新
可以看到sessionid并没有发生变化
在名称和值中分别输入1、1、2、2、3、3、4、4,可以看到如下结果
上面的测试说明,session已经能够共享,并且session里面存储的变量也能够在集群中复制。
apache2.4+tomcat8+jk1.2.40集群配置的更多相关文章
- Apache 2.4.12 64位+Tomcat-8.0.32-windows-x64负载集群方案
上次搞了Apache 2.2的集群方案,但是现在自己的机器和客户的服务器一般都是64位的,而且tomcat已经到8了.重新做Apache 2.4.12 64位+Tomcat-8.0.32-window ...
- apache2.2.25+tomcat7.0.47集群方案
因为公司项目在线人数的增加,随着现在硬件成本越来越低,大多数的生产环境内存大多都已经达到 16G,尤其最新的阿里云,客户的机器都是配置超高的java主机,但是Java的运行环境,内存使用有限 ,这样就 ...
- Linux+Apache+Tomcat集群配置
参考: http://blog.csdn.net/bluishglc/article/details/6867358# http://andashu.blog.51cto.com/8673810/13 ...
- (转)Apache+Tomcat集群配置
本文Apache+Tomcat集群配置 基于最新的Apache和Tomcat,具体是2011年4月20日最新的Tomcat和Apache集群和负载均衡配置. 准备环境 Apache Apache是ht ...
- 1.Apache+Tomcat负载均衡+集群配置
1.本文Apache+Tomcat集群配置 基于最新的Apache和Tomcat,具体是2011年4月20日最新的Tomcat和Apache集群和负载均衡配置. 准备环境 Apache Apache是 ...
- Apache负载均衡与Tomcat集群配置学习(Windows环境)
本文主要参考自http://www.iteye.com/topic/985404?dhcc,经由实际操作配置操并记录而成. 由于最近的一个Java开发项目用到了Tomcat中间件作为web服务器,刚开 ...
- Spring+quartz 实现定时任务job集群配置
为什么要有集群定时任务? 因为如果多server都触发相同任务,又同时执行,那在99%的场景都是不适合的.比如银行每晚24:00都要汇总营业额.像下面3台server同时进行汇总,最终计算结果可能是真 ...
- Apache+tomcat+mod_jk+centos6.2负载均衡集群配置--转载
转载地址:http://blog.163.com/chenhui_java/blog/static/17267249420128101191860/ 注: 由于长期受转载毒害,所以本人日志均是原创:其 ...
- window xp Apache与Tomcat集群配置--转载
转载地址:http://www.cnblogs.com/obullxl/archive/2011/06/09/apache-tomcat-cluster-config.html 一. 环境说明 Win ...
随机推荐
- V4L2学习(四)VIVI分析
vivi 相对于后面要分析的 usb 摄像头驱动程序,它没有真正的硬件相关层的操作,也就是说抛开了复杂的 usb 层的相关知识,便于理解 V4L2 驱动框架,侧重于驱动和应用的交互. 前面我们提到,V ...
- rope(转载)
谈c++ pb_ds库(一)rope大法好 (转载)原文链接 https://www.cnblogs.com/keshuqi/p/6257642.html 参考资料 1)官方说明 支持 sorry,c ...
- 将FragmentManger事务添加到返回栈中
FragmentManger事务添加或替换的 Fragment 后,这时点击 Back 键,程序并不会返回添加之前的状态. 我们可以使用 Transaction 对象的 addToBackStack( ...
- IOS开发---菜鸟学习之路--(十七)-利用UITableView实现个人信息界面
首先来看下我们要实现的效果 需要实现这样的效果 然后我们开始动手吧. 首先选择添加一个新的ViewController 然后打开XIB文件,添加一UITableView 并将样式设置为分组 同时将按住 ...
- 『编写高质量代码Web前端开发修炼手册』读书笔记--高质量的CSS
1.怪异模式和DTD 标准模式:浏览器根据规范表现页面 怪异模式:模拟老浏览器行为防止老站点无法工作(为了兼容老式浏览器的代码),如果漏写DTD(Document Type Definition文档定 ...
- leetcode 【 Subsets II 】python 实现
题目: Given a collection of integers that might contain duplicates, S, return all possible subsets. No ...
- Effictive C++ 学习记录
这是前段时间看的书,整理到这里吧,以后查看也方便. 这些条款需要反复查看. 条款01:视C++为一个语言联邦 条款02:尽量用const.enum.inline替换#define 条款03:尽可能的使 ...
- MongoDB快速入门学习笔记8 MongoDB的java驱动操作
import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; import org.bson.D ...
- MFC DLL 可以封装MFC的窗体 供别的MFC程序使用
MFC DLL 可以封装MFC的窗体 供别的MFC程序使用 在庞大程序分工里面 非常可取. 可以细分每个窗体就是单独的 模块. [后续不断完善]
- Unity 查找
GameObject.Find().Transform.Find查找游戏对象 1.前置条件 Unity中常用到查找对象,非隐藏的.隐藏的,各种方法性能有高有低,使用又有各种条件限制. 在此对查找的性能 ...