apache2.2 tomcat6.0 负载均衡集群整理配置

worker.list=controller,tomcat1,tomcat2#server列表

#========tomcat1========

worker.tomcat1.port=8009#ajp13端口号,在tomcat下server.xml配置,默认8009

worker.tomcat1.host=localhost#tomcat的主机地址,如不为本机,请填写ip地址

worker.tomcat1.type=ajp13

worker.tomcat1.lbfactor=1#server的加权比重,值越高,分得的请求越多

#========tomcat2========

worker.tomcat2.port=8010#ajp13端口号,在tomcat下server.xml配置,默认8009

worker.tomcat2.host=localhost#tomcat的主机地址,如不为本机,请填写ip地址

worker.tomcat2.type=ajp13

worker.tomcat2.lbfactor=1#server的加权比重,值越高,分得的请求越多

#========controller,负载均衡控制器========

worker.controller.type=lb

worker.controller.balanced_workers=tomcat1,tomcat2#指定分担请求的tomcat

worker.controller.sticky_session=1

workers.tomcat_home=D:\tomcat6.0.18_clusterone#让mod_jk模块知道Tomcat的位置

workers.java_home=D:\Java\jdk1.6.0\jre#让mod_jk模块知道jre的位置

ps=\

worker.list=tomcat1#server列表,tomcat2,controller

#========tomcat1========

worker.tomcat1.port=8009#ajp13端口号,在tomcat下server.xml配置,默认8009

worker.tomcat1.host=localhost#tomcat的主机地址,如不为本机,请填写ip地址

worker.tomcat1.type=ajp13

worker.tomcat1.lbfactor=1#server的加权比重,值越高,分得的请求越多

#========tomcat2========

#worker.tomcat2.port=8010#ajp13端口号,在tomcat下server.xml配置,默认8009

#worker.tomcat2.host=localhost#tomcat的主机地址,如不为本机,请填写ip地址

#worker.tomcat2.type=ajp13

#worker.tomcat2.lbfactor=1#server的加权比重,值越高,分得的请求越多

#========controller,负载均衡控制器========

#worker.controller.type=lb

#worker.controller.balanced_workers=tomcat1,tomcat2#指定分担请求的tomcat这里balanced写错了,应是balance

#worker.controller.sticky_session=1

workers.tomcat_home=D:\tomcat6.0.18_clusterone#让mod_jk模块知道Tomcat的位置

workers.java_home=D:\Java\jdk1.6.0\jre#让mod_jk模块知道jre的位置

ps=\

worker.list=ajp13#模块版本

worker.ajp13.port=8009#工作端口,若没占用则不用修改

worker.ajp13.host=localhost#本机,若上面的Apache主机不为localhost,作相应修改

worker.ajp13.type=ajp13#类型

worker.ajp13.lbfactor=1#代理数,不用修改

===========================正确配置=======================

前期准备

下载mod_jk-1.2.28-httpd-2.2.3.so

http://apache.justdn.org/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/mod_jk-1.2.28-httpd-2.2.3.somod_jk-1.2.28-httpd-2.2.3.so

下载Apache2.2

下载tomcat6

环境

现在的环境,是在同一台机器中配置一个apache,两个tomcat

1\

apachehttp.conf

在文件尾增加

LoadModulejk_modulemodules\mod_jk-1.2.28-httpd-2.2.3.so

JkWorkersFile"D:\Apache2.2\conf\workers.properties"

