; Nginx/httpd 代理两个Tomcat | Linux运维部落

Nginx/httpd 代理两个Tomcat

Nginx

前端代理服务器172.16.71.1

从ftp下载Nginx

安装


1
vim /etc/nginx/nginx.conf<br /><br />http {<br />...<br /># 添加以下内容<br />upstream tcsrvs {<br /> &nbsp; &nbsp; &nbsp; &nbsp; server 172.16.71.4:8080;<br /> &nbsp; &nbsp; &nbsp; &nbsp; server 172.16.71.5:8080;<br /> &nbsp; &nbsp; }<br />...<br /> }<br />

1
vim /etc/nginx/conf.d/default.conf<br /><br />location / {<br /> &nbsp; &nbsp;root &nbsp; /usr/share/nginx/html;<br /> &nbsp; &nbsp;proxy_pass http://tcsrvs/; &nbsp;#添加此行<br /> &nbsp; &nbsp;index &nbsp;index.html index.htm;<br />}<br />

后端Tomcat服务器

1
172.16.71.4

1
172.16.71.5

两个主机都要安装jdk和Tomcat


1
yum install java-1.8.0-openjdk-devel -y<br />yum install tomcat -y<br />

主机1


1
mkdir -pv /var/lib/tomcat/webapps/test/{lib,classes,WEB-INF}<br />vim /var/lib/tomcat/webapps/test/index.jsp<br /><br /><br />&lt;%@ page language=&quot;java&quot; %&gt;<br />&lt;html&gt;<br /> &nbsp;&lt;head&gt;&lt;title&gt;TomcatA&lt;/title&gt;&lt;/head&gt;<br /> &nbsp;&lt;body&gt;<br /> &nbsp; &nbsp;&lt;h1&gt;&lt;font color=&quot;red&quot;&gt;TomcatA.magedu.com&lt;/font&gt;&lt;/h1&gt;<br /> &nbsp; &nbsp;&lt;table align=&quot;centre&quot; border=&quot;1&quot;&gt;<br /> &nbsp; &nbsp; &nbsp;&lt;tr&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;&lt;td&gt;Session ID&lt;/td&gt;<br /> &nbsp; &nbsp;&lt;% session.setAttribute(&quot;magedu.com&quot;,&quot;magedu.com&quot;); %&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;&lt;td&gt;&lt;%= session.getId() %&gt;&lt;/td&gt;<br /> &nbsp; &nbsp; &nbsp;&lt;/tr&gt;<br /> &nbsp; &nbsp; &nbsp;&lt;tr&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;&lt;td&gt;Created on&lt;/td&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;&lt;td&gt;&lt;%= session.getCreationTime() %&gt;&lt;/td&gt;<br /> &nbsp; &nbsp; &lt;/tr&gt;<br /> &nbsp; &nbsp;&lt;/table&gt;<br /> &nbsp;&lt;/body&gt;<br />&lt;/html&gt;<br /><br /><br />systemctl start tomcat <br />

主机2


1
mkdir -pv /var/lib/tomcat/webapps/test/{lib,classes,WEB-INF}<br />vim /var/lib/tomcat/webapps/test/index.jsp<br /><br /><br />&lt;%@ page language=&quot;java&quot; %&gt;<br />&lt;html&gt;<br /> &nbsp;&lt;head&gt;&lt;title&gt;TomcatB&lt;/title&gt;&lt;/head&gt;<br /> &nbsp;&lt;body&gt;<br /> &nbsp; &nbsp;&lt;h1&gt;&lt;font color=&quot;red&quot;&gt;TomcatB.magedu.com&lt;/font&gt;&lt;/h1&gt;<br /> &nbsp; &nbsp;&lt;table align=&quot;centre&quot; border=&quot;1&quot;&gt;<br /> &nbsp; &nbsp; &nbsp;&lt;tr&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;&lt;td&gt;Session ID&lt;/td&gt;<br /> &nbsp; &nbsp;&lt;% session.setAttribute(&quot;magedu.com&quot;,&quot;magedu.com&quot;); %&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;&lt;td&gt;&lt;%= session.getId() %&gt;&lt;/td&gt;<br /> &nbsp; &nbsp; &nbsp;&lt;/tr&gt;<br /> &nbsp; &nbsp; &nbsp;&lt;tr&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;&lt;td&gt;Created on&lt;/td&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;&lt;td&gt;&lt;%= session.getCreationTime() %&gt;&lt;/td&gt;<br /> &nbsp; &nbsp; &lt;/tr&gt;<br /> &nbsp; &nbsp;&lt;/table&gt;<br /> &nbsp;&lt;/body&gt;<br />&lt;/html&gt;<br /><br />systemctl start tomcat <br />

前端代理


1
systemctl start nginx <br />

测试

从浏览器访问

1
172.16.71.1

,显示Tomcat欢迎页面

从浏览器访问

1
172.16.71.1/test

,显示测试页面信息,刷新会变化。


httpd


1
yum install httpd -y<br /><br />vim /etc/httpd/conf.d/tomcat_httpd.conf<br /><br />&lt;proxy balancer://tcsrvs&gt;<br /> &nbsp; &nbsp;BalancerMember http://172.16.71.4:8080<br /> &nbsp; &nbsp;BalancerMember http://172.16.71.5:8080<br /> &nbsp; &nbsp;ProxySet lbmethod=byrequests<br />&lt;/Proxy&gt;<br />&lt;VirtualHost *:80&gt;<br /> &nbsp; &nbsp;ServerName www.magedu.com<br /> &nbsp; &nbsp;ProxyVia On<br /> &nbsp; &nbsp;ProxyRequests Off <br /> &nbsp; &nbsp;ProxyPreserveHost On<br /> &nbsp; &nbsp;&lt;Proxy *&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;Require all granted<br /> &nbsp; &nbsp;&lt;/Proxy&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;ProxyPass / balancer://tcsrvs/<br /> &nbsp; &nbsp; &nbsp; &nbsp;ProxyPassReverse / balancer://tcsrvs/<br /> &nbsp; &nbsp;&lt;Location /&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;Require all granted<br /> &nbsp; &nbsp;&lt;/Location&gt;<br />&lt;/VirtualHost&gt; &nbsp; &nbsp;<br /><br />systemctl start httpd<br />

测试

从浏览器访问

1
172.16.71.1

,显示Tomcat欢迎页面

从浏览器访问

1
172.16.71.1/test

,显示测试页面信息,刷新会变化。


实现会话粘性方法

1
172.16.71.4


1
vim /etc/tomcat/server.xml<br /><br /> &nbsp; &nbsp;&lt;Engine name=&quot;Catalina&quot; defaultHost=&quot;localhost&quot; jvmRoute=&quot;TomcatA&quot;&gt; #修改此行<br /><br /><br />systemctl restart tomcat<br />

1
172.16.71.5


1
vim /etc/tomcat/server.xml<br /><br /> &nbsp; &nbsp;&lt;Engine name=&quot;Catalina&quot; defaultHost=&quot;localhost&quot; jvmRoute=&quot;TomcatB&quot;&gt; #修改此行<br /><br />systemctl restart tomcat<br />

1
172.16.71.1


1
vim /etc/httpd/conf.d/tomcat_httpd.conf<br /><br />Header add Set-Cookie &quot;ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/&quot; env=BALANCER_ROUTE_CHANGED<br />&lt;proxy balancer://tcsrvs&gt;<br /> &nbsp; &nbsp;BalancerMember http://172.18.100.67:8080 route=TomcatA loadfactor=1<br /> &nbsp; &nbsp;BalancerMember http://172.18.100.68:8080 route=TomcatB loadfactor=2<br /> &nbsp; &nbsp;ProxySet lbmethod=byrequests<br /> &nbsp; &nbsp;ProxySet stickysession=ROUTEID<br />&lt;/Proxy&gt;<br />&lt;VirtualHost *:80&gt;<br /> &nbsp; &nbsp;ServerName lb.magedu.com<br /> &nbsp; &nbsp;ProxyVia On<br /> &nbsp; &nbsp;ProxyRequests Off<br /> &nbsp; &nbsp;ProxyPreserveHost On<br /> &nbsp; &nbsp;&lt;Proxy *&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;Require all granted<br /> &nbsp; &nbsp;&lt;/Proxy&gt;<br /> &nbsp; &nbsp;ProxyPass / balancer://tcsrvs/<br /> &nbsp; &nbsp;ProxyPassReverse / balancer://tcsrvs/<br /> &nbsp; &nbsp;&lt;Location /&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;Require all granted<br /> &nbsp; &nbsp;&lt;/Location&gt;<br />&lt;/VirtualHost&gt; &nbsp;<br /><br />systemctl restart httpd<br />

测试

从浏览器访问

1
172.16.71.1

,显示Tomcat欢迎页面

从浏览器访问

1
172.16.71.1/test

,显示测试页面信息,刷新不会变化。


启用管理接口


1
vim /etc/httpd/conf.d/balaner_manager.conf<br /><br />&lt;Location /balancer-manager&gt;<br /> &nbsp; &nbsp;SetHandler balancer-manager<br /> &nbsp; &nbsp;ProxyPass !<br /> &nbsp; &nbsp;Require all granted<br />&lt;/Location&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /><br />systemctl restart httpd<br /><br />

测试

浏览器访问

1
172.16.71.1/balancer-manager

会出现管理接口

ajp balancer


1
vim /etc/httpd/conf.d/tomcat-ajp.conf<br /><br />&lt;proxy balancer://tcsrvs&gt;<br /> &nbsp; &nbsp;BalancerMember ajp://172.16.71.4:8009<br /> &nbsp; &nbsp;BalancerMember ajp://172.16.71.5:8009<br /> &nbsp; &nbsp;ProxySet lbmethod=byrequests<br />&lt;/Proxy&gt;<br />&lt;VirtualHost *:80&gt;<br /> &nbsp; &nbsp;ServerName lb.magedu.com<br /> &nbsp; &nbsp;ProxyVia On<br /> &nbsp; &nbsp;ProxyRequests Off<br /> &nbsp; &nbsp;ProxyPreserveHost On<br /> &nbsp; &nbsp;&lt;Proxy *&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;Require all granted<br /> &nbsp; &nbsp;&lt;/Proxy&gt;<br /> &nbsp; &nbsp;ProxyPass / balancer://tcsrvs/<br /> &nbsp; &nbsp;ProxyPassReverse / balancer://tcsrvs/<br /> &nbsp; &nbsp;&lt;Location /&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;Require all granted<br /> &nbsp; &nbsp;&lt;/Location&gt;<br /> &nbsp; &nbsp;&lt;Location /balancer-manager&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;SetHandler balancer-manager<br /> &nbsp; &nbsp; &nbsp; &nbsp;ProxyPass !<br /> &nbsp; &nbsp; &nbsp; &nbsp;Require all granted<br /> &nbsp; &nbsp;&lt;/Location&gt;<br />&lt;/VirtualHost&gt; &nbsp;<br />

测试

从浏览器访问

1
172.16.71.1

,显示Tomcat欢迎页面

从浏览器访问

1
172.16.71.1/test

,显示测试页面信息,刷新会变化。

会话绑定与前面相似


1
vim /etc/httpd/conf.d/tomcat-ajp.conf<br /><br />&lt;proxy balancer://tcsrvs&gt;<br /> &nbsp; &nbsp;BalancerMember ajp://172.16.71.4:8009 route=TomcatA loadfactor=1<br /> &nbsp; &nbsp;BalancerMember ajp://172.16.71.5:8009 route=TomcatB loadfactor=1<br /> &nbsp; &nbsp;ProxySet lbmethod=byrequests<br />&lt;/Proxy&gt;<br />&lt;VirtualHost *:80&gt;<br /> &nbsp; &nbsp;ServerName lb.magedu.com<br /> &nbsp; &nbsp;ProxyVia On<br /> &nbsp; &nbsp;ProxyRequests Off<br /> &nbsp; &nbsp;ProxyPreserveHost On<br /> &nbsp; &nbsp;&lt;Proxy *&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;Require all granted<br /> &nbsp; &nbsp;&lt;/Proxy&gt;<br /> &nbsp; &nbsp;ProxyPass / balancer://tcsrvs/<br /> &nbsp; &nbsp;ProxyPassReverse / balancer://tcsrvs/<br /> &nbsp; &nbsp;&lt;Location /&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;Require all granted<br /> &nbsp; &nbsp;&lt;/Location&gt;<br /> &nbsp; &nbsp;&lt;Location /balancer-manager&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;SetHandler balancer-manager<br /> &nbsp; &nbsp; &nbsp; &nbsp;ProxyPass !<br /> &nbsp; &nbsp; &nbsp; &nbsp;Require all granted<br /> &nbsp; &nbsp;&lt;/Location&gt;<br />&lt;/VirtualHost&gt; &nbsp;<br />

Tomcat集群

1
172.16.71.4


1
vim /etc/tomcat/server.xml<br /><br /> &nbsp; &nbsp; &lt;Engine name=&quot;Catalina&quot; defaultHost=&quot;localhost&quot; jvmRoute=&quot;TomcatA&quot;&gt; # jvmRoute 一定要有<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp;&lt;Cluster className=&quot;org.apache.catalina.ha.tcp.SimpleTcpCluster&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; channelSendOptions=&quot;8&quot;&gt;<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Manager className=&quot;org.apache.catalina.ha.session.DeltaManager&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; expireSessionsOnShutdown=&quot;false&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; notifyListenersOnReplication=&quot;true&quot;/&gt;<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Channel className=&quot;org.apache.catalina.tribes.group.GroupChannel&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Membership className=&quot;org.apache.catalina.tribes.membership.McastService&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;address=&quot;228.0.71.4&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;port=&quot;45564&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;frequency=&quot;500&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dropTime=&quot;3000&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Receiver className=&quot;org.apache.catalina.tribes.transport.nio.NioReceiver&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;address=&quot;172.16.71.4&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;port=&quot;4000&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;autoBind=&quot;100&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;selectorTimeout=&quot;5000&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;maxThreads=&quot;6&quot;/&gt;<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Sender className=&quot;org.apache.catalina.tribes.transport.ReplicationTransmitter&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Transport className=&quot;org.apache.catalina.tribes.transport.nio.PooledParallelSender&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/Sender&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Interceptor className=&quot;org.apache.catalina.tribes.group.interceptors.TcpFailureDetector&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Interceptor className=&quot;org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/Channel&gt;<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Valve className=&quot;org.apache.catalina.ha.tcp.ReplicationValve&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filter=&quot;&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Valve className=&quot;org.apache.catalina.ha.session.JvmRouteBinderValve&quot;/&gt;<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Deployer className=&quot;org.apache.catalina.ha.deploy.FarmWarDeployer&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tempDir=&quot;/tmp/war-temp/&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deployDir=&quot;/tmp/war-deploy/&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;watchDir=&quot;/tmp/war-listen/&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;watchEnabled=&quot;false&quot;/&gt;<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;ClusterListener className=&quot;org.apache.catalina.ha.session.ClusterSessionListener&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;&lt;/Cluster&gt;<br />

1
cp /etc/tomcat/web.xml &nbsp;/var/lib/tomcat/webapps/test/WEB-INF/<br />vim /var/lib/tomcat/webapps/test/WEB-INF/web.xml <br /><br />&lt;distributable/&gt; # 添加<br /><br />systemctl restart tomcat<br />

1
172.16.71.5

同理


1
vim /etc/tomcat/server.xml<br /><br /> &nbsp; &nbsp; &lt;Engine name=&quot;Catalina&quot; defaultHost=&quot;localhost&quot; jvmRoute=&quot;TomcatB&quot;&gt; # jvmRoute 一定要有<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp;&lt;Cluster className=&quot;org.apache.catalina.ha.tcp.SimpleTcpCluster&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; channelSendOptions=&quot;8&quot;&gt;<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Manager className=&quot;org.apache.catalina.ha.session.DeltaManager&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; expireSessionsOnShutdown=&quot;false&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; notifyListenersOnReplication=&quot;true&quot;/&gt;<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Channel className=&quot;org.apache.catalina.tribes.group.GroupChannel&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Membership className=&quot;org.apache.catalina.tribes.membership.McastService&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;address=&quot;228.0.71.4&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;port=&quot;45564&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;frequency=&quot;500&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dropTime=&quot;3000&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Receiver className=&quot;org.apache.catalina.tribes.transport.nio.NioReceiver&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;address=&quot;172.16.71.5&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;port=&quot;4000&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;autoBind=&quot;100&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;selectorTimeout=&quot;5000&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;maxThreads=&quot;6&quot;/&gt;<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Sender className=&quot;org.apache.catalina.tribes.transport.ReplicationTransmitter&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Transport className=&quot;org.apache.catalina.tribes.transport.nio.PooledParallelSender&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/Sender&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Interceptor className=&quot;org.apache.catalina.tribes.group.interceptors.TcpFailureDetector&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Interceptor className=&quot;org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/Channel&gt;<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Valve className=&quot;org.apache.catalina.ha.tcp.ReplicationValve&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filter=&quot;&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Valve className=&quot;org.apache.catalina.ha.session.JvmRouteBinderValve&quot;/&gt;<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Deployer className=&quot;org.apache.catalina.ha.deploy.FarmWarDeployer&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tempDir=&quot;/tmp/war-temp/&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deployDir=&quot;/tmp/war-deploy/&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;watchDir=&quot;/tmp/war-listen/&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;watchEnabled=&quot;false&quot;/&gt;<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;ClusterListener className=&quot;org.apache.catalina.ha.session.ClusterSessionListener&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp;&lt;/Cluster&gt;<br />

1
cp /etc/tomcat/web.xml &nbsp;/var/lib/tomcat/webapps/test/WEB-INF/<br />vim /var/lib/tomcat/webapps/test/WEB-INF/web.xml <br /><br />&lt;distributable/&gt; # 添加<br /><br />systemctl restart tomcat<br />

测试

从浏览器访问

1
172.16.71.1

,显示Tomcat欢迎页面

从浏览器访问

1
172.16.71.1/test

,显示测试页面信息,刷新不会变化。

注意:一定要先为主机配置网关,否则Tomcat将无法启动


memcached 实现session存储

1
172.16.71.4

1
172.16.71.5


1
vim /etc/tomcat/server.xml<br /><br /># 删除上一步添加的内容<br /><br />systemctl stop tomcat<br />

1
yum install memcached -y<br /><br />systemctl start memcached<br />

下载类库


1
cd /usr/share/tomcat/lib<br />lftp 172.16.0.1<br />cd pub/Sources/7.x86_64/msm/<br />mget *<br />bye<br />

1
vim /etc/tomcat/server.xml<br /><br />#在&lt;Host&gt;中添加:<br />&lt;Context path=&quot;/&quot; docBase=&quot;test&quot; reloadable=&quot;true&quot;&gt;<br />&lt;/Context&gt;<br /><br />systemctl start tomcat<br />

测试

从浏览器访问

1
172.16.71.1

,显示Tomcat欢迎页面

从浏览器访问

1
172.16.71.1/test

,显示测试页面信息,刷新不会变化。

添加session保持

1
172.16.71.4

 

1
172.16.71.5


1
vim /etc/tomcat/server.xml<br /><br /> &nbsp; &nbsp; &nbsp;&lt;Host name=&quot;localhost&quot; &nbsp;appBase=&quot;webapps&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;unpackWARs=&quot;true&quot; autoDeploy=&quot;true&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Context path=&quot;/sample&quot; docBase=&quot;sample&quot; reloadable=&quot;true&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Manager className=&quot;de.javakaffee.web.msm.MemcachedBackupSessionManager&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;memcachedNodes=&quot;n1:172.16.71.4:11211,n2:172.16.71.5:11211&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;failoverNodes=&quot;n1&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;requestUriIgnorePattern=&quot;.*\.(ico|png|gif|jpg|css|js)$&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;transcoderFactoryClass=&quot;de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory&quot;<br /><br /><br />systemctl restart tomcat<br />

测试

从浏览器访问

1
172.16.71.1

,显示Tomcat欢迎页面

从浏览器访问

1
172.16.71.1/sample

,显示测试页面信息,刷新session不会变化,内容会变化。

注意:此处前端要使用Nginx,httpd不能实现以上功能,原因未知。

原创文章,作者:wangshuai,如若转载,请注明出处:/68251

发表评论

电子邮件地址不会被公开。 必填项已用*标注

联系我们

400-080-6560

在线咨询:点击这里给我发消息

邮件:1660809109@qq.com

工作时间:周一至周五,9:30-18:30,节假日同时也值班

友情链接:万达直属  万达娱乐主管QQ  万达娱乐招商QQ  万达娱乐主管QQ  万达主管  万达娱乐招商  万达娱乐开户  万达娱乐注册  万达娱乐  万达招商