搭建集群(apache+tomcat+mod_jk)

一个mod_jk,一个apache,二个tomcat;

apache版本      httpd-2.2.27.tar.gz
tomcat版本      apache-tomcat-6.0.41.tar.gz
jdk             jdk-6u13-linux-i586.bin
jk              tomcat-connectors-1.2.40-src.tar.gz

1.软件的安装;

 2.配置文件的修改;

apache的配置文件主要有三个:httpd.conf,mod_jk.conf,workers.properties

httpd.conf配置文件主要引用mod.jk.so,和include mod_jk.conf配置文件;

mod_jk.conf配置文件主要引用workers.properties配置文件(httpd.conf直接引用也可以),对请求的处理,日志文件等;

workers.properties配置文件tomcat集群处理;

下面分别是配置文件内容:

httpd.conf:

#
# This is the main Apache HTTP server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.2> for detailed information.
# In particular, see
# <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They‘re here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#
# Configuration and logfile names: If the filenames you specify for many
# of the server‘s control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path.  If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so ‘log/access_log‘
# with ServerRoot set to ‘/www‘ will be interpreted by the
# server as ‘/www/log/access_log‘, where as ‘/log/access_log‘ will be
# interpreted as ‘/log/access_log‘.

#
# ServerRoot: The top of the directory tree under which the server‘s
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path.  If you point
# ServerRoot at a non-local disk, be sure to point the LockFile directive
# at a local disk.  If you wish to share the same ServerRoot for multiple
# httpd daemons, you will need to change at least LockFile and PidFile.
#
ServerRoot "/usr/local/apache"

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 127.0.0.1:80

#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule‘ lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l‘) do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbd_module modules/mod_authn_dbd.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule dbd_module modules/mod_dbd.so
LoadModule dumpio_module modules/mod_dumpio.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule include_module modules/mod_include.so
LoadModule filter_module modules/mod_filter.so
LoadModule substitute_module modules/mod_substitute.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule log_forensic_module modules/mod_log_forensic.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule cern_meta_module modules/mod_cern_meta.so
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
LoadModule ident_module modules/mod_ident.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule unique_id_module modules/mod_unique_id.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule asis_module modules/mod_asis.so
LoadModule info_module modules/mod_info.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule imagemap_module modules/mod_imagemap.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule jk_module modules/mod_jk.so

Include /usr/local/apache/conf/mod_jk.conf
LoadModule encoding_module modules/mod_encoding.so

<IfModule mod_encoding.c>
EncodingEngine on
NormalizeUsername on
SetServerEncoding GBK
DefaultClientEncoding UTF-8 GBK GB2312
AddClientEncoding "(Microsoft .* DAV $)" UTF-8 GBK GB2312
AddClientEncoding "Microsoft .* DAV" UTF-8 GBK GB2312
AddClientEncoding "Microsoft-WebDAV*" UTF-8 GBK GB2312
</IfModule>

<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.  
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User daemon
Group daemon

</IfModule>
</IfModule>

# ‘Main‘ server configuration
#
# The directives in this section set up the values used by the ‘main‘
# server, which responds to any requests that aren‘t handled by a
# <VirtualHost> definition.  These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. [email protected]
#
ServerAdmin [email protected]

#
# 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 localhost: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 "/var/www/html/htqh_web"

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.  
#
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something‘s not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/var/www/html/htqh_web">
    #
    # 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 Includes

#
    # 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>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.jsp
</IfModule>

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>

#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host‘s errors will be logged there and not here.
#
ErrorLog "logs/error_log"

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

<IfModule log_config_module>
    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

<IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

#
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    CustomLog "logs/access_log" common

#
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    #CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    #
    # Redirect: Allows you to tell clients about documents that used to
    # exist in your server‘s namespace, but do not anymore. The client
    # will make a new request for the document at its new location.
    # Example:
    # Redirect permanent /foo http://www.example.com/bar

#
    # Alias: Maps web paths into filesystem paths and is used to
    # access content that does not live under the DocumentRoot.
    # Example:
    # Alias /webpath /full/filesystem/path
    #
    # If you include a trailing / on /webpath then the server will
    # require it to be present in the URL.  You will also likely
    # need to provide a <Directory> section to allow access to
    # the filesystem path.

#
    # ScriptAlias: This controls which directories contain server scripts.
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the target directory are treated as applications and
    # run by the server when requested rather than as documents sent to the
    # client.  The same rules about trailing "/" apply to ScriptAlias
    # directives as to Alias.
    #
    ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"

</IfModule>

<IfModule cgid_module>
    #
    # ScriptSock: On threaded servers, designate the path to the UNIX
    # socket used to communicate with the CGI daemon of mod_cgid.
    #
    #Scriptsock logs/cgisock
</IfModule>

#
# "/usr/local/apache/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/usr/local/apache/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

