【转】Apache Http Server与Tomcat实现负载均衡和集群

一、分布式实现原理

       

        如上图所示,主要通过 Apache-Server 作为中转服务器,实现多个 tomcat 服务器之间的分布式处理,用户直接请求Apache-Server ,然后 Apache-Server 会将请求分发到具体的 tomcat-server ,之后tomcat-server 响应客户请求并返回结果到 Apache-Server ,最后 Apache-Server 返回结果给用户 

二、负载均衡

文件说明:

mod_jk.conf

主要定义 mod_jk 模块的位置以及 mod_jk 模块的连接日志设置,还有定义 worker.properties 文件的位置。  

worker.properties 
定义 worker 的参数,主要是连接 tomcat 主机的地址和端口信息。如果 Tomcat 与apache 不在同一台机器上,或者需要做多台机器上 tomcat 的负载均衡只需要更改 workers.properties 文件中的相应定义即可。

 

% APACHE_HOME %为你的安装目录  

 

环境说明:

        主要使用了一个 Apache Server 和两个 Tomcat ,在同一台电脑上进行测试。

 

1.  准备软件

Jdk1.6

下载地址: http://java.sun.com

tomcat -6.0.29

下载地址: http://jakarta.apache.org

apache_2.2.4-win32-x86-no_ssl.msi

下载地址: http://httpd.apache.org/download.cgi

mod_jk-1.2.31-httpd-2.0.52.so (主要作用是建立 Apache Server 与 Tomcat 之间的连接 )

下载地址: http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/ 

        说明: apache-server 安装完成后,可以在浏览器中输入 http://localhost/来测试,如果出现 ” It works!”则表示安装成功。


2.  
安装 mod_jk 连接模块

安装好 Jdk 、 tomcat 、 apache 后 , 加入 mod_jk 连接模块,就是把 mod_jk- 1.2.31 -httpd-2.2.3.so 文件 拷贝到%APACHE_HOME % \modules 下,把 jk 模块的配置放到单独的文件中来,在%APACHE_HOME % \conf 目录新建 mod_jk.conf 、 workers.properties 文件。 

在 httpd.conf 最后加上:

        # JK module settings

Include conf/mod_jk.conf  

说明:以上表示将 mod_jk.conf 配置文件包含进来 


3.  
修改 mod_jk.conf 文件

为了保持 httpd.conf 文件的简洁,把 jk 模块的配置放到单独的文件中来。      

在 mod_jk.conf 文件中添加以下内容:

# Load mod_jk2 module

LoadModule jk_module modules/mod_jk-1.2.31-httpd-2.2.3.so 

# Where to find workers.properties(引用 workers配置文件 )

JkWorkersFile conf/workers.properties 

# Where to put jk logs(log文件路径 )

JkLogFile logs/mod_jk2.log 

# Set the jk log level [debug/error/info](log级别 )

JkLogLevel info      

# Select the log format(log格式 )

JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

# JkOptions indicate to send SSL KEY SIZE,

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories 

# JkRequestLogFormat set the request format

JkRequestLogFormat "%w %V %T" 

# Send JSPs for context / to worker named loadBalancer(URL转发配置,匹配的 URL才转发到 tomcat进行处理 )

