全部系统采用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.5 node5.centos7.com node5
node2, node3 --> tomcat ( jsp网站服务器 )
node5 --> httpd(mod_jk) 反向代理至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
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
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 "%r" %s %b" />
</Host>
==============
mkdir -pv /data/logs
catalina.sh configtest
>全部都是INFO开头的就正常了
(难道是把jar放在 /data/webapps/ROOT/lib 下?)
mkdir -pv /data/webapps/ROOT/{lib,classes,META-INF,WEB-INF}
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 0BFA3EE6FC07F3BD88FA5036B0E79771.TomcatA
Created on 1446027380322
--------------------------------------------------------------------
================ 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" #修改
=================
mkdir -pv /data/webapps/ROOT/{lib,classes,META-INF,WEB-INF}
mkdir /data/logs
vim /data/webapps/ROOT/index.jsp
(:set paste)
<%@ 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 configtest
>全部都是INFO开头的就是正常了
catalina.sh start
windows 浏览器访问 http://172.16.92.3:8080/
(第一次访问时间会比较长)
-----------------------------------------------------------------------
TomcatB.centos7.com
Session ID CC4D40356F6AF35CFA57D1B635BC4386.TomcatB
Created on 1446028117653
-----------------------------------------------------------------------
================ node5 172.16.92.5/16 ===================
apache做tomcat反向代理方式三 --- mod_jk
wget http://www.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.40-src.tar.gz
mount /dev/cdrom /mnt/cdrom
yum -y install httpd
yum -y groupinstall "Development Tools"
yum -y install gcc glibc-devel httpd-devel
tar xf tomcat-connectors-1.2.40-src.tar.gz
cd tomcat-connectors-1.2.40-src/native
./configure --with-apxs=/usr/bin/apxs
make && make install
vim /etc/httpd/conf/httpd.conf
ServerName node5.centos7.com:80 #去注释并更改
#DocumentRoot "/var/www/html" #加注释
==============
vim /etc/httpd/conf.d/mod_jk.conf
LoadModule jk_module modules/mod_jk.so
JkWorkersFile /etc/httpd/conf.d/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel debug
JkMount /* TomcatA #只反代到TomcatA
JkMount /status/ stat1
===============
vim /etc/httpd/conf.d/workers.properties
worker.list=TomcatA,stat1
worker.TomcatA.port=8009
worker.TomcatA.host=172.16.92.2
worker.TomcatA.type=ajp13
worker.TomcatA.lbfactor=1
worker.stat1.type = status
=================
httpd -t
systemctl start httpd
ss -tanl | grep 80
windows浏览器访问 http://172.16.92.5/, 只看到第一个页面
-------------------------------------------------------------------------------
TomcatA.centos7.com
Session ID DD6356EB4465083243F9379F29047B9D
Created on 1446027043639
-------------------------------------------------------------------------------
windows浏览器访问 http://172.16.92.5/status/ (注意:最后的斜杠/不能缺少)
--------------------------------------------------------------------------------------------------------
JK Status Manager for 172.16.92.5:80
Server Version: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_fcgid/2.3.9 mod_jk/1.2.40 Server Time: Wed, 28 Oct 2015 00:32:14 CST
JK Version: mod_jk/1.2.40 Unix Seconds: 1445963534
.........
--------------------------------------------------------------------------------------------------------
apache基于mod_jk模块对多个tomcat负载均衡
vim /etc/httpd/conf.d/mod_jk.conf
LoadModule jk_module modules/mod_jk.so
JkWorkersFile /etc/httpd/conf.d/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel debug
JkMount /* lbcluster1
JkMount /status/ stat1
==========================
vim /etc/httpd/conf.d/workers.properties
worker.list = lbcluster1,stat1
worker.TomcatA.type = ajp13
worker.TomcatA.host = 172.16.92.2
worker.TomcatA.port = 8009
worker.TomcatA.lbfactor = 1
worker.TomcatB.type = ajp13
worker.TomcatB.host = 172.16.92.3
worker.TomcatB.port = 8009
worker.TomcatB.lbfactor = 1
worker.lbcluster1.type = lb
worker.lbcluster1.sticky_session = 0
worker.lbcluster1.balance_workers = TomcatA, TomcatB
worker.stat1.type = status
============================
httpd -t
systemctl reload httpd
( systemctl start httpd )
windows浏览器访问 http://172.16.92.5/
-------------------------------------------------------------------------------
TomcatA.centos7.com
Session ID D262A57364DE5DC44847005DC115DDC4.TomcatA
Created on 1446028212973
-------------------------------------------------------------------------------
TomcatB.centos7.com
Session ID E084352D5514528A006693BE0231538A.TomcatB
Created on 1446028199998
-------------------------------------------------------------------------------
apache基于mod_jk模块对多个tomcat负载均衡并实现会话(session)绑定
vim /etc/httpd/conf.d/workers.properties
worker.list = lbcluster1,stat1
worker.TomcatA.type = ajp13
worker.TomcatA.host = 172.16.92.2
worker.TomcatA.port = 8009
worker.TomcatA.lbfactor = 1
worker.TomcatB.type = ajp13
worker.TomcatB.host = 172.16.92.3
worker.TomcatB.port = 8009
worker.TomcatB.lbfactor = 1
worker.lbcluster1.type = lb
worker.lbcluster1.sticky_session = 1 #修改
worker.lbcluster1.balance_workers = TomcatA, TomcatB
worker.stat1.type = status
=====================================
httpd -t
systemctl reload httpd
(systemctl start httpd)
windows浏览器访问 http://172.16.92.5/, 会话绑定在某一主机上
-------------------------------------------------------------------------------
TomcatA.centos7.com
Session ID 82BAFDE1D04873CEB20F762F2631B8FA.TomcatA
Created on 1445964263757
-------------------------------------------------------------------------------