apache2.2 tomcat6 jk 负载均衡, 做backup server

2024-04-16 14:38

本文主要是介绍apache2.2 tomcat6 jk 负载均衡, 做backup server,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.下载 在http://tomcat.apache.org/connectors-doc/

下载JK-1.2.30

mod_jk-1.2.30-httpd-2.2.3.so    

apache2.2,tomcat6,下载下来

2. 把

mod_jk-1.2.30-httpd-2.2.3.so    

放到apache2.2/modules下

 

3. apache2.2 配置3个文件:

 

(1)mod_jk.conf #负责配置mod-jk 模块新建一个文件,放置在apache2.2/conf/extra 文件夹下

 

内容:

#####################
# jk module
#####################

#加载jk模块
LoadModule jk_module modules/mod_jk-1.2.30-httpd-2.2.3.so


#表明workers文件,里面配置的workers用于负责响应不同请求,负载均衡等
JkWorkersFile conf/workers.properties

 

#用于配置特定uri由哪个worker来响应
JkMountFile conf/uriworkermap.properties

 

#日志文件
JkLogFile logs/mod_jk.log

 

#日志打印级别
JkLogLevel info

 

#日志格式
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

 

#请求日志
JkRequestLogFormat "%w %V %T"

 

#有种status worker,用于监控 mod-jk状态
#限制worker jk-manager 只能在本地访问
<Location /jk-manager>
    JkMount jk-manager
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Location>

 

 

(2)workers.properties 里面配置的workers用于负责响应不同请求,负载均衡等

此文件可在 jk 项目的源文件里获得到

 

内容:

 

写道
# Licensed to the Apache Software Foundation (ASF) under one or more
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Note that the distributed version of this file requires modification
# before it is usable.
#
# Reference documentation: http://tomcat.apache.org/connectors-doc/reference/workers.html
#
# As a general note, the characters $( and ) are used internally to define
# macros. Do not use them in your own configuration!!!
#
# Whenever you see a set of lines such as:
# x=value
# y=$(x)\something
#
# the final value for y will be value\something

# Define two status worker:
# - jk-status for read-only use
# - jk-manager for read/write use
worker.list=jk-status
worker.jk-status.type=status
worker.jk-status.read_only=true

worker.list=jk-manager
worker.jk-manager.type=status

# We define a load balancer worker
# with name "balancer"
worker.list=balancer
worker.balancer.type=lb
# error_escalation_time: seconds, default = recover_time/2 (=30)
# Determines, how fast a detected error should switch from
# local error state to global error state
# Since: 1.2.28
worker.balancer.error_escalation_time=0

# - max_reply_timeouts: number, default=0
# If there are to many reply timeouts, a worker
# is put into the error state, i.e. it will become
# unavailable for all sessions residing on the respective
# Tomcat. The number of tolerated reply timeouts is
# configured with max_reply_timeouts. The number of
# timeouts occuring is divided by 2 once a minute and the
# resulting counter is compared against max_reply_timeouts.
# If you set max_reply_timeouts to N and the errors are
# occuring equally distributed over time, you will
# tolerate N/2 errors per minute. If they occur in a burst
# you will tolerate N errors.
# Since: 1.2.24
worker.balancer.max_reply_timeouts=10



# Now we add members to the load balancer
# First member is "node1", most
# attributes are inherited from the
# template "worker.template".
worker.balancer.balance_workers=node1
worker.node1.reference=worker.template
worker.node1.host=localhost
worker.node1.port=8109
# Activation allows to configure
# whether this node should actually be used
# A: active (use node fully)
# D: disabled (only use, if sticky session needs this node)
# S: stopped (do not use)
# Since: 1.2.19
worker.node1.activation=A

# Second member is "node2", most
# attributes are inherited from the
# template "worker.template".
worker.balancer.balance_workers=node2
worker.node2.reference=worker.template
worker.node2.host=localhost
worker.node2.port=8209
# Activation allows to configure
# whether this node should actually be used
# A: active (use node fully)
# D: disabled (only use, if sticky session needs this node)
# S: stopped (do not use)
# Since: 1.2.19
worker.node2.activation=A