JkMount /*.jsp controller

# JkMount /*.* loadBalancer      

4.  修改 workers.properties 文件

在 workers.properties 文件中添加以下内容:

#server  列表

worker.list =  controller,tomcat1,tomcat2

 

# tomcat1(ajp13  端口号,在tomcat下server.xml配置,默认8009)

worker.tomcat1.port=8009

#tomcat 的主机地址,如不为本机,请填写ip地址

worker.tomcat1.host=localhost

worker.tomcat1.type=ajp13

#server 的加权比重,值越高,分得的请求越多

worker.tomcat1.lbfactor = 1

 

# tomcat2

worker.tomcat2.port=9009

worker.tomcat2.host=localhost

worker.tomcat2.type=ajp13

worker.tomcat2.lbfactor = 1

 

# controller( 负载均衡控制器)

worker.controller.type=lb

#  指定分担请求的tomcat

worker.controller.balanced_workers=tomcat1,tomcat2

#worker.controller.sticky_session=true

说明:此文件配置了 2 个 tomcat 服务器进行负载均衡处理   

5.  修改 tomcat 配置文件 server.xml

        更改其中一个的设置打开tomcat2/conf/server.xml 文件,修改里面所有的端口设置,将8 改为 9 ,如下:      
 

6.  编写一个测试页面 teat1.jsp

        建立一个 test 的 web 应用,里面新建一个 test1.jsp, 内容为

<%  @ page language =" java "  contentType = " text/html; charset=UTF-8" 

    pageEncoding
= " UTF-8 " 
%>
<! 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 >  test1 </title > 
</ head > 
< body > 
<%   

   System.out.println(
" ===========================" );

%> 
</ body > 
</ html >  


7.  
启动服务器并进行测试

        依次启动 apache-server 、 tomcat1 、tomcat2 ,通过   http://localhost/test/test1.jsp  访问,查看 tomcat1 的窗口,可以看到打印了一行"==========" ,再刷新一次, tomcat2 也打印了一条,再刷新,可以看到请求会被tomcat1,tomcat2 轮流处理, 实现了负载均衡

 

 


三、集群 
(session复制 )

只配置负载均衡还不行,还要 session 复制,也就是说其中任何一个tomcat 的添加的 session ,是要同步复制到其它 tomcat ,  集群内的 tomcat 都有相同的 session 

1. tomcat 配置

1.1  修改 tomcat1, tomcat2 的 server.xml 文件添加集群内容,tomcat5.5 无需添加,只需要去掉注释符, tomcat6.0需要添加,内容如下:

<Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"

                 managerClassName="org.apache.catalina.cluster.session.DeltaManager"

                 expireSessionsOnShutdown="false"

                 useDirtyFlag="true"

                 notifyListenersOnReplication="true"> 

            <Membership

                 className="org.apache.catalina.cluster.mcast.McastService"

                mcastAddr="228.0.0.4"

                mcastPort="45564"

                mcastFrequency="500"

                mcastDropTime="3000"/> 

            <Receiver

                 className="org.apache.catalina.cluster.tcp.ReplicationListener"

                tcpListenAddress="auto"

                 tcpListenPort="4001"

                tcpSelectorTimeout="100"

                tcpThreadCount="6"/> 

            <Sender

                 className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"

                replicationMode="pooled"

                ackTimeout="15000"

                waitForAck="true"/> 

            <Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"

                   filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>                  

            <Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"

                      tempDir="/tmp/war-temp/"

                      deployDir="/tmp/war-deploy/"

                      watchDir="/tmp/war-listen/"

                      watchEnabled="false"/>                     

                    <ClusterListener className="org.apache.catalina.cluster.session.ClusterSessionListener"/>

        </Cluster>

分别添加以上内容后,在 tomcat2 中,修改 tcpListenPort="4001"  为 4002 

1.2. Engine 增加 jvmRoute 属性设置, jvmRoute 的值来自于workers.properties 文件所设置的服务器名称。

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

#server  列表

worker.list =  controller,tomcat1,tomcat2

2.  添加 test.jsp 页面

2.1. test.jsp 添加以下内容:

<%  @ page contentType = " text/html; charset=UTF-8"  %>
<%  @ page import =" java.util.*"  %>

< html > 
< head > 
< 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.print(
" <b>Session 列表</b>" );
  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 ="test.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 >  

2.2.  修改 web.xml 文件,加入 <distributable/>节点,如下所示:

<? 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" xmlns:web ="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation ="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id ="WebApp_ID" version ="2.5"> 
  
< display-name >  test </display-name > 
  
< distributable/> 
  
< 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> 
</ web-app>

3. Session 复制测试

测试步骤如下:

1)         启动apache-server 、 tomcat1 、 tomcat2

2)         访问http://localhost/test/test.jsp,输入名称: test0001 、值: 123 并点击“提交查询内容”按钮,显示效果如下:

 

如上图所示, tomcat1 创建了一个新的 session , session 中有属性 test0001, 值为 123
 

3)         关闭tomcat1 服务器, tomcat1 端口为 8080 ,如下图:

4)         在页面中再次点击“提交查询内容”按钮,效果如下:

    前端页面并没有发生改变,接下来查看后台情况:
    

    
 如图所示,可以发现 session 已成功复制到tomcat2 中,以此证明 tomcat 集群已配置成功。 

5)         另外来看看不关闭tomcat1 服务器再次提交的情况

       
 如图所示,请求并没有转发到 tomcat2 服务器,而是再次转回tomcat1 服务器,这种情况是由于配置了jvmRoute 所致,以个人理解,配置了此属性后, apache-server 会根据session 情况来进行路由,同一个 session 会转发给同一个服务器。 

6)         打开一个新的IE 窗口,并访问 http://localhost/test/test.jsp

 

             
               
             
 新窗口的请求转发到了 tomcat2 服务器,session 的 id 为 DD9E6C8181653B9BCCF534FC8760B264.tomcat2 ,根据测试结果可以说明,在不发生服务器关闭的情况下,每个 session 会绑定到同一个服务器中,而不会在服务器间发生复制。

 

转自:http://www.blogjava.net/libin2722/articles/352842.html

Windows 10/11 安装 HYSPLIT 气象模型全攻略(附必备工具包下载清单) 本文提供了一份详尽的Windows 10/11系统下HYSPLIT气象模型安装与配置全攻略。指南涵盖了从核心认知、必备工具包(Tcl/Tk、ImageMagick)下载,到分步安装、环境变量设置及首次运行验证的完整流程,旨在帮助研究者和学生高效部署这一用于大气轨迹模拟与污染物扩散分析的专业工具。 阅读详情

相关推荐

Python-OPCUA 实现西门子PLC数据批量读写与自动化监控

本文详细介绍了如何使用Python结合OPC UA协议,实现对西门子PLC数据的批量读写与自动化监控。通过搭建开发环境、利用KEPserverEX作为通信桥梁,并配合Python代码实战,读者可以掌握高效的数据采集、批量写入以及构建带报警功能的监控系统的方法,从而大幅提升工业自动化场景下的数据处理效率和系统灵活性。

www00的博客 183

Apache HTTP Server详解

Apache HTTP Server(简称Apache),中文名:阿帕奇,是Apache软件基金会(Apache软件基金会(ASF)是一个非营利性组织,它为Apache社区的开源软件项目提供支持)的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩展,将Perl/Python等解释器编译...

顺其自然~专栏 8256

手把手教你用Xilinx Ultrascale+ FPGA解串12-bit ADC的LVDS信号(附Verilog代码)

本文详细介绍了如何使用Xilinx Ultrascale+ FPGA解串12-bit ADC的LVDS信号,涵盖硬件设计、时钟域处理和数据对齐等关键技术。通过Verilog代码实例和调试技巧,帮助工程师解决高速数据采集中的核心挑战,提升系统稳定性和性能。

weixin_42522964的博客 373

Apache Http Server

简介 Apache HTTP Server(简称Apache),是Apache软件基金会的一个开放源代码的网页服务器,可以在大多数电脑操作系统中运行,由于其具有的跨平台性和安全性,被广泛使用,是最流行的Web服务器端软件之一。 它快速、可靠并且可通过简单的API扩展,Perl/Python解释器可被编译到服务器中,可以创建一个每天有数百万人访问的Web服务器。 Apache和Tomcat区别 Apache侧重于HTTPServer ;Tomcat侧重于Servlet引擎,如果以Standalone方

AlbenXie的博客 4485

LLM之RAG实战(五十四)| 复杂文档处理RAG框架:Ragflow

RAGFlow 是一种结合了检索增强(Retrieval-Augmented Generation,RAG)与流程控制(Flow)的人工智能技术架构。它通过检索外部知识库中的信息,结合自然语言生成技术,为用户提供更准确、更丰富的回答。同时,它还引入了流程控制机制,能够根据任务需求动态调整信息检索和生成的流程,从而更好地完成复杂的任务。RAGFlow 的核心优势在于将检索和生成相结合,打破了传统生成模型仅依赖内部参数进行文本生成的局限。

wshzd的博客 1067

高等数学/概率论/数理统计/线性代数/离散数学面试-核心概念-问题理解

特征值与特征向量是线性代数中的概念,它们与线性变换有关。在线性变换中,如果存在非零向量 v ,使得当该向量通过变换后,其方向不变,只是长度发生了变化,那么这个向量 v 就是特征向量。而这个长度变化的比例因子,即变换前后向量长度的比值,称为特征值。数学公式表示:通俗易懂的解释:想象一下,你有一个可以伸缩的橡皮筋,这个橡皮筋可以代表一个向量。现在,你有一个特殊的机器,它可以改变橡皮筋的形状,但不会改变它延伸的方向。当你把橡皮筋放入机器中,机器会拉伸或压缩橡皮筋,但橡皮筋的方向保持不变。

m0_64198455的博客 2294

Apache 服务器的搭建和配置

Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一,Apache的主程序名为httpd。

2301_78315274的博客 5193

基于Python的二手奢侈品电商平台商品保值率数据爬取与分析

本文旨在探讨如何利用Python网络爬虫技术获取二手奢侈品电商平台商品数据,并通过数据分析研究奢侈品的保值率特性。研究将使用最新的爬虫技术(包括Playwright、异步处理和数据清洗技术)来高效获取数据,并利用Pandas、Matplotlib等数据分析库进行深入的数据可视化分析。本文详细介绍了爬虫的设计思路、实现过程以及数据分析方法,为奢侈品投资和消费提供数据参考。关键词:Python爬虫、奢侈品保值率、数据分析、Playwright、异步处理。

2201_76125261的博客 512

http协议工具:apache详解

本文主要介绍了Apache HTTP Server程序的相关配置,希望对你有帮助!

十七拾的博客 4039

【FastDDS】Layer DDS之Subscriber ( 09-Accessing received data)

Fast DDS提供了多种接收数据访问方式:通过读取(read)或提取(take)操作获取数据,其中提取会移除数据而读取保留数据。应用程序可通过序列高效借用接收队列内存,但需及时归还。数据处理时需检查SampleInfo的有效性,可通过监听器回调或等待集机制异步获取数据。等待集允许线程专门等待新数据到达,通过条件触发和超时控制实现可靠的数据接收处理。

Ray Home 863

【maven】idea左侧External Libraries里,没有Maven的依赖包 代码飘红

文章目录1.概述M.参考 1.概述 因为内网开发,然后这几天我被隔离了,然后公司搞了一个外网的vpn能连接的云桌面,云桌面也是网络隔离的,因此只能自己拷贝相关的文件到里面。 然后我就拷贝了代码和maven仓库中的一部分,因为本地的20G一次拷贝不完,需要多次拷贝,但是我拷贝了kafka,仍然飘红。具体如下 idea左侧External Libraries里,没有Maven的依赖包 然后整了很久都没搞定,后来我自己新建了一个项目,然后引入发现是不可以的,而且框框里面的飘红。 然后我就想是不是因为缺少依赖

九师兄 4412

Apache Http Server与Tomcat实现负载均衡和集群

一、分布式实现原理                 如上图所示,主要通过 Apache-Server 作为中转服务器,实现多个 tomcat 服务器之间的分布式处理,用户直接请求 Apache-Server ,然后 Apache-Server 会将请求分发到具体的 tomcat-server ,之后 tomcat-server 响应客户请求并返回结果到 Apache-S

dragon_fire的专栏 1230

华为OD机试双机位B卷 - 比赛的冠亚季军 (C++ & Python & JAVA & JS & GO)

华为OD机试双机位B卷 比赛的冠亚季军,提供Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解。 华为OD机试 比赛的冠亚季军

qq_45776114的博客 703

Tomcat实现java与http_Apache Http Server与Tomcat实现负载均衡和集群

如上图所示,主要通过Apache-Server作为中转服务器,实现多个tomcat服务器之间的分布式处理,用户直接请求Apache-Server,然后Apache-Server会将请求分发到具体的tomcat-server,之后tomcat-server响应客户请求并返回结果到Apache-Server,最后Apache-Server返回结果给用户文件说明:mod_jk.conf主要定义mod_j...

weixin_28931507的博客 265

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Apache HTTP Server + Tomcat的集群配置

如何应对大量请求所造成的服务器性能下降、崩溃 应用逻辑优化 服务器优化 增强服务器处理能力 增加服务器 增加逻辑应用服务器(纵向扩展) 增加硬件服务器(水平扩展) 此处不打算介绍各种各种方式的优劣,下文展示的是如何纵向扩展,搭建Tomcat集群。 Tomcat集群访问示意图: 搭建Apache HTTP Server     我的建议是最好在虚拟机里面做,并且在安装Apache HTTP Se

XiaoM的专栏 1201

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Tomcat(62)如何在Tomcat集群中实现负载均衡?

在Tomcat集群中实现负载均衡可以通过多种方式完成,最常见的方法是使用HTTP服务器如Apache HTTP Server与mod_jk模块、Nginx等作为负载均衡器。下面介绍如何使用Apache HTTP Server与mod_jk模块来实现Tomcat集群的负载均衡。

qq_43012298的博客 1224

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Apache HTTP server集群和负载均衡的配置

一、安装apache 1、安装依赖包,以下命令仅适用于centos服务器,suse服务器在运行yast2进行安装。 yum install gcc yum install apr yum install apr-util yum install pcre 解压apache安装包 tar -xjf httpd-2.2.6.tar.gz cd httpd-2.2.6/ 编译 ./configure -...

Liusha_night的博客 595

MATLAB compatloose,【转】Apache Http Server与Tomcat兑现负载均衡和集群

一、分布式实现原理如上图所示,主要通过Apache-Server作为中转服务器,实现多个tomcat服务器之间的分布式处理,用户直接请求Apache-Server,然后Apache-Server会将请求分发到具体的tomcat-server,之后tomcat-server响应客户请求并返回结果到Apache-Server,最后Apache-Server返回结果给用户二、...

weixin_39805409的博客 125

Windows 2003下配置Apache代理Tomcat集群

索引 0、工作原理1、软件准备       1.1 软件条目       1.2 安装JDK       1.3 安装Tomcat       1.4 安装Apache2、配置Tomcat集群       2.1 修改Tomcat默认应用       2.2 添加ROOT应用       2.3 修改server.xml       2.4 修改web.xml3、配置Apache HTTP代理

Mr_Von的专栏 1843

Apache Http Server与Tomcat7.0实现负载均衡与集群

1、使用的软件环境为: 下载地址:http://download.youkuaiyun.com/detail/cxb24008/6832515 http://download.youkuaiyun.com/detail/cxb24008/6832495 http://download.youkuaiyun.com/detail/cxb24008/6832463 2、实现原理: 如上图所示,主要通过 Apac

一杯清茶 859

结合Apache和Tomcat实现集群和负载均衡

1. Apache: apache 2.0.55 (由http://httpd.apache.org/进入下载)(点击下载apache 2.0.55) 2. Tomcat: Tomcat 5.5.25 (由http://tomcat.apache.org/进入下载)(点击下载Tomcat...

chenqunan3231的博客 109

Apache Http Server整合Tomcat集群

一.分布式原理 通过Apache-Server作为中转服务器,实现多个tomcat服务器之间的分布式处理,用户直接请求Apache-Server,然后Apache-Server会将请求分发到具体的tomcat-server,之后tomcat-server响应客户请求并返回...

227

apache tomcat linux集群配置,apache tomcat集群配置和负载均衡

1】 下载安装网页服务器Apache/IIS 用来连接后台Tomcat的模块,支持集群和负载均衡JK 分为两个版本 1,x 和 2.x ,其中 2.x 并不是最新的版本,它是 JK 的另外一个分支,后不知何因没有继续开发,因此2.x 版本已经废弃安装到指定目录,我安装的是C:\Program Files\Apache2.2,以后这个目录将用Apache_Home代替安装tomcat,我是将两个t...

weixin_39589693的博客 174
上一篇: EveryDay笔记
下一篇: 负载均衡技术解读
lvwenwenjava
博客等级 码龄15年 53粉丝 726原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值