#
# DefaultType: the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain

<IfModule mime_module>
    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig conf/mime.types

#
    # AddType allows you to add to or override the MIME configuration
    # file specified in TypesConfig for specific file types.
    #
    #AddType application/x-gzip .tgz
    #
    # AddEncoding allows you to have certain browsers uncompress
    # information on the fly. Note: Not all browsers support this.
    #
    #AddEncoding x-compress .Z
    #AddEncoding x-gzip .gz .tgz
    #
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

#
    # AddHandler allows you to map certain file extensions to "handlers":
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action directive (see below)
    #
    # To use CGI scripts outside of ScriptAliased directories:
    # (You will also need to add "ExecCGI" to the "Options" directive.)
    #
    #AddHandler cgi-script .cgi

# For type maps (negotiated resources):
    #AddHandler type-map var

#
    # Filters allow you to process content before it is sent to the client.
    #
    # To parse .shtml files for server-side includes (SSI):
    # (You will also need to add "Includes" to the "Options" directive.)
    #
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

#
# The mod_mime_magic module allows the server to use various hints from the
# contents of the file itself to determine its type.  The MIMEMagicFile
# directive tells the module where the hint definitions are located.
#
#MIMEMagicFile conf/magic

#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
#

#
# MaxRanges: Maximum number of Ranges in a request before
# returning the entire resource, or one of the special
# values ‘default‘, ‘none‘ or ‘unlimited‘.
# Default setting is to accept 200 Ranges.
#MaxRanges unlimited

#
# EnableMMAP and EnableSendfile: On systems that support it,
# memory-mapping or the sendfile syscall is used to deliver
# files.  This usually improves server performance, but must
# be turned off when serving from networked-mounted
# filesystems or if support for these functions is otherwise
# broken on your system.
#
#EnableMMAP off
#EnableSendfile off

# Supplemental configuration
#
# The configuration files in the conf/extra/ directory can be
# included to add extra features or to modify the default configuration of
# the server, or you may simply copy their contents here and change as
# necessary.

# Server-pool management (MPM specific)
#Include conf/extra/httpd-mpm.conf

# Multi-language error messages
#Include conf/extra/httpd-multilang-errordoc.conf

# Fancy directory listings
#Include conf/extra/httpd-autoindex.conf

# Language settings
#Include conf/extra/httpd-languages.conf

# User home directories
#Include conf/extra/httpd-userdir.conf

# Real-time info on requests and configuration
#Include conf/extra/httpd-info.conf

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

# Local access to the Apache HTTP Server Manual
#Include conf/extra/httpd-manual.conf

# Distributed authoring and versioning (WebDAV)
#Include conf/extra/httpd-dav.conf

# Various default settings
#Include conf/extra/httpd-default.conf

# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf
#
# Note: The following must must be present to support
#       starting without SSL on platforms with no /dev/random equivalent
#       but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

mod_jk.conf:

# 指出mod_jk模块工作所需要的工作文件workers.properties的位置
JkWorkersFile /usr/local/apache/conf/workers.properties

# Where to put jk logs
JkLogFile /usr/local/apache/logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel debug

# Select the 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"