# Finally we put the parameters
# which should apply to all our ajp13
# workers into the referenced template
# - Type is ajp13
worker.template.type=ajp13

# - socket_connect_timeout: milliseconds, default=0
# Since: 1.2.27
worker.template.socket_connect_timeout=5000

# - socket_keepalive: boolean, default=false
# Should we send TCP keepalive packets
# when connection is idle (socket option)?
worker.template.socket_keepalive=true

# - ping_mode: Character, default=none
# When should we use cping/cpong connection probing?
# C = directly after establishing a new connection
# P = directly before sending each request
# I = in regular intervals for idle connections
# using the watchdog thread
# A = all of the above
# Since: 1.2.27
worker.template.ping_mode=A

# - ping_timeout: milliseconds, default=10000
# Wait timeout for cpong after cping
# Can be overwritten for modes C and P
# Using connect_timeout and prepost_timeout.
# Since: 1.2.27
worker.template.ping_timeout=10000

# - connection_pool_minsize: number, default=connection_pool_size
# Lower pool size when shrinking pool due
# to idle connections
# We want all connections to be closed when
# idle for a long time in order to prevent
# firewall problems.
# Since: 1.2.16
worker.template.connection_pool_minsize=0

# - connection_pool_timeout: seconds, default=0
# Idle time, before a connection is eligible
# for being closed (pool shrinking).
# This should be the same value as connectionTimeout
# in the Tomcat AJP connector, but there it is
# milliseconds, here seconds.
worker.template.connection_pool_timeout=600

# - reply_timeout: milliseconds, default=0
# Any pause longer than this timeout during waiting
# for a part of the reply will abort handling the request
# in mod_jk. The request will proceed running in
# Tomcat, but the web server resources will be freed
# and an error is send to the client.
# For individual requests, the timeout can be overwritten
# by the Apache environment variable JK_REPLY_TIMEOUT.
# JK_REPLY_TIMEOUT since: 1.2.27
worker.template.reply_timeout=300000

# - recovery_options: number, default=0
# Bit mask to configure, if a request, which was send
# to a backend successfully, should be retried on another backend
# in case there's a problem with the response.
# Value "3" disables retries, whenever a part of the request was
# successfully send to the backend.
worker.template.recovery_options=3
 

(3)uriworkermap.properties

 

