• CentOS系统下做nginx和tomcat负载均衡


    系统总是频繁更新,为了避免更新系统的时候领导看不到东西,打算用ngix做代理,后台部署两个tomcat做负载均衡,避免更新一台就无法使用系统的问题,这两天看了写资料,把几个关键点记录在这里以便备忘。

    环境:jdk,1.7,tomcat7,nginx1.5.8; 基于64位的windows配置

    第一步:更改tomcat三个端口,保证同一台机器上可以运行两个tomcat,更改的端口包括server port,两个connector port,xml配置参见下面,为了避免文件过大,删除了注释和无关的配置:

    [html] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. <?xml version='1.0' encoding='utf-8'?>  
    2.    
    3. <Server port="18005" shutdown="SHUTDOWN">   
    4.   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />  
    5.   <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->  
    6.   <Listener className="org.apache.catalina.core.JasperListener" />  
    7.   <!-- Prevent memory leaks due to use of particular java/javax APIs-->  
    8.   <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />  
    9.   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />  
    10.   <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />  
    11.   
    12.     
    13.   <GlobalNamingResources>  
    14.     
    15.     <Resource name="UserDatabase" auth="Container"  
    16.               type="org.apache.catalina.UserDatabase"  
    17.               description="User database that can be updated and saved"  
    18.               factory="org.apache.catalina.users.MemoryUserDatabaseFactory"  
    19.               pathname="conf/tomcat-users.xml" />  
    20.   </GlobalNamingResources>  
    21.   
    22.    
    23.   <Service name="Catalina">  
    24.   
    25.    
    26.     <Connector port="8082" protocol="HTTP/1.1"  
    27.                connectionTimeout="20000"  
    28.                redirectPort="8443" />  
    29.      
    30.     <Connector port="18009" protocol="AJP/1.3" redirectPort="8443" />  
    31.   
    32.    
    33.      。。。。。  
    34.   </Service>  
    35. </Server>  

    第二部,配置nginx(负载均衡):

    http节点下增加如下配置:

    [plain] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. upstream localhost {      
    2.         #针对不同ip的用户请求分配固定的tomcat响应其请求。      
    3.         ip_hash;  
    4.                 #配置tomcat服务器的ip:端口,处理请求权重  
    5.         server localhost:8080 weight=5;   
    6.         server localhost:8082 weight=5;  
    7.     }  

    http的节点下更改location/节点配置:

    [plain] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. location / {  
    2.            #root   html;  
    3.            #index  index.html index.htm;  
    4.         proxy_connect_timeout   3;  
    5.         proxy_send_timeout      30;  
    6.         proxy_read_timeout      30;  
    7.         proxy_pass http://localhost;  
    8.        }  

    配置完毕后,启动两个tomcat,再启动nginx,启动ngix方式:进入dos命令窗口,切换至nginx主目录,输入命令nginx.exe即可,

    停止nginx可以使用nginx.exe -s stop

    了解更详细的步骤参考下面两个链接:

    http://ari.iteye.com

    http://www.blogjava.net/tunaic/archive/2009/11/30/304212.html

  • 相关阅读:
    windows下编译及使用libevent
    安装和使用memcached
    BroadcastReceiver插件化解决方案
    Service插件化解决方案
    Activity插件化解决方案
    换肤-插件化
    资源的插件化
    startActivity进行Hook
    代理模式
    对反射的封装
  • 原文地址:https://www.cnblogs.com/fx2008/p/4110879.html
Copyright © 2020-2023  润新知