nginx+tomcat负载均衡

环境:nginx-1.4.0、tomcat-7.0.39
需要扩展包:nginx_ajp_module-master.zip
通过ajp协议连接tomcat可以提高连接速度,减少资源消耗,提高并发响应。
重新编译nginx

cd nginx-1.3.16patch -p1 < /path/to/nginx_ajp_module-master/ajp.patch
./configure --prefix=/usr/local/nginx --with-pcre=pcre-8.32 --with-zlib=zlib-1.2.7 --with-http_ssl_module --with-openssl=openssl-1.0.1e --add-module=/path/to/nginx_ajp_module-master --add-module=/path/to/ngx_cache_purge-2.1 --user=www --group=wwwmake && make install

修改/usr/local/nginx/conf/nginx.conf

    upstream tomcat
        {
              server   192.168.11.132:8009 srun_id=jvm00;
              server   192.168.11.132:8109 srun_id=jvm01;
              server   192.168.11.132:8209 srun_id=jvm02;
              keepalive 10;
        }
    server
        {
                listen       80;
                server_name 192.168.11.132 localhost 127.0.0.1;
                location /
                        {
                                root   html;
                                index  index.html index.htm;
                                ajp_keep_conn  on;
                                ajp_pass  tomcat;
                        }
        }

修改tomcat配置文件sever.xml,对应不同主机jvmRoute值设置不同,AJP协议访问端口可以相同(实验机器3个服务器都在一台上面,设置端口不同)。

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /><Engine name="Catalina00" defaultHost="localhost" jvmRoute="jvm00">

=============================
通过nginx的nginx_http连接tomcat,修改/usr/local/nginx/conf/nginx.conf

    upstream tomcat
        {
              server   192.168.11.132:8080;
              server   192.168.11.132:8180;
              server   192.168.11.132:8280;
        }
    server
        {
                listen       80;
                server_name 192.168.11.132 localhost 127.0.0.1;
                location /
                        {
                                root   html;
                                index  index.html index.htm;
                                proxy_pass   tomcat;
                        }
        }

nginx_http模块采用的是server.xml当中HTTP/1.1协议定义的端口

结合memcached-session-manager,实现Tomcat high-availability clusters with memcached。


你可能感兴趣的:(tomcat,nginx,负载均衡,ajp,proxy_pass)