zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    STL堆算法性能分析与优化方法(GCC4.4.2 stl_heap.h源代码分析与改进方案)
    POJ 1631 Bridging Singnals
    一个用于读unicode文本的迭代器(iterator)
    常用文本压缩算法及实现(To be finshed!)
    volatile语义及线程安全singleton模式探讨
    C++实现的huffman与canonical huffman的压缩解压缩系统,支持基于单词的压缩解压缩
    linux环境下 C++性能测试工具 gprof + kprof + gprof2dot
    多线程统计多个文件的单词数目C++0x多线程使用示例
    python嵌入C++ boost.python如何在C++中调用含有不定长参数tuple变量和关键字参数dict变量的函数
    boost.python入门教程 python 嵌入c++
  • 原文地址:https://www.cnblogs.com/fx2008/p/4110879.html
Copyright © 2011-2022 走看看