zzl001 发表于 2018-12-4 08:55:07

负载均衡基于Cookie OpenRest+tomcat+php+memcache+Jsp

  一.OpenResty简介
  OpenResty是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。
  OpenResty通过汇聚各种设计精良的 Nginx 模块(主要由 OpenResty 团队自主开发),从而将 Nginx 有效地变成一个强大的通用 Web 应用平台。这样,Web 开发人员和系统工程师可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,快速构造出足以胜任 10K 乃至 1000K 以上单机并发连接的高性能 Web 应用系统。
  OpenResty的目标是让你的Web服务直接跑在 Nginx 服务内部,充分利用 Nginx 的非阻塞 I/O 模型,不仅仅对 HTTP 客户端请求,甚至于对远程后端诸如 MySQL、PostgreSQL、Memcached 以及 Redis 等都进行一致的高性能响应。
  二.OpenResty的安装配置
  1.配置 编译 安装

https://s1.运维网.com/wyfs02/M00/A6/42/wKioL1nLkcmgGYzwAACnrPWliqE645.png
https://s3.运维网.com/wyfs02/M01/07/91/wKiom1nLkgiwdVh1AAB8A8eI6iM873.png
https://s1.运维网.com/wyfs02/M01/A6/42/wKioL1nLkcmjDR4TAABkIU2xL24703.png
https://s1.运维网.com/wyfs02/M01/07/91/wKiom1nLkgiTHYgtAABNf4ldmGs322.png
  2.配置openresty
  启动memcache服务
https://s2.运维网.com/wyfs02/M02/A6/42/wKioL1nLkjvwX50tAABORhBP-eo515.png
  检查语法,启动nginx

https://s2.运维网.com/wyfs02/M01/A6/42/wKioL1nLkjvjQ6KmAACGUQp2EZY028.png
  启动fastcgi服务

https://s2.运维网.com/wyfs02/M00/A6/42/wKioL1nLkjyyJUnxAAA3cujmuuM877.png
https://s1.运维网.com/wyfs02/M00/07/91/wKiom1nLknuzZFokAAAvwGEWvf0185.png
  配置openresty的nginx
https://s2.运维网.com/wyfs02/M00/07/91/wKiom1nLknrR9qaJAABDHsSSFRw525.png
https://s2.运维网.com/wyfs02/M02/A6/42/wKioL1nLkjvQssGoAAASbl7AGog062.png
https://s2.运维网.com/wyfs02/M01/07/91/wKiom1nLknqjy8WXAAA8dTTkyJY303.png
  添加内核最大链接数
https://s1.运维网.com/wyfs02/M01/07/91/wKiom1nLknvRlaZSAAAOpSORK3Q460.png
https://s1.运维网.com/wyfs02/M00/A6/42/wKioL1nLkjyAgmyVAAAdD1Itic4694.png
  配置php默认发布文件

https://s1.运维网.com/wyfs02/M01/A6/42/wKioL1nLkjyzvtd4AAAMmrg_sY0311.png
https://s1.运维网.com/wyfs02/M02/07/91/wKiom1nLknuwh5gQAAAfEybRN5o451.png
  显示正常

https://s5.运维网.com/wyfs02/M00/07/91/wKiom1nLmUHiKHqNAAEDKaOnvH8645.png
  
  3.在nginx上添加memcache
  vim nginx.conf

https://s2.运维网.com/wyfs02/M01/A6/43/wKioL1nLmQHhIKeHAAAb9278J7o982.png
https://s2.运维网.com/wyfs02/M02/07/91/wKiom1nLmUGTL0yWAAC1VcU4RTc991.png
https://s2.运维网.com/wyfs02/M00/A6/43/wKioL1nLmQOgbR_QAADANDQgf90704.png
  4.测试example.php缓存文件memcache

https://s5.运维网.com/wyfs02/M02/A6/43/wKioL1nLmhXTbhRdAAAVLj-yS_E467.png
https://s2.运维网.com/wyfs02/M01/07/91/wKiom1nLmULTY8p5AABMFHOC_z8037.png
https://s1.运维网.com/wyfs02/M00/07/91/wKiom1nLmlODdVsLAACIYvuDN9A062.png
  每秒处理量为6787次

  5.将memcache缓存读取取消测试