/*=balancer
/jk-manager=jk-manager

!/*.gif=balancer
!/*.jpg=balancer
!/*.png=balancer
!/*.css=balancer
!/*.js=balancer
!/*.htm=balancer
!/*.html=balancer
!/*.exe=balancer
!/*.rar=balancer
!/*.zip=balancer
!/*.txt=balancer
!/*.xml=balancer

 

4.tomcat6配置文件

将tomcat6解压到两个文件夹下,分别作为负载均衡的应用服务器node1,node2

将node1,node2的server.xml中的端口都改下,否则冲突起不来,如下

node1:

(1)

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

改成

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

(2)

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

 

改成

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

(3)

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

改成

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

 

node2同理分别改成 8205 8280 8209

 

5.测试。重启apache 服务器,启动tomcat6 node1,node2

新建文件夹 testloadblance,里面建一个1.jsp

内容:

<%

System.out.println("this is a test !");

%>

将testloadblance分别复制到 node1,node2的webapps文件夹下,

在浏览器里输入网址 http://localhost:8080/testloadblance/1.jsp

会在 node1,node2的控制台下看到输出。表明成功

如下图:

 

 

6.做backup server,位保持企业应用的高可用性,需要做好备用服务器

利用上面的配置稍作修改即可,

(1)在worker.properties里添加:

worker.node1.redirect=node2#出错就转发到节点2

(2)

worker.node2.activation=A

改成

#disabled,除非发生了错误并且处理失败了,否则就禁用所有发给worker2的请求

worker.node2.activation=D

 

ok,重启所有服务器,刷新页面,会发下只有节点1 node1有响应了,把node1 shutdown,在刷新页面,会发现node2开始响应了,ok

这篇关于apache2.2 tomcat6 jk 负载均衡, 做backup server的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/909075

相关文章

Hadoop集群数据均衡之磁盘间数据均衡

生产环境,由于硬盘空间不足,往往需要增加一块硬盘。刚加载的硬盘没有数据时,可以执行磁盘数据均衡命令。(Hadoop3.x新特性) plan后面带的节点的名字必须是已经存在的,并且是需要均衡的节点。 如果节点不存在,会报如下错误: 如果节点只有一个硬盘的话,不会创建均衡计划: (1)生成均衡计划 hdfs diskbalancer -plan hadoop102 (2)执行均衡计划 hd

一种改进的red5集群方案的应用、基于Red5服务器集群负载均衡调度算法研究

转自: 一种改进的red5集群方案的应用: http://wenku.baidu.com/link?url=jYQ1wNwHVBqJ-5XCYq0PRligp6Y5q6BYXyISUsF56My8DP8dc9CZ4pZvpPz1abxJn8fojMrL0IyfmMHStpvkotqC1RWlRMGnzVL1X4IPOa_  基于Red5服务器集群负载均衡调度算法研究 http://ww

red5-server源码

red5-server源码:https://github.com/Red5/red5-server

【微服务】Ribbon(负载均衡,服务调用)+ OpenFeign(服务发现,远程调用)【详解】

文章目录 1.Ribbon(负载均衡,服务调用)1.1问题引出1.2 Ribbon负载均衡1.3 RestTemplate整合Ribbon1.4 指定Ribbon负载均衡策略1.4.1 配置文件1.4.2 配置类1.4.3 定义Ribbon客户端配置1.4.4 自定义负载均衡策略 2.OpenFeign面向接口的服务调用(服务发现,远程调用)2.1 OpenFeign的使用2.1 .1创建

安装SQL2005后SQL Server Management Studio 没有出来的解决方案

一种情况,在安装 sqlServer2005 时 居然出现两个警告: 1 Com+ 目录要求 2 Edition change check 郁闷!网上说出现两个警告,是肯定装不成功的!我抱着侥幸的态度试了下,成功了。 安装成功后,正准备 “ 仅工具、联机丛书和示例(T)” 但是安装不了,他提示我“工作站组件”安装过了对现有组件无法更新或升级。 解决办法: 1 打开“控

ERROR 2003 (HY000): Can't connect to MySQL server on (10061)

在linux系统上装了一个mysql-5.5,启动后本机都是可以访问的,操作都正常,同时建了一个%的用户(支持远程访问), root@debian:/# mysql -u loongson -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id

MySQL数据库负载均衡

数据库负载均衡是通过将数据库请求分散到多个数据库服务器上,以提高数据库的处理能力和可用性。在高并发的场景下,使用数据库负载均衡器可以有效避免单点故障,提高系统的整体性能和可靠性。 数据库负载均衡器 数据库负载均衡器可以是硬件设备或软件解决方案。在MySQL环境中,一些流行的数据库负载均衡器包括: MySQL Proxy:MySQL Proxy是一个简单的中间件,用于监控、分析或增强对MySQ

Oracle和Sql_Server 部分sql语句的区别

比如:A表中, 字段:gxmlflag  number;  比如数据:20210115 字段:gxmldate date ;    比如数据:2021-01-15 09:50:50 一、在Oracle数据库中: 1、insert 和 update 语句: t.gxmlflag = to_char(sysdate,'yyyymmdd'),t.gxmldate=sysdate 比如:update f

828华为云征文|基于华为云Flexus X实例搭建Nginx集群负载均衡

目录 前言 一、Flexus云服务器X介绍 1.1 Flexus云服务器X实例简介 1.2 Flexus X实例购买 1.3 登录服务器 三、Springboot集群服务 3.1 部署9901节点服务 3.2 部署9902节点服务 四、Nginx负载均衡配置 五、集群负载调用测试 5.1 负载调用9901端口 5.2 负载调用9901端口 总结 前言 华为云Flexus X实例凭借其

【VueJS】live-server 快速搭建服务 及 注意事项

本地开发常常需要搭建临时的服务,第一时间我们会想到用 http-server。 但现在流行修改文件浏览器自动刷新,这里可以使用 live-server 很简单就能启动一个看起来很专业的本地服务。 你只需要全局安装live-server: npm install -g live-server 并在项目根目录执行这条命令: PS E:\AblazeProject\Vue> live-serv