博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tomcat lb cluster
阅读量:6821 次
发布时间:2019-06-26

本文共 10469 字,大约阅读时间需要 34 分钟。

tomcat lb cluster

session会话保持

source ip
cookie

nginx proxy>>tomcat1>>tomcat2

nginx

vim /etc/hostsweb1.test.com 192.168.100.101 web2.test.com 192.168.100.102vim /etc/nginx/nginx.confupstream webs {        ip_hash;        server web1.test.com:8080;        server web2.test.com:8080;}server {...        location ~* \.(jsp|do)$ {                proxy_pass http://webs;        }}nginx -t nginx -s reload

tomcat1

catalina.sh configtestcatalina.sh stopcatalina.sh start

tomcat2

catalina.sh configtestcatalina.sh stopcatalina.sh start

客户端测试

firefox http://192.168.200.102/index.jsp

apache proxy >>tomcat1>>tomcat2

(1)apache:

mod_proxy
mod_proxy_http
mod_proxy_balancer
tomcat:
http connector
(2)apache:
mod_proxy
mod_proxy_ajp
mod_proxy_balancer
tomcat:
ajp connector
(3)apache:
mod_jk
tomcat:
ajp connector

tomcat session绑定+负载均衡

httpd

balancerMember http://192.168.100.101:8080 loadfactor=10 route=TomcatA balancerMember http://192.168.100.102:8080 loadfactor=10 route=TomcatB
ServerName www.test.com ProxyVia On ProxyRequests Off ProxyPreserveHost On
Require all granted
ProxyPass /status ! ProxyPass / balancer://lbcluster1/ ProxyPassReverse / balancer://lbcluster1/
Require all granted

tomcata

vim index.jsp<%@ page language="java" %><%@ page import="java.util.*" %>
JSP Test Page

TomcatA.test.com

<% session.setAttribute("test.com","test.com"); %>
Session ID <%=session.getId() %>
Created on <%=session.getCreationTime() %>

tomcatb

vim index.jsp<%@ page language="java" %><%@ page import="java.util.*" %>
JSP Test Page

TomcatB.test.com

<% session.setAttribute("test.com","test.com"); %>
Session ID <%=session.getId() %>
Created on <%=session.getCreationTime() %>

client

firefox http://192.168.100.101
启用balancer模块内置的manager
vim vhosts.confHeader add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
balancerMember http://192.168.100.101:8080 loadfactor=10 route=TomcatA balancerMember http://192.168.100.102:8080 loadfactor=10 route=TomcatB ProxySet stickysession=ROUTEID
ServerName web1.test.com ProxyVia On ProxyRequests Off ProxyPreserveHost On
Require all granted
ProxyPass /status ! ProxyPass / balancer://lbcluster1/ ProxyPassReverse / balancer://lbcluster1/
Require all granted
SetHandler balancer-managerProxypass !Require all granted#Ordey Deny,Allow#Allow from all
firefox http://192.168.100.101/balancer-manager

http装载模块 tomcat-connectors

mod_jk 额外编译安装

yum install httpd-devel gcc glibc-devel -yyum groupinstall "Development Tools"which apxstar xf tomcat-connectors-1.2.46-src.tar.gzcd tomcat-connectors-1.2.46-src/native./configure --with-apxs=/usr/bin/apxsmake -j4 && make installvim  /etc/httpd/conf.d/mod_jk.conf LoadModule jk_module modules/mod_jk.soJkWorkersFile /etc/httpd/conf.d/workers.propertiesJkLogFile logs/mod_jk.log JkLogLevel debug JkMount /* TomcatA JkMount /status/ stat1vim  /etc/httpd/conf.d/workers.properties worker.list=TomcatA,stat1worker.TomcatA.port=8009worker.TomcatA.host=192.168.100.101worker.TomcatA.type=ajp13worker.TomcatA.lbfactor=1worker.stat1.type=statussystemctl restart httpdfirefox http://192.168.100.101/index.jspfirefox http://192.168.100.101/status/
负载均衡+session绑定

http

[root@localhost conf.d]# cat mod_jk.conf LoadModule jk_module modules/mod_jk.soJkWorkersFile /etc/httpd/conf.d/workers.propertiesJkLogFile logs/mod_jk.log JkLogLevel debug JkMount /* lbcluster1 JkMount /status/ stat1[root@localhost conf.d]# cat workers.properties worker.list=lbcluster1,stat1worker.TomcatA.port=8009worker.TomcatA.host=192.168.100.101worker.TomcatA.type=ajp13worker.TomcatA.lbfactor=1worker.TomcatB.port=8009worker.TomcatB.host=192.168.100.102worker.TomcatB.type=ajp13worker.TomcatB.lbfactor=1worker.lbcluster1.type=lbworker.lbcluster1.sticky_session=1#worker.lbcluster1.sticky_session=0  #0表示不绑定session,1表示开启worker.lbcluster1.balance_workers=TomcatA,TomcatBworker.stat1.type=status

session cluster

示例一

1、各节点配置使用deltamaanager

2、为需要使用的session cluster的webapps开启session disribution的功能
WEB-INF/web.xml

tomcata

vim server.xml
cp /usr/local/tomcat/conf/web.xml /data/webapps/ROOT/WEB-INF/vim web.xml
catalina.sh configtestcatalina.sh stopcatalina.sh starttail -100 /usr/local/tomcat/logs/catalina.out

tomcatb

vim server.xml
cp /usr/local/tomcat/conf/web.xml /data/webapps/ROOT/WEB-INF/vim web.xml
catalina.sh configtestcatalina.sh stopcatalina.sh starttail -100 /usr/local/tomcat/logs/catalina.out

http

vim vhosts.conf#Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
balancerMember http://192.168.100.101:8080 loadfactor=10 route=TomcatA balancerMember http://192.168.100.102:8080 loadfactor=10 route=TomcatB# ProxySet stickysession=ROUTEID
ServerName www.test.com ProxyVia On ProxyRequests Off ProxyPreserveHost On
Require all granted
ProxyPass /status ! ProxyPass / balancer://lbcluster1/ ProxyPassReverse / balancer://lbcluster1/
Require all granted
SetHandler balancer-managerProxypass !Require all granted#Ordey Deny,Allow#Allow from all

client

firefox http://192.168.100.101

示例2

装载模块

http

cat mod_jk.conf LoadModule jk_module modules/mod_jk.soJkWorkersFile /etc/httpd/conf.d/workers.propertiesJkLogFile logs/mod_jk.log JkLogLevel debug JkMount /* lbcluster1 JkMount /status/ stat1cat workers.properties worker.list=lbcluster1,stat1worker.TomcatA.port=8009worker.TomcatA.host=192.168.100.101worker.TomcatA.type=ajp13worker.TomcatA.lbfactor=1worker.TomcatB.port=8009worker.TomcatB.host=192.168.100.102worker.TomcatB.type=ajp13worker.TomcatB.lbfactor=1worker.lbcluster1.type=lb#worker.lbcluster1.sticky_session=1worker.lbcluster1.sticky_session=0worker.lbcluster1.balance_workers=TomcatA,TomcatBworker.stat1.type=status

示例3

nginx

upstream webs {        #ip_hash;        server web1.test.com:8080;        server web2.test.com:8080;}        location / {        }        location ~* \.(jsp|do)$ {                proxy_pass http://webs;        }

转载于:https://www.cnblogs.com/fina/p/10213723.html

你可能感兴趣的文章
freemarker 数字格式化
查看>>
解决SELinux对网站目录权限控制的不当的问题
查看>>
2016年4月6日作业
查看>>
RxJava 学习笔记<十> 译 Leaving the monad
查看>>
Mariadb galera cluster 安装配置
查看>>
川模型 一款新的测试模型的提出与研究
查看>>
如何快速开发网站?
查看>>
手动创建并自动挂载swap分区
查看>>
cloudera search1.0.0环境搭建(1):搭建solrcloud
查看>>
bitnami-testlink 相关配置
查看>>
SpringBoot整合Quartz(升级版)
查看>>
导入sql语句 汉字编码不一样报异常
查看>>
html文本自动换行
查看>>
Exchange常见问题大全
查看>>
安装Sublime Text 2插件的方法
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
Kubernetes NFS存储服务的误报
查看>>
meta设置
查看>>
sed 行编辑器知识汇总
查看>>