https://s5.运维网.com/wyfs02/M00/A6/43/wKioL1nLmhWTlwQoAABf9K-KOp0740.png
  访问index.php页面,此页面不能进行mencache缓存

https://s5.运维网.com/wyfs02/M02/A6/43/wKioL1nLmQLzENCQAABQi_v454U677.png
https://s5.运维网.com/wyfs02/M02/A6/43/wKioL1nLmQKSldr8AACF5sIOgKw416.png
  每秒处理量为3360次

  
三.Tomcat的安装配置,jsp页面的访问
  
  1.添加系统环境变量

https://s5.运维网.com/wyfs02/M01/A6/43/wKioL1nLnRHBZmjtAABftT2gJpM883.png
https://s5.运维网.com/wyfs02/M01/07/91/wKiom1nLnVCTTMB5AAA8DBXZeyk089.png
  2.安装Java

https://s5.运维网.com/wyfs02/M02/07/91/wKiom1nLnVDja4sdAABepI-himM431.png
  3.安装tomcat

https://s5.运维网.com/wyfs02/M02/A6/43/wKioL1nLnRHg2HD1AAEv6S_tLe8241.png
  4.写一段java的测试代码

https://s5.运维网.com/wyfs02/M01/A6/43/wKioL1nLnRKgC9a3AAAbgOCM22c575.png
https://s5.运维网.com/wyfs02/M00/07/91/wKiom1nLnVCA5Z4uAAArM0IN0l4962.png
  5.启动tomcat服务

https://s5.运维网.com/wyfs02/M01/A6/43/wKioL1nLnRGTj2tIAACe3gbNLo8555.png
https://s5.运维网.com/wyfs02/M00/A6/43/wKioL1nLnRKAEcVbAACS2hPo4kY984.png
  6.客户机测试8080端口的tomcat

https://s5.运维网.com/wyfs02/M01/07/91/wKiom1nLnVGjd6XNAAHJJmONxh4493.png
  7.修改jsp测试访问页面

https://s5.运维网.com/wyfs02/M02/07/91/wKiom1nLnVHyg15wAAB9mz3saW0881.png
https://s5.运维网.com/wyfs02/M02/A6/43/wKioL1nLnRLDILJ9AAATcG1hcpU982.png
https://s5.运维网.com/wyfs02/M02/A6/43/wKioL1nLnROCD0OAAAA1Admn8cc811.png
  四.设置Tomcat居于cookie的负载均衡
  1.将server2与server3配置相同的tomcat服务

  将server2的jdk传给server3

https://s4.运维网.com/wyfs02/M01/07/91/wKiom1nLn4TzkdbmAACYbLqg4-w214.png
  2.在server3配置环境变量,两边服务开通

https://s3.运维网.com/wyfs02/M00/A6/43/wKioL1nLn0bgDMmXAAA6oy-Uej4970.png
https://s3.运维网.com/wyfs02/M02/07/92/wKiom1nLn4WSqSy8AAD29nA1OPw013.png
https://s3.运维网.com/wyfs02/M02/A6/43/wKioL1nLn0aTSlbYAACaTPscxtc280.png
  3.配置测试jsp访问页面

  
  
  Cluster App Test
  
  Server Info:
  
   0) {
  String dataValue = request.getParameter("dataValue");
  session.setAttribute(dataName, dataValue);
  }
  out.print("Session list");
  Enumeration e = session.getAttributeNames();
  while (e.hasMoreElements()) {
  String name = (String)e.nextElement();
  String value = session.getAttribute(name).toString();
  out.println( name + " = " + value+"");
  System.out.println( name + " = " + value);
  }
  %>
  
  name:
  
  key:
  
  
  
  
  
  

https://s3.运维网.com/wyfs02/M02/07/92/wKiom1nLn4WCY6z2AAEtxOWaLsg872.png
  将页面传给server3

https://s3.运维网.com/wyfs02/M00/07/92/wKiom1nLn4WBqYNbAABLSCN8yC0385.png
  4.重新安装支持sticky的nginx版本,由于openresty不支持sticky
  停止原先的nginx服务

