我是靠谱客的博主 多情黄豆,最近开发中收集的这篇文章主要介绍LAMT&LNMT,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Tomcat运行方式

1.standalone configure:tomcat作为独立的web服务器和jsp服务器

    request ----> web server(tomcat) ----> servlet container

66513265

2.进程间配置,在一台主机上,web由Apache或nginx提供,jsp服务有servlet提供

image

3.独立网络配置,把提供web服务的主机独立出来,一台主机提供web服务,一台主机提供jsp服务

image

web/Apache和后端的servlet通信有两种方式:

1.mod_jk :Apache/1.3, Apache/2.0;mod_jk常用的版本是jk,jk2.0反倒不建议使用,Apache 2.0以前不支持使用mod_proxy

2.mod_proxy :Apache/2.2+ , Apache 2.2以后要使用mod_jk需要编译安装

注:通信协议有 http(https)和ajp

mod_jk V.S. mod_proxy:
        负载均衡 : mod_proxy稍弱一点
        管理接口 : 都支持基于web页面的管理接口
        兼容性:
        配置 : mod_proxy较简单
        协议:mod_jk (ajp)通常不使用http, mod_proxy(http/https/ajp)

web/nginx和后端的servlet通信只能使用http协议

LAMT:
        apache(mod_jk, ajp) + tomcat(ajp )
        apache(mod_proxy, (http, https, ajp)) + tomcat(http, https, ajp)
LNMT:
        nginx + tomcat(http, https)


LNMT实现

48993359

安装nginx:

 
  
  1: rpm -ivh nginx-1.4.7-1.e16.ngx.x86_64.rpm
  2: vim /etc/nginx/nginx.conf
  3: location / {
  4:     #         root   html;
  5:     #         index  index.html index.htm;
  6:          proxy_pass http://192.168.21.1;  #只需加入这一句即可实现最简单的代理功能,不过我们这里不这样做
  7:          }

配置nginx实现反向代理tomcat和动静分离

 
  
  1: upstream tcser {   #添加后端tomcat主机,这是定义在http段的
  2:         server 192.168.21.1:8080;
  3:         server 192.168.21.2:8080;
  4:         }
  5: location / { 这是server段的
  6:             root   html;
  7:             index  index.jsp index.html index.htm;  增加一个index.jsp的默认主页
  8:         }   
  9:  location ~* .(jsp|do)$ {    #所有jsp和do结尾的页面都代理至后端服务器器
 10:         proxy_pass http://tcser;
 11:         }   


74366218

Apache反代-->mod_proxy,将所有网页内同都代理至后端,http协议

 
  
  1: vim /etc/httpd/conf.d/mod_proxy.conf
  2: ProxyVia on
  3: ProxyRequests off 
  4: ProxyPreserveHost on
  5: 
  6: ProxyPass / http://192.168.21.1/
  7: ProxyPa***everse / http://192.168.21.1/
  8: 
  9: <Location />
 10: Order Allow,Deny
 11: Allow from all
 12: </Location>

Apache反代-->mod_proxy,将所有网页内同都代理至后端,ajp协议

 
  
  1: ProxyVia on
  2: ProxyRequests off
  3: ProxyPreserveHost on
  4: 
  5: ProxyPass / ajp://192.168.21.1:8009/  #ajp监听的端口是8009
  6: ProxyPa***everse ajp/ http://192.168.21.1:8009/
  7: 
  8: <Location />
  9: Order Allow,Deny
 10: Allow from all
 11: </Location>

Apache反代实现负载均衡

前端Apache服务器:外网:172.16.21.1,内网:192.168.21.3

后端tomcat1:192.168.21.1,后端tomcat2:192.168.21.2

 
  
  1: vim /etc/httpd/conf.d/mod_proxy.conf
  2: ProxyVia on
  3: ProxyRequests off 
  4: ProxyPreserveHost on
  5: <Proxy balancer://lb>
  6: BalancerMember http://192.168.21.2 loadfactor=1
  7: BalancerMember http://192.168.21.1 loadfactor=1
  8: </Proxy>
  9: ProxyPass / balancer://lb/
 10: ProxyPa***everse / balancer://lb/
 11: <Location />
 12: Order Allow,Deny
 13: Allow from all
 14: </Location>

Apache反代实现负载均衡以及session绑定

 
  
  1: vim /etc/httpd/conf.d/mod_proxy.conf
  2: ProxyVia on
  3: ProxyRequests off 
  4: ProxyPreserveHost on
  5: <Proxy balancer://lb>
  6: BalancerMember http://192.168.21.2 loadfactor=1 route=TomcatB
  7: BalancerMember http://192.168.21.1 loadfactor=1 route=TomcatA
  8: </Proxy>
  9: ProxyPass / balancer://lb/ stickysession=JSESSIONID
 10: ProxyPa***everse / balancer://lb/
 11: <Location />
 12: Order Allow,Deny
 13: Allow from all
 14: </Location>
 15: --------后端服务器需添加----
 16: <Engine name="Catalina" defaultHost="localhost" jvmRoute="TomcatA"> 注意与上面的IP地址对应即可
 17: <Engine name="Catalina" defaultHost="localhost" jvmRoute="TomcatB">

Apache反代实现负载均衡以及session绑定添加管理器

 
  
  1: vim /etc/httpd/conf.d/mod_proxy.conf
  2: ProxyVia on
  3: ProxyRequests off
  4: ProxyPreserveHost on
  5: <Proxy balancer://lb>
  6: BalancerMember http://192.168.21.2 loadfactor=1
  7: BalancerMember http://192.168.21.1 loadfactor=1
  8: </Proxy>
  9: <Location /lbmanager>  定义管理web功能
 10: SetHandler balancer-manager
 11: </Location>
 12: Proxypass /lbmanager !  #这里表示/lbmanager不向后转发
 13: ProxyPass / balancer://lb/
 14: ProxyPa***everse / balancer://lb/
 15: <Location />
 16: Order Allow,Deny
 17: Allow from all
 18: </Location>

转载于:https://blog.51cto.com/lidefu/1409472

最后

以上就是多情黄豆为你收集整理的LAMT&LNMT的全部内容,希望文章能够帮你解决LAMT&LNMT所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部