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

INFO: Replication memberadded:org.apache.catalina.tribes.membership.MemberImpl[tcp://{192, 168, 0,20}:4000,{192, 168, 0, 20},4000, alive=209565, securePort=-1, UDP Port=-1,id={6 -86 -55 -67 102 127 77 -57 -67 -67 -105 -20 -37 -55 76 -22 }, payload={},command={}, domain={}, ]

Sep 26, 2017 3:01:05 AMorg.apache.catalina.tribes.membership.McastServiceImpl waitForMembers

INFO: Done sleeping, membershipestablished, start level:4

Sep 26, 2017 3:01:05 AMorg.apache.catalina.tribes.membership.McastServiceImpl waitForMembers

INFO: Sleeping for 1000 milliseconds toestablish cluster membership, start level:8

Sep 26, 2017 3:01:05 AMorg.apache.catalina.tribes.io.BufferPool getBufferPool

INFO: Created a buffer pool with maxsize:104857600 bytes of type:org.apache.catalina.tribes.io.BufferPool15Impl

Sep 26, 2017 3:01:06 AM org.apache.catalina.tribes.membership.McastServiceImplwaitForMembers

INFO: Done sleeping, membershipestablished, start level:8

Sep 26, 2017 3:01:06 AMorg.apache.catalina.ha.deploy.FarmWarDeployer start

SEVERE: FarmWarDeployer can only work ashost cluster subelement!

Sep 26, 2017 3:01:06 AMorg.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory/var/lib/tomcat/webapps/ROOT

Sep 26, 2017 3:01:48 AMorg.apache.catalina.util.SessionIdGenerator createSecureRandom

INFO: Creation of SecureRandom instance forsession ID generation using [SHA1PRNG] took [41,566] milliseconds.

Sep 26, 2017 3:01:48 AMorg.apache.catalina.ha.session.DeltaManager startInternal

INFO: Register manager localhost# tocluster element Engine with name Catalina

Sep 26, 2017 3:01:48 AMorg.apache.catalina.ha.session.DeltaManager startInternal

INFO: Starting clustering manager atlocalhost#

Sep 26, 2017 3:01:48 AMorg.apache.catalina.ha.session.DeltaManager getAllClusterSessions

INFO: Manager [localhost#], requestingsession state from org.apache.catalina.tribes.membership.MemberImpl[tcp://{192,168, 0, 20}:4000,{192, 168, 0, 20},4000, alive=253179, securePort=-1, UDPPort=-1, id={6 -86 -55 -67 102 127 77 -57 -67 -67 -105 -20 -37 -55 76 -22 },payload={}, command={}, domain={}, ]. This operation will timeout if no sessionstate has been received within 60 seconds.

Sep 26, 2017 3:01:48 AMorg.apache.catalina.ha.session.DeltaManager waitForSendAllSessions

INFO: Manager [localhost#]; session statesend at 9/26/17 3:01 AM received in 114 ms.

Sep 26, 2017 3:01:48 AMorg.apache.catalina.startup.HostConfig deployDirectory

INFO: Deployment of web applicationdirectory /var/lib/tomcat/webapps/ROOT has finished in 42,286 ms

Sep 26, 2017 3:01:48 AMorg.apache.catalina.ha.session.JvmRouteBinderValve startInternal

INFO: JvmRouteBinderValve started

Sep 26, 2017 3:01:48 AMorg.apache.coyote.AbstractProtocol start

INFO: Starting ProtocolHandler["http-bio-8080"]

Sep 26, 2017 3:01:48 AMorg.apache.coyote.AbstractProtocol start

INFO: Starting ProtocolHandler["ajp-bio-8009"]

Sep 26, 2017 3:01:48 AMorg.apache.catalina.startup.Catalina start

INFO: Server startup in 44401 ms

集群session配置成功,使用浏览器访问反代服务器的80端口检验效果

wKioL1nKdbLAQFExAABl0_gwe1o888.png

wKiom1nKdfDz4ziiAABlfsimPXM165.png

至此,httpd反代tomcat集群,并且tomcat集群session复制都成功实现了

Nginx反代tomat集群配置

在这里我们为了节约资源就把nginx反代服务器配置到TomcatB服务器上

[root@TomcatB ~]# yum install -y nginx

[root@TomcatB ~]# cp/etc/nginx/nginx.conf{,.bak}

[root@TomcatB ~]# vim /etc/nginx/nginx.conf

Nginx默认配置文件需要修改以下几处

定义后端tomcat集群

1

2

3

4

 

upstreamtomcatservers {

       server 192.168.0.20:8080;

       server 192.168.0.21:8080;

}

 

注释IPV6监听

1

2

3

 

   server {

       listen       80 default_server;

       #listen       [::]:80default_server;

 

定义完全反代至后端tomcat集群

1

2

3

4

5

 

       location / {

           root  /usr/share/tomcat/wepapps/ROOT;

            index  index.jsp;

           proxy_pass http://tomcatservers;

       }

 

定义让后端tomcat集群获取客户端真实IP

1

2

3

 

       proxy_set_header Host $host;

       proxy_set_header X-Real-IP $remote_addr;

       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

 

[root@TomcatB ~]# nginx -t

nginx: the configuration file/etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conftest is successful

[root@TomcatB ~]#

httpd反代tomcat集群配置之后需要修改的地方

[root@TomcatA ~]# vim/etc/tomcat/server.xml

1

2

3

4

5

6

 

       <ValveclassName="org.apache.catalina.valves.AccessLogValve"directory="logs"

              prefix="localhost_access_log." suffix=".txt"

              pattern="%{X-Forwarded-For}i %l %u %t &quot;%r&quot; %s %b&quot;%{Referer}i&quot;

                      &quot;%{User-Agent}i&quot;"/>

               <!--pattern="%h %l %u %t&quot;%r&quot; %s %b &quot;%{Referer}i&quot;

                       &quot;%{User-Agent}i&quot;"/> -->

 

[root@TomcatA ~]# systemctl restart tomcat

[root@TomcatB ~]# vim/etc/tomcat/server.xml

1

2

3

4

5

6

 

       <ValveclassName="org.apache.catalina.valves.AccessLogValve"directory="logs"

              prefix="localhost_access_log." suffix=".txt"

              pattern="%{X-Forwarded-For}i %l %u %t &quot;%r&quot; %s %b&quot;%{Referer}i&quot;

                      &quot;%{User-Agent}i&quot;"/>

               <!--pattern="%h %l %u %t&quot;%r&quot; %s %b &quot;%{Referer}i&quot;

                       &quot;%{User-Agent}i&quot;"/> -->

 

[root@TomcatB ~]# systemctl restart tomcat

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

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