https://s3.运维网.com/wyfs02/M00/A6/43/wKioL1nLn0fzo0ooAAAY5tCXWgM413.png
  安装nginx1.1版本,安装到/opt目录下

https://s2.运维网.com/wyfs02/M01/A6/43/wKioL1nLn0fhR1_LAADFD7KVt7I563.png
https://s1.运维网.com/wyfs02/M00/07/92/wKiom1nLn4bRwo50AABDKvJHSeI580.png
  配置主配置文件,注意sticky
https://s2.运维网.com/wyfs02/M01/07/92/wKiom1nLn4eRX2TXAAAn-1yoUC0968.png
  

https://s2.运维网.com/wyfs02/M02/A6/43/wKioL1nLn0fjUcZiAAApuhuqKBY279.png
https://s4.运维网.com/wyfs02/M01/07/92/wKiom1nLoj-zEqZZAABB9DWzz74007.png
  
  5.客户机测试,输入172.25.29.1/test.jsp


https://s4.运维网.com/wyfs02/M01/07/92/wKiom1nLoj6TQuvDAABzWJJxFM8749.png
https://s4.运维网.com/wyfs02/M01/A6/43/wKioL1nLof-B7_2DAAB0ZXDbhsk165.png
  由以上看出,开启sticky同一会话后端没有负载均衡,会话没有断开,但是server3上的tomcat出现问题,server2 上的tomcat接管,但当前会话结束,之前的会话消失,需要使用memcache
  取消sticky,提交会话负载均衡,在server2 和server3 之间变动,无法保存会话信息。
https://s4.运维网.com/wyfs02/M02/07/92/wKiom1nLoj6Agls2AAApnXzIHV0775.png
https://s4.运维网.com/wyfs02/M02/A6/43/wKioL1nLof_DeMZEAABqDMjK1aw946.png
https://s4.运维网.com/wyfs02/M02/A6/43/wKioL1nLof_xctNRAAB2IeuQs3U698.png
  五.处理Tomcat负载均衡sticky会话结束
  1.在server2和server3上安装memcache-session包

https://s2.运维网.com/wyfs02/M01/07/92/wKiom1nLpRuBcSD7AABlJcp99j4748.png
https://s1.运维网.com/wyfs02/M01/A6/44/wKioL1nLpNzj9GVcAAAV9WfKlC4325.png
  2.sevrer2上安装memcache,设置n1,并启动服务
https://s2.运维网.com/wyfs02/M02/A6/44/wKioL1nLpN3yg3GuAAAoSPR3fJ8107.png
https://s2.运维网.com/wyfs02/M01/A6/44/wKioL1nLpN2QyzETAACUcFV-B-8773.png
https://s2.运维网.com/wyfs02/M02/07/92/wKiom1nLpRzj60IkAABuMu3njeI459.png
https://s2.运维网.com/wyfs02/M00/A6/44/wKioL1nLpN6ROud_AADhTJm9Lx4111.png
  
  3.sevrer3上安装memcache,设置n2,并启动服务
https://s2.运维网.com/wyfs02/M00/07/92/wKiom1nLpRyjpxa9AAApaJyHcTE169.png
https://s2.运维网.com/wyfs02/M00/07/92/wKiom1nLpRzzFpsUAABhAl14lQs248.png
https://s3.运维网.com/wyfs02/M02/A6/44/wKioL1nLpN7gMXxSAADKJcSsD9g341.png
  4.客户机测试

https://s3.运维网.com/wyfs02/M01/07/92/wKiom1nLpR2zFlY7AAB7iBHqg08359.png
  当会话正在进行时,server3 tomcat停掉

https://s3.运维网.com/wyfs02/M01/07/92/wKiom1nLpR2gvNviAABZuqRTTTE528.png
  server2 tomcat接管,但读取的memcache还是在原先的n1上,会话没有中断

https://s3.运维网.com/wyfs02/M01/A6/44/wKioL1nLpN6DZSeNAAB-uJWTNOU170.png



页: [1]
查看完整版本: 负载均衡基于Cookie OpenRest+tomcat+php+memcache+Jsp