JkMount/*.jspcontroller

JkLogFile"D:\Tomcat6.0\logs\mod_jk2.log"

JkLogLevelinfo

2\

新建workers.properties,并把workers.properties也放在D:\Apache2.2\conf\workers.properties目录下

并在文件中增加如下内容

worker.list=controller,tomcatone,tomcattwo#server列表,tomcat2,controller

#========tomcat1========

worker.tomcatone.port=8009#ajp13端口号,在tomcat下server.xml配置,默认8009

worker.tomcatone.host=localhost#tomcat的主机地址,如不为本机,请填写ip地址

worker.tomcatone.type=ajp13

worker.tomcatone.lbfactor=1#server的加权比重,值越高,分得的请求越多

#========tomcat2========

worker.tomcattwo.port=8010#ajp13端口号,在tomcat下server.xml配置,默认8009

worker.tomcattwo.host=localhost#tomcat的主机地址,如不为本机,请填写ip地址

worker.tomcattwo.type=ajp13

worker.tomcattwo.lbfactor=1#server的加权比重,值越高,分得的请求越多

#========controller,负载均衡控制器========

worker.controller.type=lb

worker.controller.balance_workers=tomcatone,tomcattwo#指定分担请求的tomcat这里balanced写错了,应是balance

worker.controller.sticky_session=1

3\如果在同一台机,增加两个Tomcat服务

a:D:\tomcat6.0.18_clusterone

b:D:\tomcat6.0.18_clustertwo

c修改,a与b中的内容

a:中的相应内容为

第二处:<Connectorport="8086"maxHttpHeaderSize="8192"

maxThreads="150"minSpareThreads="25"maxSpareThreads="75"

enableLookups="false"redirectPort="8443"acceptCount="100"

connectionTimeout="20000"disableUploadTimeout="true"/>

原来为

<Connectorport="8086"protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443"/>

第三处:<Enginename="Catalina"defaultHost="localhost"jvmRoute="tomcatone">

原来为

<Enginename="Catalina"defaultHost="localhost">(注:其实这行原来存在,只是把其注释掉)

b:中的相应内容为

第一处:<Serverport="8007"shutdown="SHUTDOWN">=====原来为====><Serverport="8006"shutdown="SHUTDOWN">

第二处:<Connectorport="8087"maxHttpHeaderSize="8192"

maxThreads="150"minSpareThreads="25"maxSpareThreads="75"

enableLookups="false"redirectPort="8443"acceptCount="100"

connectionTimeout="20000"disableUploadTimeout="true"/>

原来为

<Connectorport="8086"protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443"/>

第三处:<Enginename="Catalina"defaultHost="localhost"jvmRoute="tomcattwo">

原来为

<Enginename="Catalina"defaultHost="localhost">(注:其实这行原来存在,只是把其注释掉)

4\增加虚似目录(注,把"1\"中的"JkMount/*.jspcontroller"注释掉)

<VirtualHost*:8089>

[email protected]

DocumentRootd:/www/wabappone/ROOT

ServerNamewww.wabappone.com

ServerAliaswabappone

ErrorLog"logs/wabappone.localhost-error.log"

CustomLog"logs/wabappone.localhost-access.log"common

JkMount/*.jspcontroller

#把JSPX程序映射到Jk连接器上

JkMount/*.jspxcontroller

#把servlet程序映射到Jk连接器上

JkMount/servlet/*controller

JkMount/*.servletcontroller

</VirtualHost>

==================================

注:apache与tomcat本来就能正常使用的前提下

==================================

能过以上四步负载作用了

============测试jsp文件====把下面内容保存成test.jsp文件并copy到相应目录下========================

<%@pagecontentType="text/html;charset=GBK"%>

<%@pageimport="java.util.*"%>

<html><head><title>ClusterAppTest</title></head>

<body>

ServerInfo:

<%

out.println(request.getLocalAddr()+":"+request.getLocalPort()+"<br>");%>

<%

out.println("<br>ID"+session.getId()+"<br>");

//如果有新的Session属性设置

StringdataName=request.getParameter("dataName");

if(dataName!=null&&dataName.length()>0){

StringdataValue=request.getParameter("dataValue");

session.setAttribute(dataName,dataValue);

}

out.print("<b>Session列表</b>");

Enumeratione=session.getAttributeNames();

while(e.hasMoreElements()){

Stringname=(String)e.nextElement();

Stringvalue=session.getAttribute(name).toString();

out.println(name+"="+value+"<br>");

System.out.println(name+"="+value);

}

%>

<formaction="test.jsp"method="POST">

名称:<inputtype=textsize=20name="dataName">

<br>

值:<inputtype=textsize=20name="dataValue">

<br>

<inputtype=submit>

</form>

</body>

</html>

==============================================================================================

5\

在tomcat中的conf目录下的server.xml文件增加以下内容

把server.xml中注释部分<!--<Clusterclassname="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>-->替换成如下内容

==========================================================================

<Clusterclassname="org.apache.catalina.ha.tcp.SimpleTcpCluster"

channelSendOptions="8">

<!--

<Managerclassname="org.apache.catalina.ha.session.BackupManager"

expireSessionsOnShutdown="false"

notifyListenersOnReplication="true"

mapSendOptions="8"/>-->

<!---->

<Managerclassname="org.apache.catalina.ha.session.DeltaManager"

expireSessionsOnShutdown="false"

notifyListenersOnReplication="true"/>

<Channelclassname="org.apache.catalina.tribes.group.GroupChannel">

<Membershipclassname="org.apache.catalina.tribes.membership.McastService"

address="228.0.0.4"

port="45564"

frequency="500"

dropTime="3000"/>

<Receiverclassname="org.apache.catalina.tribes.transport.nio.NioReceiver"

address="auto"

port="4000"

autoBind="100"

selectorTimeout="5000"

maxThreads="6"/>

<!--timeout="60000"-->

<Senderclassname="org.apache.catalina.tribes.transport.ReplicationTransmitter">

<Transportclassname="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>

</Sender>

<Interceptorclassname="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>

<Interceptorclassname="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>

<Interceptorclassname="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>

</Channel>

<Valveclassname="org.apache.catalina.ha.tcp.ReplicationValve"filter=""/>

<Valveclassname="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

<ClusterListenerclassname="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>

<ClusterListenerclassname="org.apache.catalina.ha.session.ClusterSessionListener"/>

</Cluster>

==========================================================================

6\

站点web.xml中加入<distributable/>,distributable元素来告诉servlet/JSP容器,编写将在分布式Web容器中部署的应用

=====================

以上配置经测试,情况如下

1\在ie中运行test.jsp

出现

ServerInfo:null:8089

IDB4D24ADB547DEAAE02B35CC72A2BC147.tomcatone

Session列表asfdasdf=asdf

不断的刷,仍显示的是"IDB4D24ADB547DEAAE02B35CC72A2BC147.tomcatone",说明没有变,

但我把tomcattwo这个tomcat站点关掉时

出现

ServerInfo:null:8089

IDB4D24ADB547DEAAE02B35CC72A2BC147.tomcattwo

Session列表asfdasdf=asdf

这时就变了,为什么一定要关掉一个服务才能执行test.jsp时,结果才能变呢(即自动在两个站点间切换以达以分流负载均衡作用)

现在的环境,是在一台机器中配置一个apache,两个tomcat

2\如果新开ie,则sessionID会变了,说明配置成功

===============================================================================================================================

注意:对于webservice的集群,特别要注意CommonBusiness.wsdl中的

<wsdl:portbinding="impl:CommonBusinessSoapBinding"name="CommonBusiness">

<wsdlsoap:addresslocation="http://www.jobservice.com:8089/JobService/services/CommonBusiness"/>

</wsdl:port>

此处要与apachehttp中的httpd-vhosts.conf的端口一致,并且需增加如下行

JkMount/JobService/services/CommonBusinesscontroller()

===============================================================================================================================

=====================

===================================================

===================================================

=============更深入的配置方式(集群)===============

===================================================

===================================================

先配置成可扩散的服务,以可以灵活的增加数据处理服务端(数据处理服务端往往压大)

windows环境下安装myphpadmin

1\php5

得到php.ini文件(在D:\php5目录下有一个这样的文件,只需改一下名字就ok)

增加环境变量(在path环境变量中增加)d:\php5;d:\php5\ext

php.ini在实际应用中要做相应修改

2\apache中的http.conf的修改

a:

在#LoadModulevhost_alias_modulemodules/mod_vhost_alias.so后面加上以下两行

LoadModulephp5_moduled:/php5/php5apache2_2.dll

PHPIniDir"d:/php5"

b:修改http.conf相应位置

<Directory"D:/www">

OptionsIndexesFollowSymLinks

AllowOverrideNone

Orderallow,deny

Allowfromall

</Directory>

c:

在AddTypeapplication/x-gzip.gz.tgz后面加上以下两行

AddTypeapplication/x-httpd-php.php

AddTypeapplication/x-httpd-php.html

d:增加index.php

<IfModuledir_module>

DirectoryIndexindex.htmlindex.jspindex.php

</IfModule>

e:

#Includeconf/extra/httpd-vhosts.conf中的"#"去除

修改httpd-vhosts.conf文件为如下内容

#

#Usename-basedvirtualhosting.

#

NameVirtualHost*:8089

#

#VirtualHostexample:

#AlmostanyApachedirectivemaygointoaVirtualHostcontainer.

#ThefirstVirtualHostsectionisusedforallrequeststhatdonot

#matchaServerNameorServerAliasinany<VirtualHost>block.

#

<VirtualHost*:8089>

[email protected]

DocumentRootd:/www/wabappone/ROOT

ServerNamewww.wabappone.com

ServerAliaswabappone

ErrorLog"logs/wabappone.localhost-error.log"

CustomLog"logs/wabappone.localhost-access.log"common

JkMount/*.jspcontroller

#把JSPX程序映射到Jk连接器上

JkMount/*.jspxcontroller

#把servlet程序映射到Jk连接器上

JkMount/servlet/*controller

JkMount/*.servletcontroller

</VirtualHost>

3\

phpmyadmin的安装配置

打开phpmyadmin目录中的config.inc.php找到以下这些:

$cfg[’PmaAbsoluteUri’]=’http://localhost/phpmyadmin’;//假设是有域名的服务器,可改成http://域名/phpmyadmin

$cfg[’Servers’][$i][’user’]=’admin’;

$cfg[’Servers’][$i][’password’]=’00000000’;//分别填上你mysql的用户和密码

$cfg[’Servers’][$i][’auth_type’]=’http’;//这里也可以改为cookie

改好了保存,在浏览器打开http://localhost/phpmyadmin(/index.php)输入你的用户名和密码,便可以管理mysql了.

4\修改

d:\php5\php.ini

把如下四行中的";"去掉

;extension=php_mcrypt.dll

;extension=php_msql.dll

;extension=php_mssql.dll

;extension=php_mysql.dll

;extension=php_mysqli.dll

;extension=php_mbstring.dll

====================================

urlrewrite

====================================

1、在httpd.conf中搜索LoadModulerewrite_module,将该行前面的#号删除。

2、将下面的内容加入在</VirtualHost>之前

 <IfModulemod_rewrite.c>

 RewriteEngineOn

 RewriteRule^(.*)/testrewrite.html$$1/index.php

</IfModule>

技巧:

果在httpd中打开调用rewrite_module的设置,查看一下是不是能调用了,要通过httpd-M的参数来查看;

#/usr/sbin/httpd-M

==================================

======支持php的基本配置步骤==========

==================================

==================================

配置支持php的步骤

首先要下载

apache2.2

php5

1\

在php5目录下找到php.ini文件,查看解压缩后的文件夹内容,找到“php.ini-dist”文件,将其重命名为“php.ini”,打开编辑,找到下面图中的地方,Ln385,有一个“register_globals=Off”值,这个值是用来打开全局变量的,比如表单送过来的值,如果这个值设为“Off”,就只能用“$_POST['变量名']、$_GET['变量名']”等来取得送过来的值,如果设为“On”,就可以直接使用“$变量名”来获取送过来的值,当然,设为“Off”就比较安全,不会让人轻易将网页间传送的数据截取。这个值是否改成“On”就看自己感觉了,是安全重要还是方便重要?

2\——在“我的电脑”上右键,“属性”,选择“高级”标签,点选“环境变量”,在“系统变量”下找到“Path”变量,选择,双击或点击“编辑”,将“;D:\php;D:\php\ext”加到原有值的后面,当然,其中的“D:\php”是我的安装目录,你要将它改为自己的php安装目录

E:\DEDECMS\php5;E:\DEDECMS\php5\ext

3\

加入到#LoadModulevhost_alias_modulemodules/mod_vhost_alias.so后面

LoadModulephp5_moduleE:/DEDECMS/php5/php5apache2_2.dll

PHPIniDir"E:/DEDECMS/php5"

4\

AddTypeapplication/x-httpd-php.php

AddTypeapplication/x-httpd-php.html

/index.html出现

出现Parseerror:syntaxerror,unexpectedT_STRING

取消AddTypeapplication/x-httpd-php.html这句就ok了,真tmd怪了

发现与php.ini中的;extension=php_mbstring.dll这行取消";"有关

要么取消http.conf中

AddTypeapplication/x-httpd-php.html

或php.ini中的改为

;extension=php_mbstring.dll

则正常运行

====================================

参看http://www.idouye.com爱豆叶资料分享

相关推荐