因为公司项目在线人数的增加,随着现在硬件成本越来越低,大多数的生产环境内存大多都已经达到 16G,尤其最新的阿里云,客户的机器都是配置超高的java主机,但是Java运行环境,内存使用有限 ,这样就造成了这台服务器资源的浪费,所以单机的多Tomcat集群就很有必要!当然有客户有多台服务器,这样更好了,配置会更少,性能会更强悍。

网上很多文章在说集群方案,很多配下来都是错的,也不说错误的原因,原本希望配置apache2.4+tomcat8的集群方案,配下来没成功,就配置apache2.2.25+tomcat7.0.47集群方案,以后会发apache2.4+tomcat8的集群方案。 同时因为公司的电脑比较老,使用的32位系统,以后再发64位的。

apache+tomcat的集群方案有三种,我采用mod_jk方式,网上的配置很多有错误,错误不外乎两种:

1,配置路径错误,

2,mod_jk版本和apache版本不匹配,我搞了两天Apache启动不成功,加载不了mod_jk.so都是版本问题造成的。比如:mod_jk-1.2.31-httpd-2.2.3.so,此版本中httpd-2.2.3一定要和Apache版本一致。

下面列出实际配置所用的:

软件:

  1. jdk:jdk-7u80-windows-i586.exe
  2. apache:httpd-2.2.25-win32-x86-no_ssl.msi
  3. tomcat:apache-tomcat-7.0.47.zip

本次使用是单机垂直集群,一台机器上装Apache ,两个tomcat

首先是Apache的安装

  1. Apache的安装,我下载的是安装版,直接一步步安装即可,如果是非安装版,需要注册成服务才可以。
  2. Apache安装完成后,找到apache的所在目录,在conf文件夹下找到httpd.conf这个配置文件,打开配置文件

1、mod_jk-1.2.31-httpd-2.2.3.so修改为mod_jk.so,拷贝mod_jk.so到Apache安装路径的modules文件夹下;

2.修改Apache配置文件httpd.conf(笔者路径:E:\Apache2.2\conf\httpd.conf),

    • 修改ServerRoot,即Apache安装路径,比如:ServerRoot "D:/Apache2.2""
    • 在最后一行末尾添加:include "E:\Apache2.2\conf\mod_jk.conf"
    1. 在httpd.conf 同目录下新建mod_jk.conf文件
 JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
