设为首页 收藏本站
查看: 287|回复: 0

[经验分享] httpd,mod_jk,tomcat,loadbalance

[复制链接]

尚未签到

发表于 2017-1-23 06:54:55 | 显示全部楼层 |阅读模式
  1.    环境配置以及安装指南
Apache:httpd-2.2.21
Mod_jk: tomcat-connectors-1.2.32-src.tar.gz
Tomcat: apache-tomcat-7.0.23.tar.gz
 
版本说明信息; http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html
 
1.1 安装apache
 
 A:解压apache
 tar-zxvf  httpd-2.2.21-beta.tar.gz
cd httpd-2.3.16-beta

B:配置
./configure  --prefix=/ceno/product/httpd--enable-module=vhost_alias --enable-module=so                                                               
                                                                              
Make
Make install

 
 
C:提示缺少apr以及aprutil,pcre,则需要先编译apr,aprutil以及pcre.
 
 C1:下载apr,aprutil 以及 pcre
apr: http://apr.apache.org/download.cgi
apr-util: http://apr.apache.org/download.cgi
pcre: http://pcre.org/
http://sourceforge.net/projects/pcre/

   
 c2:安装apr:
tar zxvf apr-1.4.5.tar.gz
cd apr-1.4.5
./configure --prefix=/usr/local/apr
Make
make install

 

c3:安装aprtuil

 

 

tar zxvf apr-util-1.3.10.tar.gz
cd apr-util-1.3.10
./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr
Make
make install

 

c4安装pcre

tar zxvf pcre-8.11.tar.gz
cd pcre-8.11
./configure --prefix=/usr/local/pcre
Make
make install

 

 

 

 

 

 
D:重新编译httpd
 
cd httpd-2.2.21
./configure --with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre--prefix=/ceno/product/httpd --enable-module=vhost_alias --enable-module=so
 
Make
Make install

 
 
 
1.2 安装并编译mod_jk
 
Tar –zxvf  tomcat-connectors-1.2.32-src.tar.gz
Cd tomcat-connectors-1.2.32-src/native
./configure --with-apxs=/ceno/product/httpd/bin/apxs
Make
 
Su –c ‘make install’

 
 
1.3   解压tomcat7.0
 
 
Tar –zxvf apache-tomcat-7.0.23.tar.gz
Cd /ceno/product/
Ln –s /work/apache/ apache-tomcat-7.0.23tomcat

 
 
2.     配置篇章
 
2.1 配置httpd.conf
 
Cd /ceno/product/httpd/conf
Vi httpd.conf  
下面是
 
#
# ServerName gives the name and port that theserver uses to identify itself.
# This can often be determined automatically, butwe recommend you specify
# it explicitly to prevent problems duringstartup.
#
# If your host doesn't have a registered DNS name,enter its IP address here.
#
#ServerName www.example.com:80
ServerName 192.168.7.18:80
 
 
#
# DocumentRoot: The directory out of which youwill serve your
# documents. By default, all requests are takenfrom this directory, but
# symbolic links and aliases may be used to pointto other locations.
#
#DocumentRoot"/ceno/product/httpd/htdocs"
DocumentRoot"/ceno/product/tomcat/webapps/examples"
 
 
 
<Directory"/ceno/product/tomcat/webapps/examples">
    #
    #Possible values for the Options directive are "None","All",
    # or anycombination of:
    #   Indexes Includes FollowSymLinksSymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Notethat "MultiViews" must be named *explicitly* --- "OptionsAll"
    #doesn't give it to you.
    #
    # TheOptions directive is both complicated and important.  Please see
    #http://httpd.apache.org/docs/2.2/mod/core.html#options
    # formore information.
    #
    OptionsIndexes FollowSymLinks
 
    #
    #AllowOverride controls what directives may be placed in .htaccess files.
    # It canbe "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
   AllowOverride None
 
    #
    #Controls who can get stuff from this server.
    #
    Orderallow,deny
    Allowfrom all
 
</Directory>
 
#加入mod_jk配置 
Include conf/jk/mod_jk.conf    

 
 
 
2.2 在httpd/conf 下添加jk目录,配置mod_jk.conf
 
 
Cd /ceno/product/httpd/conf/jk/
 
#load mod_jk module
 LoadModule   jk_module  modules/mod_jk.so
