posts - 18,  comments - 0,  trackbacks - 0

          Apache + Tomcat集群配置方案

          ---------- 黃建德 2005-12-02

          ?

          1、? 下載mod_jk2.so/mod_jk.so,并拷貝文件到Apache\modules目錄

          mod_jk-1.2.14-apache-2.0.54.so/mod_jk-2.0.4-apache-2.0.49.so

          2、? 配置conf\httpd.conf文件內(nèi)容

          #======================================#

          # 加載mod_jk2/mod_jk

          #LoadModule jk2_module modules/mod_jk2.so(加載mod_jk)

          LoadModule jk2_module modules/mod_jk2.so

          ?

          #--------以下為mod_jk時配置---------#

          # 配置mod_jk

          JkWorkersFile conf/workers.properties

          JkLogFile logs/mod_jk.log

          JkLogLevel info

          #請求分發(fā),對jsp文件,.do等動態(tài)請求交由tomcat處理

          #DocumentRoot "C:/Apache/htdocs"

          JkMount /*.jsp loadbalancer

          JkMount /*.do loadbalancer

          JkMount /servlet/* loadbalancer

          #--------以上為mod_jk時配置---------#

          ?

          #關(guān)掉主機Lookup,如果為on,很影響性能,可以有10多秒鐘的延遲。

          HostnameLookups Off

          ?

          #緩存配置

          LoadModule cache_module modules/mod_cache.so

          LoadModule disk_cache_module modules/mod_disk_cache.so

          LoadModule mem_cache_module modules/mod_mem_cache.so

          ?

          #一個連接的最大請求數(shù)量

          MaxKeepAliveRequests 10000

          #NT環(huán)境,只能配置這個參數(shù)來提供性能

          <IfModule mpm_winnt.c>

          ???? #每個進程的線程數(shù),最大1920。NT只啟動父子兩個進程,不能設(shè)置啟動多個進程

          ???? ThreadsPerChild 1900

          ???? #每個子進程能夠處理的最大請求數(shù)

          ???? MaxRequestsPerChild? 10000

          </IfModule>

          ?

          <IfModule mod_cache.c>

          ? CacheForceCompletion 100

          ? CacheDefaultExpire 3600

          ? CacheMaxExpire 86400

          ? CacheLastModifiedFactor 0.1

          ?

          ? <IfModule mod_disk_cache.c>

          ???? ???? CacheEnable disk /

          ???? ???? CacheRoot c:/cacheroot

          ???? ???? CacheSize 327680

          ???? ???? CacheDirLength 4

          ???? ???? CacheDirLevels 5

          ???? ???? CacheGcInterval 4

          ? </IfModule>

          ? <IfModule mod_mem_cache.c>

          ???? ???? CacheEnable mem /

          ???? ???? MCacheSize 8192

          ???? ???? MCacheMaxObjectCount 10000

          ???? ???? MCacheMinObjectSize 1

          ???? ???? MCacheMaxObjectSize 51200

          ? </IfModule>

          </IfModule>

          #======================================#

          3、? Apache\conf目錄增加文件workers2.properties/workers.properties:

          u??????? workers2.properties內(nèi)容:

          [logger.apache2]

          level=ERROR

          ?

          #shm必須配

          [shm]

          file=${serverRoot}/logs/shm.file

          size=1048576

          ?

          # 第一個tomcat的地址

          #The socket channel, override port and host.

          [channel.socket:tomcat1]

          port=8009

          host=127.0.0.1

          # 定義第一個工作者指向第一個tomcat

          # define the worker

          [ajp13:tomcat1]

          channel=channel.socket:tomcat1

          ?

          #第二個tomcat的地址

          #The socket channel, override port and host.

          [channel.socket:tomcat2]

          port=12009

          host=127.0.0.1

          # 定義第二個工作者指向第二個tomcat

          # define the worker

          [ajp13:tomcat2]

          channel=channel.socket:tomcat2

          ?

          #定義負載均衡器,使其包含兩個工作者

          [lb:lb1]

          worker=ajp13:tomcat1

          worker=ajp13:tomcat2

          ?

          #指定負載均衡器完成單一地址映射,使得apache服務(wù)所在的uri全部指向兩個tomcat上的root

          # Uri mapping

          [uri:/*]

          [uri:/*.jsp]

          [uri:/*.do]

          [uri:/servlet/*]

          group=lb:lb1

          u??????? workers.properties內(nèi)容:

          [logger.apache2]

          level=DEBUG

          ?

          #shm必須配

          [shm]

          file=${serverRoot}/logs/shm.file

          size=1048576

          ?

          # list the workers by name

          worker.list=tomcat1, tomcat2, loadbalancer

          ?

          # ------------------------

          # First tomcat server

          # ------------------------

          worker.tomcat1.port=8009

          worker.tomcat1.host=localhost

          worker.tomcat1.type=ajp13

          ?

          # Specify the size of the open connection cache.

          #worker.tomcat1.cachesize

          ?

          # Specifies the load balance factor when used with

          # a load balancing worker.

          # Note:

          #? ----> lbfactor must be > 0

          #? ----> Low lbfactor means less work done by the worker.

          worker.tomcat1.lbfactor=900

          ?

          # ------------------------

          # Second tomcat server

          # ------------------------

          worker.tomcat2.port=12009

          worker.tomcat2.host=localhost

          worker.tomcat2.type=ajp13

          ?

          # Specify the size of the open connection cache.

          #worker.tomcat2.cachesize

          ?

          # Specifies the load balance factor when used with

          # a load balancing worker.

          # Note:

          #? ----> lbfactor must be > 0

          #? ----> Low lbfactor means less work done by the worker.

          worker.tomcat2.lbfactor=2000

          ?

          # ------------------------

          # Load Balancer worker

          # ------------------------

          #

          # The loadbalancer (type lb) worker performs weighted round-robin

          # load balancing with sticky sessions.

          # Note:

          #? ----> If a worker dies, the load balancer will check its state

          #??????? once in a while. Until then all work is redirected to peer

          #??????? worker.

          worker.loadbalancer.type=lb

          worker.loadbalancer.balanced_workers=tomcat1,tomcat2

          ?

          # ------------------------

          # END workers.properties

          # ------------------------

          4、? 配置TOMCAT的 負載平衡

          u??????? 配置第一個TOMCAT服務(wù)器(配置server.xml):

          <!-- 配置8080端口 -->

          <Connector port="8080" maxThreads="500" minSpareThreads="400" maxSpareThreads="450"

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

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

          ???? <!-- 配置引擎 -->

          ???? <Engine name="Catalina" defaultHost="localhost" debug="0" jvmRoute="tomcat1">

          u??????? 配置第二個TOMCAT服務(wù)器(配置server.xml):

          <!-- tomcat 停止指令監(jiān)聽端口 -->

          <Server port="12005" shutdown="SHUTDOWN" debug="0">

          <!-- 配置8081端口 -->

          <Connector port="8081" maxThreads="500" minSpareThreads="400" maxSpareThreads="450"

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

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

          ??? <!--配置8009端口為如下,端口 12009和workers2.properties/workers.properties的port一致 -->

          ???? <Connector port="12009"

          ?????????????? enableLookups="false" redirectPort="8443" debug="0"

          protocol="AJP/1.3" />

          ???? <!-- 配置引擎 -->

          ???? <Engine name="Catalina" defaultHost="localhost" debug="0" jvmRoute="tomcat2">

          u??????? 配置第二個TOMCAT服務(wù)器的 jk2 (配置jk2.properties)

          ## THIS FILE MAY BE OVERRIDEN AT RUNTIME. MAKE SURE TOMCAT IS STOPED

          ## WHEN YOU EDIT THE FILE.

          ?

          ## COMMENTS WILL BE _LOST_

          ?

          ## DOCUMENTATION OF THE FORMAT IN JkMain javadoc.

          ?

          # Set the desired handler list

          # handler.list=apr,request,channelJni

          # 設(shè)置jk2 connector的端口12009,server.xml文件的<Connector port="12009"..>的端口一致

          # Override the default port for the socketChannel

          channelSocket.port=12009

          # Default:

          # channelUnix.file=${jkHome}/work/jk2.socket

          # Just to check if the the config? is working

          # shm.file=${jkHome}/work/jk2.shm

          ?

          # In order to enable jni use any channelJni directive

          # channelJni.disabled = 0

          # And one of the following directives:

          ?

          # apr.jniModeSo=/opt/apache2/modules/mod_jk2.so

          ?

          # If set to inprocess the mod_jk2 will Register natives itself

          # This will enable the starting of the Tomcat from mod_jk2

          # apr.jniModeSo=inprocess

          u?????? 配置……TOMCAT服務(wù)器:

          如果有其他TOMCAT服務(wù)器,則按照如上步驟修改相關(guān)的端口,注意端口要和workers2.properties/workers.properties文件的port一致

          5、? 配置TOMCAT集群:

          u??????? 配置第一個TOMCAT服務(wù)器(配置server.xml):

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

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

          expireSessionsOnShutdown="false" useDirtyFlag="true">

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

          mcastAddr="228.0.0.4" mcastBindAddr="127.0.0.1" 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"/>

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

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

          </Cluster>

          u?????? 配置第二個TOMCAT服務(wù)器(配置server.xml):

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

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

          expireSessionsOnShutdown="false" useDirtyFlag="true">

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

          mcastAddr="228.0.0.4" mcastBindAddr="127.0.0.1" mcastPort="45564"

          mcastFrequency="500" mcastDropTime="3000"/>

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

          tcpListenAddress="auto" tcpListenPort="4002" tcpSelectorTimeout="100"

          tcpThreadCount="6"/>

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

          replicationMode="pooled"/>

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

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

          </Cluster>

          u?????? 配置……TOMCAT服務(wù)器:

          如果有其他TOMCAT服務(wù)器,則按照如上步驟修改相關(guān)的端口,如果為同一臺機器上的多個TOMCAT服務(wù)器,修改tcpListenPort="4002"/tcpListenPort="4002"/…,端口不能重復(fù)。

          6、? 優(yōu)化配置方案:

          u??????? 如果操作系統(tǒng)采用windows server 2003:

          優(yōu)化tomcat配置:

          maxThreads="500" minSpareThreads="400" maxSpareThreads="450",但是tomcat最多支持500個并發(fā)訪問

          優(yōu)化apache配置:

          ThreadsPerChild 1900
          MaxRequestsPerChild 10000

          u??????? 如果操作系統(tǒng)采用windows 2000 server:

          優(yōu)化tomcat配置:

          maxThreads="300" minSpareThreads="150" maxSpareThreads="200",但是tomcat最多支持300個并發(fā)訪問

          優(yōu)化apache配置:

          ThreadsPerChild 1000
          MaxRequestsPerChild 8000

          7、? 技術(shù)方案:

          u?????? 采用負載平衡和集群技術(shù),采用 Apache+Tomcat 的機群技術(shù)。
          采用壓力測試工具,測試壓力。工具是 Loadrunner 7.8

          8、? 其他:

          網(wǎng)站的壓力測試,涉及的知識面挺廣的,不僅要熟悉壓力測試工具,還要知道如何配置和優(yōu)化應(yīng)用服務(wù)器和數(shù)據(jù)庫,并且需要知道如何優(yōu)化網(wǎng)絡(luò)、操作系統(tǒng)、硬件系統(tǒng)。

          測試中不僅要善于發(fā)現(xiàn)問題,要知道如何解決。最重要的一點,要有良好的測試方法。剛開始測試時,可以從最簡單的測試腳本入手,不需要太復(fù)雜的腳本,這樣便于發(fā)現(xiàn)問題。如我們剛開始時,就從一個簡單的下載登陸界面的腳本入手,測試一個 tomcat 的壓力負載。一個簡單的獲取登陸的腳本,幫助我們優(yōu)化了 tomcat 的配置;后來再測試數(shù)據(jù)庫連接,也是一個簡單的數(shù)據(jù)庫連接腳本,幫助我們優(yōu)化了數(shù)據(jù)庫連接池;然后利用這些簡單的腳本,測試 apache 的負載平衡,優(yōu)化了 apache 配置。最后運行復(fù)雜的腳本,模擬多種角色的用戶在不同時間下的處理,以測試網(wǎng)站壓力負載。

          posted on 2006-04-22 20:14 LORD BLOG 閱讀(1959) 評論(0)  編輯  收藏 所屬分類: Application Server
          主站蜘蛛池模板: 崇信县| 六枝特区| 阜南县| 新巴尔虎左旗| 柳江县| 辽源市| 上杭县| 高清| 大城县| 泰来县| 宜州市| 曲松县| 河曲县| 迁安市| 霞浦县| 福鼎市| 崇明县| 成安县| 江川县| 楚雄市| 纳雍县| 开化县| 台中市| 晴隆县| 富裕县| 通渭县| 南宁市| 宜丰县| 台南县| 昌宁县| 扎兰屯市| 玉树县| 浮梁县| 西盟| 海林市| 永福县| 申扎县| 富裕县| 鱼台县| 定西市| 通道|