Tomcat原理详解和各种集群的实现
程序员文章站
2022-07-12 10:20:38
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@TomcatA ~] # rpm -ivh jdk-7u9-linux-x64.rpm
[root@TomcatA ~] # ll /usr/java/
total 4 lrwxrwxrwx 1 root root 16 Oct 3 19:52 default -> /usr/java/latest
drwxr-xr-x 10 root root 4096 Oct 3 19:52 jdk1.7.0_09 lrwxrwxrwx 1 root root 21 Oct 3 19:52 latest -> /usr/java/jdk1 .7.0_09
[root@TomcatA ~] # vim /etc/profile.d/java.sh
export JAVA_HOME= /usr/java/latest
export PATH=$JAVA_HOME /bin :$PATH
[root@TomcatA ~] # . /etc/profile.d/java.sh
[root@TomcatA ~] # java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05) Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode) [root@TomcatA ~] #
|
1
2
3
4
5
6
7
8
9
|
[root@TomcatA ~] # tar xf apache-tomcat-7.0.42.tar.gz -C /usr/local/
[root@TomcatA ~] # cd /usr/local/
[root@TomcatA ~] # ln -sv apache-tomcat-7.0.42 tomcat
`tomcat' -> `apache-tomcat-7.0.42 [root@TomcatA ~] # vim /etc/profile.d/tomcat.sh
export CATALINA_HOME= /usr/local/tomcat
exportPATH=$CATALINA_HOME /bin :$PATH
[root@TomcatA ~] # catalina.sh --help #显示相关的命令选项
[root@TomcatA ~] # jps #显示当前系统运行的JVM程序
|
1
2
3
4
5
6
7
8
9
10
|
#!/bin/sh # Tomcat init script for Linux. # # chkconfig: 2345 96 14 # description: The Apache Tomcat servlet/JSP container. JAVA_OPTS= '-Xms64m -Xmx256m' #设置JAVA运行时的内容大小
JAVA_HOME= /usr/java/latest
CATALINA_HOME= /usr/local/tomcat
export JAVA_HOME CATALINA_HOME
exec $CATALINA_HOME /bin/catalina .sh $*
|
1
2
3
|
[root@TomcatA ~] # cd /usr/local/tomcat/webapps/
[root@TomcatA webapps] # mkdir -pv test/WEB-INF/{classes,lib}
[root@TomcatA webapps] # vim test/index.jsp
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<%@ page language= "java" %>
<html> <head><title>TomcatA</title></head>
<body>
<h1><font color= "red" >TomcatA</font></h1>
<table align= "centre" border= "1" >
<tr>
<td>Session ID</td> <% session.setAttribute( "abc" , "abc" ); %>
<td><%= session.getId() %></td> </tr>
<tr>
<td>Created on</td> <td><%= session.getCreationTime() %></td> </tr>
</table> </body>
</html> |
1
|
[root@TomcatA webapps] # vim test/index.jsp
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<%@ page language= "java" %>
<html> <head><title>TomcatB</title></head>
<body>
<h1><font color= "blue" >TomcatB</font></h1>
<table align= "centre" border= "1" >
<tr>
<td>Session ID</td> <% session.setAttribute( "abc" , "abc" ); %>
<td><%= session.getId() %></td> </tr>
<tr>
<td>Created on</td> <td><%= session.getCreationTime() %></td> </tr>
</table> </body>
</html> |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
[root@apache ~] # vim /etc/httpd/conf.d/mod_proxy.conf
ProxyVia on ProxyRequests Off #关闭正向代理
ProxyPreserveHost Off <Proxy balancer: //xkun > #定义代理的后端real server
BalancerMemberajp: //192 .168.21.1:8009 loadfactor=1
BalancerMemberajp: //192 .168.21.2:8009 loadfactor=1
ProxySetlbmethod=byrequests
< /Proxy >
<Location /xkun > #状态检测的实现
SetHandler balancer-manager #调用处理模块
Proxypass ! #不向后方代理
Order allow,deny #定义访问权限
Allow from all #建议在实际生产中做好访问控制
< /Location >
<Proxy *> #相关反向代理的权限控制
Order allow,deny
Allow from all
< /Proxy >
ProxyPass / balancer: //xkun/ #设置代理路径的映射管理
ProxyPassReverse / balancer: //xkun/
<Location / > #定义相关的访问控制策略
Order allow,deny
Allow from all
< /Location >
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
< Cluster className = "org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions = "8" >
< Manager className = "org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown = "false"
notifyListenersOnReplication = "true" />
< Channel className = "org.apache.catalina.tribes.group.GroupChannel" >
< Membership className = "org.apache.catalina.tribes.membership.McastService"
address = "228.0.0.4"
port = "45564"
frequency = "500"
dropTime = "3000" />
< Receiver className = "org.apache.catalina.tribes.transport.nio.NioReceiver"
address = "auto" <!--注意修改地址为自己的网卡IP -->
port="4000"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
< Sender className = "org.apache.catalina.tribes.transport.ReplicationTransmitter" >
< Transport className = "org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
</ Sender >
< Interceptor className = "org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
< Interceptor className = "org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
</ Channel >
< Valve className = "org.apache.catalina.ha.tcp.ReplicationValve"
filter = "" />
< Valve className = "org.apache.catalina.ha.session.JvmRouteBinderValve" />
< Deployer className = "org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir = "/tmp/war-temp/"
deployDir = "/tmp/war-deploy/"
watchDir = "/tmp/war-listen/"
watchEnabled = "false" />
< ClusterListener className = "org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener" />
< ClusterListener className = "org.apache.catalina.ha.session.ClusterSessionListener" />
</ Cluster >
|
1
2
3
4
|
[root@TomcatA ~] # cd /usr/local/tomcat/conf/
[root@TomcatA conf] # cp -a web.xml ../webapps/test/WEB-INF/
# 修改web.xml文件在 web-app 容器中添加如下行: <distributable /> |
1
2
3
4
5
6
|
[root@TomcatA ~] # unzip shopxx-a5-Beta.zip
[root@TomcatA ~] # cd shopxx-v3.0-Beta/
[root@TomcatA shopxx-v3.0-Beta] # ls shopxx-3.0Beta/
admin favicon.ico install META-INF robots.txt upload
changelog.txt index.jsp license.html resources shopxx.txt WEB-INF [root@TomcatA shopxx-v3.0-Beta] # mv shopxx-3.0Beta /usr/local/tomcat/webapps/shop
|
1
2
3
|
mysql> create database shopxx; mysql> create user 'showuser' @ '%' identified by 'showpass' ;
mysql> grant all on shopxx.* to 'showuser' @ '%' ;
|
1
|
# scp -rp shop 192.168.21.2:/usr/local/tomcat/webapps/root@192.168.21.2 |
上一篇: swing 实现JBPM 4.2例子
下一篇: 权限问题