Tengine (淘宝nginx ) + tomcat 安装整合 后篇+ 高可用和负载均衡

来源:互联网 发布:rio网络用语什么意思 编辑:程序博客网 时间:2024/05/22 08:12

1. Nginx 配置

 /app/nginx/sbin/nginx -V
Tengine version: Tengine/1.4.6 (nginx/1.2.9)
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
TLS SNI support enabled
configure arguments: --user=nginx --group=app --prefix=/app/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_concat_module --with-http_upstream_check_module --with-http_sub_module --with-http_realip_module

 

vim /app/nginx/conf/nginx.conf

    upstream app_tomcat {
        consistent_hash $remote_addr;
        session_sticky;

        server 172.16.80.1:8000 id=1001 weight=1;
        server 172.16.80.2:8000 id=1002 weight=1;

        check interval=1000 rise=2 fall=3 timeout=1000 type=http port=8000;
        check_http_send "GET / HTTP/1.0\r\n\r\n";
        check_http_expect_alive http_2xx http_3xx;
    }

vim /app/nginx/conf.d/app.test.com

    server {
        listen       80;
        server_name  app.test.com;

 #影藏.svn 代码文件

        location ~ ^(.*)\/\.svn\/{
            deny all;
         }

        location / {
            concat on;
            root /app/web/app.test.com/ROOT;
            index  index.html index.htm index.jsp;
        }


        location /status {
            stub_status on;
            access_log off;
            allow 172.16.80.0/24;
        }

        location ~ (\.jsp)|(\.do)|(/url/)|(/membercard/)|(\.action)$   {
             session_sticky_hide_cookie upstream=app_tomcat;
             proxy_pass http://app_tomcat;
             proxy_set_header   Host                app.test.com;
             proxy_set_header   X-Real-IP        $remote_addr;
             proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

 

2.Tomcat 配置

2.1 第一台Tomcat

vim /app/tomcat/conf/server.xml 

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">

      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
          <Manager className="org.apache.catalina.ha.session.DeltaManager"
            expireSessionsOnShutdown="false" notifyListenersOnReplication="true"/>
          <Channel className="org.apache.catalina.tribes.group.GroupChannel">
            <Membership className="org.apache.catalina.tribes.membership.McastService"
              address="224.0.0.4"
              port="45365"
              frequency="500"
              dropTime="3000" />
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
              address="172.16.80.1"
              port="4002"
              autoBind="100"
              selectorTimeout="5000"
              maxThreads="6" />
            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
                <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
            </Sender>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
          </Channel>
          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter="" />
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
          <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
            tempDir="/tmp/war-temp/"
            deployDir="/tmp/war-deploy/"
            watchDir="/tmp/war-listen/"
            watchEnabled="false" />
          <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
      </Cluster>

      <Host name="app.test.com" appBase="webapps">
        <Context path="" docBase="/app/web/app.test.com/ROOT" debug="0" reloadable="true" distributable="true" useHttpOnly="true" sessionCookiePath="/" sessionCookieDomain=".test.com" crossContext="true" />   主域名和二级域名之间的session复制
      </Host>

第二台Tomcat

vim /app/tomcat/conf/server.xml

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm2">

      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
          <Manager className="org.apache.catalina.ha.session.DeltaManager"
            expireSessionsOnShutdown="false" notifyListenersOnReplication="true"/>
          <Channel className="org.apache.catalina.tribes.group.GroupChannel">
            <Membership className="org.apache.catalina.tribes.membership.McastService"
              address="224.0.0.4"
              port="45365"
              frequency="500"
              dropTime="3000" />
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
              address="172.16.80.2"
              port="4002"
              autoBind="100"
              selectorTimeout="5000"
              maxThreads="6" />
            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
                <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
            </Sender>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
          </Channel>
          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter="" />
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
          <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
            tempDir="/tmp/war-temp/"
            deployDir="/tmp/war-deploy/"
            watchDir="/tmp/war-listen/"
            watchEnabled="false" />
          <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
      </Cluster>

      <Host name="app.test.com" appBase="webapps">
        <Context path="" docBase="/app/web/app.test.com/ROOT" debug="0" reloadable="true" distributable="true" useHttpOnly="true" sessionCookiePath="/" sessionCookieDomain=".test.com" crossContext="true" />

      </Host>

原创粉丝点击