Tomcat集群session复制,httpd/nginx反代Tomcat集群

一个大型站点都会涉及到动态应用,动态应用都需要做会话保持,常见的会话保持方式就三种,一是session stick,二是session replication,三是session share,对于小型规模的tomcat集群,大多者会采用session replication方式,但阅读官方文档也好,查询大牛博客也罢,发现均有不准确之处,所以亲测成功实现之后得出如下文档,还望高人指点。

实验环境:

操作系统:CentOS 7.2

tomcat版本:tomcat-7.0.54yum安装方式)

httpd版本:httpd-2.4.6yum安装方式)

nginx版本:nginx-1.10.2yum安装方式)

iptables状态:disable

SELinux状态:disable

TomcatA配置过程

[root@TomcatA ~]# ifconfig

eno16777736:flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

inet 192.168.0.20  netmask255.255.255.0  broadcast 192.168.0.255

inet6 fe80::20c:29ff:fefe:64f3 prefixlen 64  scopeid0x20<link>

ether 00:0c:29:fe:64:f3 txqueuelen 1000  (Ethernet)

RX packets 1147  bytes 141324(138.0 KiB)

RX errors 0  dropped 0  overruns 0 frame 0

TX packets 659  bytes 102242 (99.8KiB)

TX errors 0  dropped 0 overruns0  carrier 0  collisions 0

lo:flags=73<UP,LOOPBACK,RUNNING>  mtu65536

inet 127.0.0.1  netmask 255.0.0.0

inet6 ::1  prefixlen 128  scopeid 0x10<host>

loop  txqueuelen 0  (Local Loopback)

RX packets 0  bytes 0 (0.0 B)

RX errors 0  dropped 0  overruns 0 frame 0

TX packets 0  bytes 0 (0.0 B)

TX errors 0  dropped 0 overruns0  carrier 0  collisions 0

[root@TomcatA ~]# cat/etc/yum.repos.d/hehe.repo

[cdrom-repo]

name=cdrom-repo

baseurl=file:///cdrom

gpgcheck=0

[aliyun-epel]

name=aliyun-epel

baseurl=http://mirrors.aliyun.com/epel/7/x86_64/

gpgcheck=0

[root@TomcatA ~]#

[root@TomcatA ~]# yum install -y tomcat

[root@TomcatA ~]# mkdir -pv/usr/share/tomcat/webapps/ROOT/WEB-INF

mkdir: created directory‘/usr/share/tomcat/webapps/ROOT’

mkdir: created directory‘/usr/share/tomcat/webapps/ROOT/WEB-INF’

[root@TomcatA ~]# vim/usr/share/tomcat/webapps/ROOT/index.jsp

[root@TomcatA ~]# cat/usr/share/tomcat/webapps/ROOT/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><fontcolor="red">TomcatA</font></h1>

                   <table                border="1">

                            <tr>

                                     <td>SessionID</td>

                            <%session.setAttribute("test.com","test.com"); %>

                                     <td><%=session.getId() %></td>

                            </tr>

                            <tr>

                                     <td>Createdon</td>

                                     <td><%=session.getCreationTime() %></td>

                            </tr>

                   </table>

         </body>

</html>

 

[root@TomcatA ~]# scp/usr/share/tomcat/webapps/ROOT/index.jsp 192.168.0.21:/usr/share/tomcat/webapps/ROOT/

The authenticity of host '192.168.0.21(192.168.0.21)' can't be established.

ECDSA key fingerprint isfc:7f:15:2b:2d:69:c9:c1:b0:79:7c:ce:ab:c0:0c:36.

Are you sure you want to continueconnecting (yes/no)? yes

Warning: Permanently added '192.168.0.21'(ECDSA) to the list of known hosts.

root@192.168.0.21's password:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/83dfb490719b0e5fcccb9b2b3c7714ac.html