`
nirvana_blanks
  • 浏览: 39735 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Ubuntu下 apache2.2.x + mod_jk + tomcat负载均衡~

阅读更多

一、安装apache、tomcat、mod_jk

今天实验了apache + jk + tomcat做负载均衡

首先准备好apache2、tomcat5

然后从下面的网址下载对应自己apache版本的jk(mod_jk-1.2.31-httpd-2.2.x.so 或者 mod_jk-1.2.31-httpd-2.0.x.so

http://apache.etoak.com//tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.31/i386/

  • mod_jk-1.2.31-httpd-2.2.x.so is for Apache 2.2.x. It has been build against version 2.2.3, but should work with Apache 2.2.0 and later. Rename to mod_jk.so before putting it in your modules directory or adjust your LoadModule statement.
  • mod_jk-1.2.31-httpd-2.0.x.so is for Apache 2.0.x. It has been build against version 2.0.52. Rename to mod_jk.so before putting it in your modules directory or adjust your LoadModule statement.

apache安装在 /usr/local/apache2,tomcat安装两个分别是 /usr/local/tomcat1 和/usr/local/tomcat2

将下载到的 mod_jk重命名为mod_jk.so,复制到/usr/local/apache2/modules/目录下。

二、修改tomcat对应Connector端口

现在apache tomcat mod_jk已经都准备好了,再开始配置之前,我们首先需要修改一下其中一个tomcat的对应端口

cd /usr/local/tomcat1/conf

sudo vi server.xml

找到:

 
    <Connector port="8080" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />
 

 修改为:

    <Connector port="8081" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />
 

找到:

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

 修改为:

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

 这样两个tomcat对应的端口分别为 8080,8081 既可以通过localhost:8080 和localhost:8081分别访问两个tomcat

三、配置worker.properties

下面我们在apache的conf目录下创建一个worker.propertis文件

sudo vi worker.properties

 内容为:

#worker.properties
worker.list = controller,tomcat1,tomcat2 
#server 列表
#========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========
#ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.port=8109       
#tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.host=localhost  
worker.tomcat1.type=ajp13
#server的加权比重,值越高,分得的请求越多
worker.tomcat2.lbfactor = 1
#========controller,负载均衡控制器========
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2  
#指定分担请求的tomcat
worker.controller.sticky_session=1              

 四、修改apache配置文件,使其加载mod_jk.so插件

然后修改apache的配置文件(/usr/local/apache2/conf/httpd.conf)

cd /usr/local/apache2/conf/

sudo vi httpd.conf

在httpd.conf文件最后加入:

#加载mod_jk Module
LoadModule jk_module modules/mod_jk.so
#JkWorkers配置文件
JkWorkersFile conf/workers.properties
# mod_jk的日志文件
JkLogFile logs/mod_jk.log
# The log level:
# - info log will contain standard mod_jk activity (default).
# - warn log will contain non fatal error reports.
# - error log will contain also error reports.
# - debug log will contain all information on mod_jk activity
# - trace log will contain all tracing information on mod_jk activity
JkLogLevel info
# Assign specific URLs to Tomcat. In general the structure of a
# JkMount directive is: JkMount [URL prefix] [Worker name]
# send all requests ending in .jsp to ajp13_worker
JkMount /*.jsp controller
# send all requests ending /servlet to ajp13_worker
JkMount /*/servlet/ controller
# send all requests endig in .service to ajp13_worker
JkMount /*.service controller
JkMount /* controller
# JkUnmount directive acts as an opposite to JkMount and blocks access
# to a particular URL. The purpose is to be able to filter out the
# particular content types from mounted context.
# do not send requests ending with .gif to ajp13_worker
#JkUnMount /servlet/*.gif controller
# JkMount / JkUnMount directives can also be used inside <VirtualHost>
# sections of your httpd.conf file. 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics