1
2
3
4
5
6
7
8
|
[root@lw-01 opt]
# tar zxvf tomcat-connectors-1.2.40-src.tar.gz
进入tomcat-connectors的native目录:
[root@lw-01 opt]
# cd tomcat-connectors-1.2.40-src/native/
进行编译参数设置:
[root@lw-01 native]
# ./buildconf.sh
[root@lw-01 native]
# ./configure --with-apxs=/usr/local/apache2/bin/apxs\ --with-java-home=$JAVA_HOME --with-java-platform=2\ --enable-jni
[root@lw-01 native]
# make && make install
|
1
2
|
[root@lw-02 opt]
# ls
apache-tomcat-8.0.14-1 apache-tomcat-8.0.14-2
|
1
2
3
4
5
6
|
[root@lw-02 conf]
# pwd
/opt/apache-tomcat-8
.0.14-2
/conf
[root@lw-02 conf]
# cat server.xml | grep port | grep -v "\!"
<Server port=
"8007"
shutdown
=
"SHUTDOWN"
>
//
默认是8006改为8007
<Connector port=
"8081"
protocol=
"HTTP/1.1"
//
默认是8080改为8081
<Connector port=
"8010"
protocol=
"AJP/1.3"
redirectPort=
"8443"
/>
//
默认是8009改为8010
|
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
35
36
37
38
39
|
<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"
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
5
6
7
8
9
10
11
|
# Load mod_jk module
LoadModule jk_module modules
/mod_jk
.so
# Specify jk log file.
JkLogFile
/var/log/mod_jk
.log
# Specify jk log level [debug/error/info]
JkLogLevel info
# Specify workers.properties, this file tell jk:
# how many nodes and where they are.
JkWorkersFile conf
/workers
.properties
# Specify which requests should handled by which node.
JkMount /* controller
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
[root@lw-01 conf]
# pwd
/usr/local/appache/conf
[root@lw-01 conf]
# cat workers.properties
#所有节点列表,其中controller是一个逻辑结点,负责负载均衡控制,
#如果JkMount中的URL指定给了controller就表示这个请求会被自动散列到某个物理节点上。
#注意:真正负责处理请求的tomcat的名称(这里就是tomcat1,tomcat2)必须于它们在conf/server.xml文件中配置的jvmRoute的属性值是一致的!
worker.list = controller
#========tomcat1========
worker.tomcat1.port=8009
#ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.host=192.168.1.111
#tomcat的主机地址,如不为本机,请填写ip地
worker.tomcat1.
type
=ajp13
worker.tomcat1.lbfactor = 1
#server的加权比重,值越高,分得的请求越多
#========tomcat2========
worker.tomcat2.port=8010
#ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.host=192.168.1.111
#tomcat的主机地址,如不为本机,请填写ip地址worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1
#server的加权比重,值越高,分得的请求越多
#========controller,负载均衡控制器========
worker.controller.
type
=lb
worker.controller.balance_workers=tomcat1,tomcat2
#指定分担请求的tomcat,旧版本中的balanced_workers,已不再推荐使用!
worker.controller.sticky_session=1
#sticky_session为1表示当某一 client的session创建之后,后续由该客户端发起的请求,也就是这个session的所有请求都始终由第一次处理该请求的结点负责处理(除非该结点挂掉)
|
1
2
3
4
5
6
7
8
9
|
[root@lw-02
test
]
# pwd
/opt/apache-tomcat-8
.0.14-2
/webapps/test
[root@lw-02
test
]
# tree
.
├── index.jsp
└── WEB-INF
└── web.xml
1 directory, 2 files
|
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
35
36
|
[root@lw-02
test
]
# cat index.jsp
<%@ page contentType=
"text/html; charset=UTF-8"
%>
<%@ page
import
=
"java.util.*"
%>
<html><
head
><title>Cluster App Test<
/title
><
/head
>
<body>
<%
System.out.println(
"SessionID:"
+ session.getId());
%>
Server Info:
<%
out.println(request.getLocalAddr() +
" : "
+ request.getLocalPort()+
"<br>"
);%>
<%
out.println(
"<br> ID "
+ session.getId()+
"<br>"
);
//
如果有新的 Session 属性设置
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(
"============================"
);
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);
}
%>
<form action=
"index.jsp"
method=
"POST"
>
名称:<input
type
=text size=20 name=
"dataName"
>
<br>
数值:<input
type
=text size=20 name=
"dataValue"
>
<br>
<input
type
=submit>
<
/form
>
<
/body
>
|
1
2
3
4
5
6
7
8
|
[root@lw-02
test
]
# cat WEB-INF/web.xml
<web-app xmlns=
"http://java.sun.com/xml/ns/j2ee"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://java.sun.com/xml/ns/j2ee [url]http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd[/url]"
version=
"2.4"
>
<display-name>TomcatDemo<
/display-name
>
<distributable/>
<
/web-app
>
|
欢迎大家访问我的个人网站
萌萌的IT人