httpd,mod_jk,tomcat,loadbalance

1.    环境配置以及安装指南

Apachehttpd-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.23 tomcat

 

 

2.     配置篇章

 

2.1 配置httpd.conf

 

Cd /ceno/product/httpd/conf

Vi httpd.conf  

下面是

 

#

# ServerName gives the name and port that the server uses to identify itself.

# This can often be determined automatically, but we recommend you specify

# it explicitly to prevent problems during startup.

#

# 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 you will serve your

# documents. By default, all requests are taken from this directory, but

# symbolic links and aliases may be used to point to 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 any combination of:

    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

    #

    # Note that "MultiViews" must be named *explicitly* --- "Options All"

    # doesn't give it to you.

    #

    # The Options directive is both complicated and important.  Please see

    # http://httpd.apache.org/docs/2.2/mod/core.html#options

    # for more information.

    #

    Options Indexes FollowSymLinks

 

    #

    # AllowOverride controls what directives may be placed in .htaccess files.

    # It can be "All", "None", or any combination of the keywords:

    #   Options FileInfo AuthConfig Limit

    #

    AllowOverride None

 

    #

    # Controls who can get stuff from this server.

    #

    Order allow,deny

    Allow from 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 <IfModule directive> (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 context directories are served by apache

 JkAutoAlias /ceno/product/tomcat/webapps/examples

 

# All requests go to worker1 by default

  JkMount /* balance1

  # Serve html, 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 one of the four types defined in the table

##(a worker name may only contain any space the characters [a-zA-Z0-9\-_]).

##Type    Description

#ajp12     This worker knows how to forward requests to out-of-process Tomcat workers using the ajpv12 protocol.

#ajp13     This worker knows how to forward requests to out-of-process Tomcat workers using the ajpv13 protocol.

#jni  DEPRECATED: This worker knows how to forward requests to in-process Tomcat workers using JNI.

#lb   This is a load-balancing worker; it knows how to provide round-robin based sticky load balancing 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 specify properties for them. Properties can be specified in the following manner:

#worker.<worker name>.<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'?>

<!--

  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:  A "Server" is not itself a "Container", so you may not

     define subcomponents such as "Valves" at this level.

     Documentation at /docs/config/server.html

 -->

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

  <!-- Security listener. Documentation at /docs/config/listeners.html

  <Listener className="org.apache.catalina.security.SecurityListener" />

  -->

  <!--APR library loader. Documentation at /docs/apr.html -->

  <Listener className="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-->

  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />

  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

  <Listener className="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" that share

       a single "Container" Note:  A "Service" is not itself a "Container",

       so you 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 or more named thread pools-->

    <!--

    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"

        maxThreads="150" minSpareThreads="4"/>

    -->

 

 

    <!-- A "Connector" represents an endpoint by which requests are received

         and responses 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

    -->

    <Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

    <!-- 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="8009" protocol="AJP/1.3" redirectPort="8443" />

 

 

    <!-- An Engine represents the entry point (within Catalina) that processes

         every request.  The Engine implementation for Tomcat stand alone

         analyzes the HTTP headers included with the request, and passes them

         on to 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  (simple how 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 -->

      <Realm className="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 web applications

             Documentation at: /docs/config/valve.html -->

        <!--

        <Valve className="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" -->

        <Valve className="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 or more named thread pools-->

    <!--

    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"

        maxThreads="150" minSpareThreads="4"/>

    -->

 

 

    <!-- A "Connector" represents an endpoint by which requests are received

         and responses 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

    -->

    <Connector port="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 Engine implementation for Tomcat stand alone

         analyzes the HTTP headers included with the request, and passes them

         on to 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  (simple how 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 -->

      <Realm className="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 web applications

             Documentation at: /docs/config/valve.html -->

        <!--

        <Valve className="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" -->

        <Valve className="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

 

 

你可能感兴趣的:(tomcat,httpd,mod_jk,loadbalance)