全部系统采用centos7.1

各节点配置好hosts文件
cat /etc/hosts
172.16.92.2    node2.centos7.com    node2
172.16.92.3    node3.centos7.com    node3
172.16.92.4    node4.centos7.com    node4

node2, node3  -> tomcat ( jsp网站服务器 )
node4 --> httpd(proxy_ajp_module) 反向代理至tomcat

================ node2 172.16.92.2/16 ===================
安装JDK(光盘源)
mount /dev/cdrom /mnt/cdrom/
yum -y install java-1.7.0-openjdk

安装二进制tomcat

wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.23/bin/apache-tomcat-8.0.23.tar.gz
tar xf apache-tomcat-8.0.23.tar.gz -C /usr/local
cd /usr/local
ln -sv apache-tomcat-8.0.23 tomcat
vim /etc/profile.d/tomcat.sh
(:set paste)
export CATALINA_HOME=/usr/local/tomcat
export PATH=$PATH:$CATALINA_HOME/bin
================
. /etc/profile.d/tomcat.sh
catalina.sh --help
catalina.sh version
catalina.sh start

windows浏览器访问 http://172.16.92.2:8080/
能看到tomcat首页即可

catalina.sh stop
mkdir -pv /data/webapps/ROOT/{lib,classes,META-INF,WEB-INF}
cd tomcat/conf
cp server.xml{,.bak}
vim server.xml
#添加虚拟主机
<Engine name="Catalina" defaultHost="node2.centos7.com" jvmRoute="TomcatA">  #修改
:set nu
:123,139y  -> p -> 修改成如下(添加虚拟主机)
      <Host name="node2.centos7.com"  appBase="/data/webapps"
            unpackWARs="true" autoDeploy="true">
        <Context path="" docBase="/data/webapps/ROOT" />
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="/data/logs"
               prefix="tomcatA_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
      </Host>
==============
mkdir /data/logs
catalina.sh configtest
>全部都是INFO开头的就正常了
(难道是把jar放在 /data/webapps/ROOT/lib 下?)


vim /data/webapps/ROOT/index.jsp
<%@ page language="java" %>
<html>
  <head><title>TomcatA</title></head>
  <body>
    <h1><font color="red">TomcatA.centos7.com</font></h1>
    <table align="centre" border="1">
      <tr>
        <td>Session ID</td>
    <% session.setAttribute("centos7.com","centos7.com"); %>
        <td><%= session.getId() %></td>
      </tr>
      <tr>
        <td>Created on</td>
        <td><%= session.getCreationTime() %></td>
     </tr>
    </table>
  </body>
</html>
================
catalina.sh start
ss -tnal | grep 8080

windows 浏览器访问 http://172.16.92.2:8080/
(第一次访问时间有点长)
----------------------------------------------------------------------------
TomcatA.centos7.com
Session ID     02D4D4F2C408321598102506715A00D9.TomcatA
Created on     1446023120028
-----------------------------------------------------------------------------


================ node3 172.16.92.3/16 ===================
安装JDK(光盘源)
mount /dev/cdrom /mnt/cdrom/
yum -y install java-1.7.0-openjdk

安装tomcat
scp node2:/root/apache-tomcat-8.0.23.tar.gz ./
tar xf apache-tomcat-8.0.23.tar.gz -C /usr/local
cd /usr/local
ln -sv apache-tomcat-8.0.23 tomcat
scp node2:/etc/profile.d/tomcat.sh /etc/profile.d/
. /etc/profile.d/tomcat.sh
catalina.sh --help
catalina.sh version
catalina.sh start

windows浏览器访问 http://172.16.92.3:8080/
能看到tomcat首页即可

catalina.sh stop

cd /usr/local/tomcat/conf/
cp server.xml{,.bak}
scp node2:/usr/local/tomcat/conf/server.xml ./
vim server.xml
<Engine name="Catalina" defaultHost="node3.centos7.com" jvmRoute="TomcatB">     #修改
<Host name="node3.centos7.com"  appBase="/data/webapps"                #修改
prefix="tomcatB_access_log" suffix=".txt"                        #修改
=================
catalina.sh configtest
mkdir -pv /data/webapps/ROOT/{lib,classes,META-INF,WEB-INF}
mkdir /data/logs
vim /data/webapps/ROOT/index.jsp