JkRequestLogFormat "%w %V %T"
JkMount /* controller

  在conf下新建workers.properties,

worker.list=controller
worker.controller.type=lb
worker.controller.sticky_session=1
worker.controller.error_escalation_time=0
worker.controller.max_reply_timeouts=10 # localhost server 1
# ------------------------
worker.jvm1.reference=worker.template
worker.jvm1.port=8009
worker.jvm1.host=localhost
worker.jvm1.lbfactor = 5
worker.jvm1.activation=A # localhost server 2
worker.jvm2.reference=worker.template
worker.jvm2.port=9009
worker.jvm2.host=localhost
worker.jvm2.lbfactor=1
worker.jvm2.activation=A worker.template.type=ajp13
worker.template.socket_connect_timeout=5000
worker.template.socket_keepalive=true
worker.template.ping_mode=A
worker.template.ping_timeout=10000
worker.template.connection_pool_minsize=0
worker.template.connection_pool_timeout=600
worker.template.reply_timeout=300000
worker.template.recovery_options=3 worker.controller.balance_workers=jvm1,jvm2

  

#这里可以配置任意多个Tomcat,此处配置了2个Tomat服务器.
#host和port根据自己实际配置.实例配置的是本机两个tomcat,分别使用不同的端口.避免冲突
#如果Tomcat不再同一机器上,没必要改端口的。

3、 重启Apache,看是否能够启动成功,访问:http://localhost/;Apache配置完成

配置tomcat,将tomcat复制,命名为tomcat1,tomcat2,两个tomcat在一个机器上,需要修改一台tomcat:主要为各个端口

  1、修改tomcat2,配置例子:tomcat1没有修改

8005改为8015,shutdown端口

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

  Connector port="8090",网站访问端口,8080改为8090

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

  ajp端口,8009改为9009

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

  增加jvmRoute,jvmRoute="jvm2",tomcat1则为jvmRoute="jvm1"

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

   Cluster打开,增加:

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

           <Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService" address="228.0.0.4" port="45564" frequency="500" dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto" port="4001" autoBind="100" selectorTimeout="5000" maxThreads="6"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel> <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter="/"/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<!--
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" tempDir="/tmp/war-temp/" deployDir="/tmp/war-deploy/" watchDir="/tmp/war-listen/" watchEnabled="false"/>
-->
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>

  tomcat配置完成,tomcat1,tomcat分别看能够启动。

增加session共享

tomcat/webApps下新建项目test,新建test.jsp文件,新建WEB-INF文件夹,文件夹下新建web.xml,插入:

 <distributable/>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<display-name>test</display-name>
<distributable/>
</web-app>

  依次启动apache,tomcat1,tomcat2.

集群+负载均衡,session共享配置完成。

apache2.2.25+tomcat7.0.47集群方案的更多相关文章

  1. (转)apache2.2.x+tomcat7.0.x集群+…

    apache http server下载地址 http://httpd.apache.org/download.cgi#apache22 这里下载的是httpd-2.2.21-win32-x86-op ...

  2. Tomcat7.0.99集群使用Redis共享session方案

    以前配置过给予多播的session共享方案,这回再配置一个redis共享session的. 先小小的炫耀一下: 相信大家要做Tomcat+Redis+session配置,遇到的头号麻烦就是编译的tom ...

  3. Redis集群方案介绍

    由于Redis出众的性能,其在众多的移动互联网企业中得到广泛的应用.Redis在3.0版本前只支持单实例模式,虽然现在的服务器内存可以到100GB.200GB的规模,但是单实例模式限制了Redis没法 ...

  4. Redis 集群方案介绍

    由于Redis出众的性能,其在众多的移动互联网企业中得到广泛的应用.Redis在3.0版本前只支持单实例模式,虽然现在的服务器内存可以到100GB.200GB的规模,但是单实例模式限制了Redis没法 ...

  5. Redis集群方案收集

    说明: 如果不考虑客户端分片去实现集群,那么市面上基本可以说就三种方案最成熟,它们分别如下所示: 系统 贡献者 是否官方Redis实现 编程语言 Twemproxy Twitter 是 C Redis ...

  6. redis 集群方案及搭建

    由于Redis出众的性能,其在众多的移动互联网企业中得到广泛的应用.Redis在3.0版本前只支持单实例模式,虽然现在的服务器内存可以到100GB.200GB的规模,但是单实例模式限制了Redis没法 ...

  7. Redis-4.0.11集群配置

    版本:redis-3.0.5 redis-3.2.0  redis-3.2.9  redis-4.0.11 参考:http://redis.io/topics/cluster-tutorial. 集群 ...

  8. Redis-5.0.5集群配置

    版本:redis-5.0.5 参考:http://redis.io/topics/cluster-tutorial. 集群部署交互式命令行工具:https://github.com/eyjian/re ...

  9. 分布式存储 CentOS6.5虚拟机环境搭建FastDFS-5.0.5集群(转载-2)

    原文:http://www.cnblogs.com/PurpleDream/p/4510279.html 分布式存储 CentOS6.5虚拟机环境搭建FastDFS-5.0.5集群 前言:       ...

随机推荐

  1. Windows Filesystem filter driver

    参考:http://www.codeproject.com/Articles/43586/File-System-Filter-Driver-Tutorial 关键点: To perform atta ...

  2. ConcurrentHashMap(锁分段技术)

    线程不安全的HashMap     因为多线程环境下,使用Hashmap进行put操作会引起死循环,导致CPU利用率接近100%,所以在并发情况下不能使用HashMap.   效率低下的HashTab ...

  3. bzoj4843 [Neerc2016]Expect to Wait

    [Neerc2016]Expect to Wait Time Limit: 10 Sec Memory Limit: 128 MB Description ls最近开了一家图书馆,大家听说是ls开的, ...

  4. 七、hibernate的事务使用

    hibernate中事务隔离级别 1:读未提交 2:读已提交 4:可重复读 8:可串行化 hibernate事务使用 在核心配置文件中配置事务隔离级别 <property name=" ...

  5. koa2入门笔记

    [TOC] 一 什么是koa koa是基于nodejs的web框架, 是一个中间件框架. 二 中间件 Koa 中间件是简单的函数,它是带有 (ctx, next)形参 的函数. 可以采用两种不同的方法 ...

  6. codelite配置信息

    codelite下编译执行wxwidgets库需要修改链接库如下: 原来的c++ compiler配置-g;-O0;-Wall;$(shell wx-config --cflags --debug) ...

  7. 一、@Html.DropDownList

    一.Html.DropDownList 通过linq 将datatable转换下拉列表 //查询城市 string CityId = WebCommon.Public.GetAdminCityId() ...

  8. python实现发送文本邮件

    简单实现了python发送文本邮件 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/4/25 17:09 # @Author ...

  9. java应用之openfire入门篇

    前言 openfire是一个聊天服务端,好比qq服务端.本质是个socker server. openfire通讯协议是 xmpp  ,什么是xmpp参考百科 https://baike.baidu. ...

  10. jquery实现左侧菜单 效果

    html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...