# 将所有servlet 和jsp请求通过ajp13的协议送给Tomcat,让Tomcat来处理
JkMount /servlet/*  tomcatlist
JkMount /*.jsp      tomcatlist
JkMount /*.action   tomcatlist
JkMount /*.do       tomcatlist

workers.properties:

# Defining a worker named worker1 and of type ajp13
worker.list=tomcatlist

# Set properties for worker1
#worker.worker1.type=ajp13
#worker.worker1.host=localhost
#worker.worker1.port=11009
#worker.worker1.lbfactor=50
#worker.worker1.cachesize=10
#worker.worker1.cache_timeout=600
#worker.worker1.socket_keepalive=1
#worker.worker1.socket_timeout=300

#worker.worker2.type=ajp13
#worker.worker2.host=localhost
#worker.worker2.port=12009
#worker.worker2.lbfactor=50
#worker.worker2.cachesize=10
#worker.worker2.cache_timeout=600
#worker.worker2.socket_keepalive=1
#worker.worker2.socket_timeout=300

worker.tomcat1.port=11009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1

worker.tomcat2.port=12009
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1

worker.tomcat3.port=13009
worker.tomcat3.host=192.168.0.126
worker.tomcat3.type=ajp13
worker.tomcat3.lbfactor = 1

worker.tomcatlist.type=lb
worker.tomcatlist.balanced_workers=tomcat1,tomcat2,tomcat3
worker.tomcatlist.sticky_session=1
worker.tomcatlist.sticky_session_force=0

以上是个人的配置文件,其中包括了mod_encoding处理中文url的.so文件;

特别说明:

/*********************************以下是我测试的结果,因为不理解下面这个是什么意思
sticky_session  sticky_session_force            含义
    true            false           SESSION会复制,有粘性
    true            true            SESSION不复制,有粘性
    false           false           SESSION会复制,无粘性
    false           true            SESSION会复制,无粘性

1 :true;0:false

worker.controller.sticky_session=1
worker.controller.sticky_session_force=0
一次请求中 session 只会在一个tomcat上,当该tomcat奔溃后,请求会跳转到其他tomcat上,但是其session不会复制到跳转后的tomcat上

worker.controller.sticky_session=0
worker.controller.sticky_session_force=0
每次请求都会跳转到其他tomcat上,(如果有AB两个tomcat负载均衡值都为1,第一次请求A
session为A1,第二次请求跳转到B session B2,第三次又回到A session为 A1 和 A3,第四次跳转到B session
为 B2 和 B4

worker.controller.sticky_session=1
worker.controller.sticky_session_force=1
一次请求中 session 只会在一个tomcat上,当该tomcat奔溃后,服务端会返回Service Temporarily Unavailable:The server is

temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

worker.controller.sticky_session=0
worker.controller.sticky_session_force=1
每次请求都会跳转到其他tomcat上,(如果有AB两个tomcat负载均衡值都为1,第一次请求A
session为A1,第二次请求跳转到B session B2,第三次又回到A session为A3,第四次跳转到B session 
B4,即每次跳转都不会带上session,也不会保留原有的session

特别注意:

ajp的端口号一定要与tomcat的servlet.xml的配置文件

<Connector port="13009" protocol="AJP/1.3" redirectPort="8443"/>

port端口一致;

<Engine defaultHost="localhost" name="Catalina" jvmRoute="tomcat3">

多个tomcat,jvmRoute最好不一样;

同一台服务器多个tomcat,端口号一定要不一样;

以下是一个server.xml的配置文件:

<?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="8007" shutdown="SHUTDOWN">

<!--APR library loader. Documentation at /docs/apr.html -->
  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
  <!--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"/>
  <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>

<!-- 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 auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
  </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="Catalina">
 
    <!--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 connectionTimeout="20000" port="8070" protocol="HTTP/1.1" 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="13009" 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 defaultHost="localhost" name="Catalina" jvmRoute="tomcat3">

<!--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" channelSendOptions="8"/>

<!-- The request dumper valve dumps useful debugging information about
           the request and response data received and sent by Tomcat.
           Documentation at: /docs/config/valve.html -->
      <!--
      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
      -->

<!-- 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"/>

<!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">

<!-- 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 -->
        <!--
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
        -->

</Host>
    </Engine>
  </Service>
</Server>

3.测试;

apache,tomcat启动;

测试用的jsp

<%@ page contentType="text/html; charset=utf-8"%>

<%@ page import="java.util.*"%>

<html>

<head>

<title>我是192.168.0.126</title>

</head>

<body>

<%

out.println("Server Info=" + request.getLocalAddr() +" : " + request.getLocalPort()+"<br>");

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

%>

<%

String dataName = request.getParameter("dataName");

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

String dataValue = request.getParameter("dataValue");

session.setAttribute(dataName, dataValue);

}

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

System.out.println("Session列表");

Enumeration e = session.getAttributeNames();

while (e.hasMoreElements()) {

String name = (String)e.nextElement();

String value = session.getAttribute(name).toString();

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

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

}

%>

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

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

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

<inputtype=submittext="提交">

</form>

</body>

</html>

整个集群的搭建参考了以下论坛或贴吧:

http://www.iteye.com/topic/1017961;

http://www.iteye.com/topic/1017961?page=7;

时间: 2024-11-08 23:04:32

搭建集群(apache+tomcat+mod_jk)的相关文章

用apache和tomcat搭建集群,实现负载均衡

型的企业应用每天都需要承受巨大的访问量,在着巨大访问量的背后有数台服务器支撑着,如果一台服务器崩溃了,那么其他服务器可以使企业应用继续运行,用户对服务器的运作是透明化的,如何实现这种透明化呢?由如下问题需要解决. 一.Session的复制 二.如何将请求发送到正常的服务器 针对以上问题,可以使用群集和负载均衡来解决,整体架构如下:  中间由一台服务器做负载均衡(Load Balancer),它将所有请求,根据一定的负载均衡规则发送给指定的群集服务器(Cluster),群集服务器拥有着相同的状态和

Apache + Tomcat + mod_jk实现集群服务及session共享

实现效果:用apache 分发请求到tomcat中的对应的项目 原理: 环境说明: 操作系统:win7   64位 Javajdk: 1.7 Apache:httpd-2.2.25-win32-x86-no_ssl.msi    (本地安装路径:D:\Program Files (x86)\Apache2.2\)Tomcat: 7.0.42  ( http://tomcat.apache.org/download-70.cgi ),如果在同一台机器上模拟,下载zip版本. 实例中展示了2个节点m

Nginx+Tomcat搭建集群环境

集群概述与架构介绍 Tomcat集群能带来什么: 提高服务的性能,例如计算处理能力.并发能力等,以及实现服务的高可用性 提供项目架构的横向扩展能力,增加集群中的机器就能提高集群的性能 Tomcat集群实现方式: Tomcat集群的实现方式有多种,最简单的就是通过Nginx负载进行请求转发来实现 Tomcat单机架构图: 可能看了上面的Tomcat单机的架构图后,会 "想当然" 的觉得Tomcat集群架构是这样子的: 这种 "想当然" 的Tomcat集群会带来什么问题

Nginx + Tomcat搭建集群

一.Tomcat集群带来的好处 1.提高服务的性能,并发能力,以及高可用性 2.提供项目架构的横向扩展能力 二.Tomcat集群实现原理 通过Nginx负载均衡进行请求转发 三.Nginx + Tomcat搭建集群 (一).修改hosts文件 1. windows修改hosts 文件 c:\Windows\System32\drivers\etc\hosts 127.0.0.1 www.water.com 2. linux修改hosts文件 vi /etc/hosts (二).启动Nginx w

使用LVS+DR搭建集群实现负载均衡

使用LVS+DR搭建集群实现负载均衡 DR模式的概述与工作原理 DR模式服务概述:        Direct Routing(直接路由) --在同一个地域,同一个网段 Director分配请求到不同的real server.real server处理请求后直接回应给用户,这样director负载均衡器仅处理客户机与服务器的一半连接.负载均衡器仅处理一半的连接,避免了新的性能瓶颈,同样增加了系统的可伸缩性.Direct Routing由与采用物理层(修改MAC地址)技术,因此所有服务器都必须在一

使用LVS+NAT搭建集群实现负载均衡

使用LVS+NAT搭建集群实现负载均衡 LVS集群简介    计算机集群简称集群是一种计算机系统,它通过一组松散集成的计算机软件或硬件连接起来高度紧密地协作完成计算工作.在某种意义上,他们可以被看作是一台计算机.集群系统中的单个计算机通常称为节点,通常通过局域网连接,但也有其它的可能连接方式.集群计算机通常用来改进单个计算机的计算速度和/或可靠性.一般情况下集群计算机比单个计算机,比如工作站或超级计算机性能价格比要高得多        LVS集群分布图   集群有三种类型:           

Ubuntu下用hadoop2.4搭建集群(伪分布式)

要真正的学习hadoop,就必须要使用集群,但是对于普通开发者来说,没有大规模的集群用来测试,所以只能使用伪分布式了.下面介绍如何搭建一个伪分布式集群. 为了节省时间和篇幅,前面一些步骤不再叙述.本文是在基于单机模式的前提下进行得搭建.若不会搭建单机模式,请看我的前一篇文章.Ubuntu下用hadoop2.4搭建集群(单机模式) 第一步 配置hdfs-site.xml /usr/local/hadoop/etc/hadoop/hdfs-site.xml用来配置集群中每台主机都可用,指定主机上作为

Nginx搭建集群服务器过程详解

Nginx+Apache+PHP+MySQL搭建集群服务器过程详解 概念介绍在本文未能提及,请自助上网科普,直接进入过程详解: 集群架构图大致如下: 一.软件下载 序号 软件名称 软件版本 下载地址 1 操作系统 Windows Server 2008 Enterprise 64bit 2 Php php-5.6.19-Win32-VC11-x64 Thread Safe(由于HTTP服务器用的apache) http://windows.php.net/downloads/releases/p

Nginx 在 Linux 下安装与搭建集群

搭建集群图例 集群搭建图如下,为了简单一点,使用一个Nginx服务器+两个Tomcat服务器,省略数据库部分: 环境说明 Linux 为 CentOS 7.2 发行版 + Java jdk 1.8 + Tomcat 1.8 + Nginx 1.15 Linux 下安装 Nginx 下载nginx的tar包 //下载tar包 wget http://nginx.org/download/nginx-1.13.7.tar.gztar -xvf nginx-1.13.7.tar.g 安装gcc依赖Ng

redis搭建集群并用TreeSoft管理

前言:redis作为一款高效的NOSQL数据库已经深入贯彻和落实到我们的日常开发代码中,作为缓存.时间控制.数据仓库.队列等使用方法层出不穷,简直是开写代码.居家旅行之必备良药.曾经,我们的项目都是单体的,直到后来逐渐演变为微服务-- 一个将我们的工程解耦成多个工程的体系.然后随着我们项目的访问量越来越高,后台的吞吐量也越来越大.如果我们还采用的单体redis,性能很容易形成瓶颈.如何突破单体redis带来的功能受限?如何突破性能带来的问题?这时我们就可以考虑横向扩展,搭建redis集群.正所谓