<%@ page language="java" %>
<html>
  <head><title>TomcatB</title></head>
  <body>
    <h1><font color="blue">TomcatB.centos7.com</font></h1>
    <table align="centre" border="1">
      <tr>
        <td>Session ID</td>
    <% session.setAttribute("centos7.com","centos7.com"); %>        
        <td><%= session.getId() %></td>
      </tr>
      <tr>
        <td>Created on</td>
        <td><%= session.getCreationTime() %></td>
     </tr>    </table>
  </body>
</html>
==========
catalina.sh start

windows 浏览器访问 http://172.16.92.3:8080/
-----------------------------------------------------------------------------
TomcatB.centos7.com
Session ID     CD4E5373840981DF41507DB8CF975CDD.TomcatB
Created on     1446023715170
-----------------------------------------------------------------------------



================ node4 172.16.92.4/16 ===================

apache做tomcat反向代理方式二 --- proxy_ajp_module
(光盘yum源)
mount /dev/cdrom /mnt/cdrom
yum -y install httpd
httpd -M | grep proxy_http_module

vim /etc/httpd/conf/httpd.conf
ServerName node4.centos7.com:80    #去注释并更改
#DocumentRoot "/var/www/html"    #注释中心主机
======================

vim /etc/httpd/conf.d/vhosts_ajp.conf    #修改成如下内容
=====================
<proxy balancer://lbcluster1>
        BalancerMember ajp://172.16.92.2:8009 loadfactor=10 route=TomcatA
        BalancerMember ajp://172.16.92.3:8009 loadfactor=10 route=TomcatB
</proxy>
<VirtualHost *:80>
        ServerName tomcat.centos7.com
        ProxyVia On
        ProxyRequests Off
        ProxyPreserveHost On
        <Proxy *>
                Require all granted
        </Proxy>
        ProxyPass / balancer://lbcluster1/
        ProxyPassReverse / balancer://lbcluster1/
        <Location />
                Require all granted
        </Location>
        <Location /balancer-manager>
                SetHandler balancer-manager
                Proxypass !
                Require all granted
                #Require ip 172.16.249.102
        </Location>
</VirtualHost>
===============end of vhosts_ajp.conf
httpd -t
systemctl start httpd.service


windows浏览器访问 http://172.16.92.4/index.jsp ,下面两个网页轮询
----------------------------------------------------------------------------
TomcatA.centos7.com
Session ID     66AEF95A272BFA8A05B415196844E1B0.TomcatA
Created on     1446024043386
----------------------------------------------------------------------------
TomcatB.centos7.com
Session ID     C8AE882F5AEAC2C0EFEDCFEA187EE17F.TomcatB
Created on     1446024053137
----------------------------------------------------------------------------

状态管理页同样是能访问的
http://172.16.92.4/balancer-manager
-----------------------------------------------------------------------------------
Load Balancer Manager for 172.16.92.4
Server Version: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_fcgid/2.3.9
Server Built: Mar 12 2015 15:07:19
.......
-----------------------------------------------------------------------------------




apache实现会话绑定

vim /etc/httpd/conf.d/vhosts_ajp.conf    
=====================添加第一行和第五行
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<proxy balancer://lbcluster1>
        BalancerMember ajp://172.16.92.2:8009 loadfactor=10 route=TomcatA    
        BalancerMember ajp://172.16.92.3:8009 loadfactor=10 route=TomcatB    
       ProxySet stickysession=ROUTEID
</proxy>
<VirtualHost *:80>
        ServerName tomcat.centos7.com
        ProxyVia On
        ProxyRequests Off
        ProxyPreserveHost On
        <Proxy *>
                Require all granted
        </Proxy>
        ProxyPass / balancer://lbcluster1/
        ProxyPassReverse / balancer://lbcluster1/
        <Location />
                Require all granted
        </Location>
        <Location /balancer-manager>
                SetHandler balancer-manager
                Proxypass !
                Require all granted
                #Require ip 172.16.249.102
        </Location>
</VirtualHost>
===============end of vhosts_ajp.conf
httpd -t
systemctl reload httpd.service

windows浏览器访问 http://172.16.92.4/index.jsp ,绑定在某个页面了
----------------------------------------------------------------------------
TomcatA.centos7.com
Session ID     2B234253F356F639B6062813AEBC36B0.TomcatA
Created on     1446024181177
----------------------------------------------------------------------------