Tomcat服务器搭建实验(3)

Tomcat服务器搭建实验

2)nginx会话绑定 在B和C上操作同上 在A上配置 vim /etc/nginx/nginx.conf upstream tomcatsrv { server 192.168.213.251:8080 ; server 192.168.213.254:8080 ; hash $request_uri consistent; } server { listen 80 default_server; listen [::]:80 default_server; index index.jsp ; root /usr/share/tomcat/webapps; location / { proxy_pass http://tomcatsrv ; } } service nginx restart http://172.18.213.253/app 发现只能调度至第一次访问的后端服务器,实现会话绑定。 6.两个tomcat服务器保存有相同的会话

环境
A:nginx和httpd:192.168.213.253
B:tomcat:192.168.213.251
C:tomcat:192.168.213.254

1)在B和C上的设置 访问tomcat的官方文档 :8080/docs/cluster-howto.html ,Document---->Clustering 将官方文档中的如下内容复制到tomcat配置文件的<engine><host>中,此实验放到Engine中 vim /etc/tomcat/server.xml <Engine name="Catalina" defaultHost="localhost"> <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.74.74.74" port="45564" frequency="500" ##表示每0.5s发送一次心跳信息告诉其他成员自己还活着 dropTime="3000"/> ##表示3s没有发送信息就证明坏了 <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="172.18.213.251" ##另外一台主机修改为172.18.213.254 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> cp /etc/tomcat/web.xml /usr/share/tomcat/webapps/app/WEB-INF/ cd /usr/share/tomcat/webapps/app/WEB-INF/ vim web.xml 在此文件内部没有注释的地方加如下内容 <distributable/> ##注意一定要在这个文件的内部,就在<web.app下加上就可 systemctl restart tomcat 注意: CentOS 7上的tomcat自带的文档中的配置示例有语法错误;没有加最后的/ <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/> <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/> 2)在A的设置 vim /etc/httpd/conf.d/tomcat.conf <proxy balancer://tomcatsrvs> BalancerMember http://172.18.213.251:8080 BalancerMember http://172.18.213.254:8080 ProxySet lbmethod=byrequests </Proxy> namevirtualhost *:80 <VirtualHost *:80> documentroot /app <directory /app> Require all granted </directory> ProxyVia On ProxyRequests Off ProxyPass / balancer://tomcatsrvs/ ProxyPassReverse / balancer://tomcatsrvs/ </VirtualHost> service httpd reload http://172.18.213.253/app/

Tomcat服务器搭建实验

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

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