# Declare the module for <IfModuledirective> (remove this line on Apache 2.0.x)
#AddModule    mod_jk.c
# Where to find workers.properties
JkWorkersFile/ceno/product/httpd/conf/jk/workers.properties
# Where to put jk shared memory
JkShmFile    /ceno/product/httpd/mod_jk.shm
# Where to put jk logs
JkLogFile   /ceno/product/httpd/logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel   debug
# Select the timestamp log format
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"
# Static files in all Tomcat webapp contextdirectories are served by apache
 JkAutoAlias/ceno/product/tomcat/webapps/examples
 
# All requests go to worker1 by default
  JkMount /*balance1
  # Servehtml, jpg and gif using httpd
  JkUnMount/*.html balance1
  JkUnMount/*.jpg  balance1
  JkUnMount/*.gif  balance1
 
 
# Add the jkstatus mount point
 JkMount/jkmanager/* jkstatus

 
workers.properties
 
# the list of workers
worker.list= worker1,worker2,balance1,jkstatus
 
##
##worker.worker name.type=<worker type>Where worker name is the name assigned to the worker and the worker type is oneof the four types defined in the table
##(a worker name may only contain any space thecharacters [a-zA-Z0-9\-_]).
##Type    Description
#ajp12     Thisworker knows how to forward requests to out-of-process Tomcat workers using theajpv12 protocol.
#ajp13     Thisworker knows how to forward requests to out-of-process Tomcat workers using theajpv13 protocol.
#jni  DEPRECATED:This worker knows how to forward requests to in-process Tomcat workers usingJNI.
#lb   This isa load-balancing worker; it knows how to provide round-robin based sticky loadbalancing with a certain level of fault-tolerance.
#Defines a worker named "loadbalancer"that loadbalances several Tomcat processes transparently.
 
 
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=192.168.7.18
worker.worker1.port=8009
worker.worker1.lbfactor=1
# Set properties for worker2 (ajp13)
worker.worker2.type=ajp13
worker.worker2.host=192.168.7.18
worker.worker2.port=8010
worker.worker2.lbfactor=3
#worker.worker2.connection_pool_timeout=600
#worker.worker2.socket_keepalive=1
#worker.worker2.socket_timeout=60
 
 
worker. balance1.type=lb
 
#
#After defining the workers you can also specifyproperties for them. Properties can be specified in the following manner:
#worker.<workername>.<property>=<property value>
#
# The worker balance1 while use "real"workers worker1 and worker2
worker.balance1.balance_workers=worker1, worker2
 
worker.balance1.sticky_session =true
 
 
 
# Define a 'jkstatus' worker using status
worker.jkstatus.type=status

 
 
 
2.3 配置tomcat
 
一台机器上测试 2tomcat
 
Tomcat1:
<Server port="8005"shutdown="SHUTDOWN">
 
<Connector port="8080"protocol="HTTP/1.1"
               connectionTimeout="20000"
              redirectPort="8443" />
 
<Connector port="8009"protocol="AJP/1.3" redirectPort="8443" />
 
<Engine name="Catalina"defaultHost="localhost" jvmRoute="worker1">
 
 
Tomcat2:
 
<Server port="8006"shutdown="SHUTDOWN">
 
<Connector port="8081"protocol="HTTP/1.1"
              connectionTimeout="20000"
              redirectPort="8445" />
 
<Connector port="8010"protocol="AJP/1.3" redirectPort="8445" />
<Engine name="Catalina"defaultHost="localhost" jvmRoute="worker2">

 
 
 
 
一个tomcat 两个实例
 
修改/tomcat/conf/server.xml文件,添加一个service
 
<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensedto the Apache Software Foundation (ASF) under one or more
 contributor license agreements. See the NOTICE file distributed with
  this workfor additional information regarding copyright ownership.
  The ASFlicenses this file to You under the Apache License, Version 2.0
  (the"License"); you may not use this file except in compliance with
  theLicense.  You may obtain a copy of theLicense at
 
     http://www.apache.org/licenses/LICENSE-2.0
 
  Unlessrequired by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS"BASIS,
  WITHOUTWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See theLicense for the specific language governing permissions and
 limitations under the License.
-->
<!-- Note: A "Server" is not itself a "Container", so you maynot
     definesubcomponents such as "Valves" at this level.
     Documentationat /docs/config/server.html
 -->
<Server port="8005"shutdown="SHUTDOWN">
  <!--Security listener. Documentation at /docs/config/listeners.html
 <ListenerclassName="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APRlibrary loader. Documentation at /docs/apr.html -->
 <ListenerclassName="org.apache.catalina.core.AprLifecycleListener"SSLEngine="on" />
 <!--Initialize Jasper prior to webapps are loaded. Documentation at/docs/jasper-howto.html -->
 <Listener className="org.apache.catalina.core.JasperListener"/>
  <!--Prevent memory leaks due to use of particular java/javax APIs-->
 <ListenerclassName="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
 <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
 <ListenerclassName="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
 
  <!--Global JNDI resources
      Documentation at /docs/jndi-resources-howto.html
  -->
 <GlobalNamingResources>
    <!--Editable user database that can also be used by
        UserDatabaseRealm to authenticate users
    -->
   <Resource name="UserDatabase" auth="Container"
             type="org.apache.catalina.UserDatabase"
             description="User database that can be updated and saved"
             factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
             pathname="conf/tomcat-users.xml" />
 </GlobalNamingResources>
 
  <!-- A"Service" is a collection of one or more "Connectors" thatshare
       asingle "Container" Note:  A"Service" is not itself a "Container",
       soyou may not define subcomponents such as "Valves" at this level.
      Documentation at /docs/config/service.html
   -->
 <Service name="Catalina1">
 
   <!--The connectors can use a shared executor, you can define one ormore named thread pools-->
    <!--
   <Executor name="tomcatThreadPool"namePrefix="catalina-exec-"
       maxThreads="150" minSpareThreads="4"/>
    -->
 
 
    <!--A "Connector" represents an endpoint by which requests are received
         andresponses are returned. Documentation at :
        Java HTTP Connector: /docs/config/http.html (blocking &non-blocking)
        Java AJP  Connector:/docs/config/ajp.html
         APR(HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port8080
    -->
   <Connector port="8080" protocol="HTTP/1.1"
              connectionTimeout="20000"
              redirectPort="8443" />
    <!--A "Connector" using the shared thread pool-->
    <!--
    <Connectorexecutor="tomcatThreadPool"
              port="8080" protocol="HTTP/1.1"
              connectionTimeout="20000"
              redirectPort="8443" />
    -->
    <!--Define a SSL HTTP/1.1 Connector on port 8443
        This connector uses the JSSE configuration, when using APR, the
        connector should be using the OpenSSL style configuration
        described in the APR documentation -->
    <!--
   <Connector port="8443" protocol="HTTP/1.1"SSLEnabled="true"
              maxThreads="150" scheme="https"secure="true"
              clientAuth="false" sslProtocol="TLS" />
    -->
 
    <!--Define an AJP 1.3 Connector on port 8009 -->
   <Connector port="8009" protocol="AJP/1.3"redirectPort="8443" />
 
 
    <!--An Engine represents the entry point (within Catalina) that processes
        every request.  The Engineimplementation for Tomcat stand alone
        analyzes the HTTP headers included with the request, and passes them
         onto the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html-->
 
    <!--You should set jvmRoute to support load-balancing via AJP ie :
   <Engine name="Catalina" defaultHost="localhost"jvmRoute="jvm1">
    -->
   <Engine name="Catalina1" defaultHost="localhost"jvmRoute="worker1">
 
     <!--For clustering, please take a look at documentation at:
         /docs/cluster-howto.html  (simplehow to)
         /docs/config/cluster.html (reference documentation) -->
     <!--
     <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->
 
     <!-- Use the LockOutRealm to prevent attempts to guess user passwords
          via a brute-force attack -->
     <RealmclassName="org.apache.catalina.realm.LockOutRealm">
       <!-- This Realm uses the UserDatabase configured in the global JNDI
            resources under the key "UserDatabase".  Any edits
            that are performed against this UserDatabase are immediately
            available for use by the Realm. -->
       <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
              resourceName="UserDatabase"/>
     </Realm>
 
     <Host name="localhost" appBase="/ceno/product/test"
           unpackWARs="true" autoDeploy="true">
 
       <!-- SingleSignOn valve, share authentication between webapplications
            Documentation at: /docs/config/valve.html -->
       <!--
       <ValveclassName="org.apache.catalina.authenticator.SingleSignOn" />
       -->
 
       <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
            Note: The pattern used is equivalent to using pattern="common"-->
       <ValveclassName="org.apache.catalina.valves.AccessLogValve"directory="logs"
              prefix="localhost_access_log." suffix=".txt"
              pattern="%h %l %u %t &quot;%r&quot; %s %b" />
 
     </Host>
   </Engine>
 </Service>
   <Service name="Catalina2">
 
   <!--The connectors can use a shared executor, you can define one ormore named thread pools-->
    <!--
   <Executor name="tomcatThreadPool"namePrefix="catalina-exec-"
       maxThreads="150" minSpareThreads="4"/>
    -->
 
 
    <!--A "Connector" represents an endpoint by which requests are received
         andresponses are returned. Documentation at :
        Java HTTP Connector: /docs/config/http.html (blocking &non-blocking)
        Java AJP  Connector:/docs/config/ajp.html
         APR(HTTP/AJP) Connector: /docs/apr.html
        Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connectorport="8081" protocol="HTTP/1.1"
              connectionTimeout="20000"
              redirectPort="8444" />
    <!--A "Connector" using the shared thread pool-->
    <!--
   <Connector executor="tomcatThreadPool"
              port="8080" protocol="HTTP/1.1"
              connectionTimeout="20000"
              redirectPort="8443" />
    -->
    <!--Define a SSL HTTP/1.1 Connector on port 8443
        This connector uses the JSSE configuration, when using APR, the
        connector should be using the OpenSSL style configuration
        described in the APR documentation -->
    <!--
   <Connector port="8443" protocol="HTTP/1.1"SSLEnabled="true"
              maxThreads="150" scheme="https"secure="true"
              clientAuth="false" sslProtocol="TLS" />
    -->
 
    <!--Define an AJP 1.3 Connector on port 8009 -->
   <Connector port="8010" protocol="AJP/1.3"redirectPort="8444" />
 
 
    <!--An Engine represents the entry point (within Catalina) that processes
        every request.  The Engineimplementation for Tomcat stand alone
        analyzes the HTTP headers included with the request, and passes them
         onto the appropriate Host (virtual host).
        Documentation at /docs/config/engine.html -->
 
    <!--You should set jvmRoute to support load-balancing via AJP ie :
   <Engine name="Catalina" defaultHost="localhost"jvmRoute="jvm1">
    -->
   <Engine name="Catalina2" defaultHost="localhost"jvmRoute="worker1">
 
     <!--For clustering, please take a look at documentation at:
         /docs/cluster-howto.html  (simplehow to)
         /docs/config/cluster.html (reference documentation) -->
     <!--
     <ClusterclassName="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->
 
     <!-- Use the LockOutRealm to prevent attempts to guess user passwords
          via a brute-force attack -->
     <RealmclassName="org.apache.catalina.realm.LockOutRealm">
       <!-- This Realm uses the UserDatabase configured in the global JNDI
            resources under the key "UserDatabase".  Any edits
            that are performed against this UserDatabase are immediately
            available for use by the Realm. -->
       <RealmclassName="org.apache.catalina.realm.UserDatabaseRealm"
              resourceName="UserDatabase"/>
     </Realm>
 
     <Host name="localhost" appBase="/ceno/product/test"
           unpackWARs="true" autoDeploy="true">
 
       <!-- SingleSignOn valve, share authentication between webapplications
            Documentation at: /docs/config/valve.html -->
       <!--
       <ValveclassName="org.apache.catalina.authenticator.SingleSignOn" />
       -->
 
       <!-- Access log processes all example.
            Documentation at: /docs/config/valve.html
            Note: The pattern used is equivalent to using pattern="common"-->
       <ValveclassName="org.apache.catalina.valves.AccessLogValve"directory="logs"
              prefix="localhost_access_log." suffix=".txt"
              pattern="%h %l %u %t &quot;%r&quot; %s %b" />
 
     </Host>
   </Engine>
 </Service>
</Server>

 
 
 
2.4  配置Jk status
方法一:
 
在worker.peroerties文件中增加:
worker.list=worker1,worker2,balancer1,jkstatus
 
# Define a 'jkstatus' worker using status
worker.jkstatus.type=status

 
在mod_jk.conf 中增加
# Add the jkstatus mount point
 JkMount/jkmanager/* jkstatus

打开浏览器访问:
http://192.168.7.18/jkmanager
 
 
方法二:
 
在workers.properties文件中添加
 
worker.list=worker1,worker2,balancer1,jkstatus
 
# Define a 'jkstatus' worker using status
worker.jkstatus.type=status
worker. jkstatus.read_only=true
worker.jkstatus.mount=/admin/status/jk

worker. jkstatus.read_only 属性 默认为false
打开浏览器访问
http://192.168.7.18/admin/status/jk
 
 

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-332113-1-1.html 上篇帖子: TOMCAT的域名配置(转) 下篇帖子: JConsole监控tomcat和jboss
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表