Tomat集群 + Tomcat集群session共享 + Nginx负载 + Nginx静态资源代理

Nginx安装配置:

具体过程参考:http://blog.csdn.net/mr__fang/article/details/40342045

Nginx  nginx.conf

#user  nobody;
worker_processes  4;

error_log   logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    use epoll;
    worker_connections  65535;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  access;

    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;
	
    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;

    #keepalive_timeout  0;
    keepalive_timeout  60;
	
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

    ##cache##
    proxy_connect_timeout 5;
    proxy_read_timeout 60;
    proxy_send_timeout 5;
    proxy_buffer_size 16k;
    proxy_buffers 4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;
    proxy_temp_path /home/temp_dir;
    proxy_cache_path /home/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;
    ##end cache##

    ##gzip##
    gzip  on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types  text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    ##end gzip##

    ##Tomcat Cluster##
    upstream tomcat_proxy{
        server 192.168.204.81:18080;
        server 192.168.204.81:28080;
        server 192.168.204.81:38080;
    }
    ##Tomcat Cluster##

    server {
        listen       80;
        server_name  fang.com www.fang.com;
	index aa.html;
	root /ss;

        location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
            proxy_pass http://tomcat_proxy;
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_cache cache_one;
            proxy_cache_valid 200 302 1h;
            proxy_cache_valid 301 1d;
            proxy_cache_valid any 1m;
            expires    7d;
        }
		
        #所有jsp、do的动态请求都交给后面的tomcat处理
        location ~ (\.jsp)|(\.do)$ {
            #tomcat地址
            proxy_pass http://tomcat_proxy;
            proxy_redirect off;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            client_max_body_size 10m;
            client_body_buffer_size 128k;
            proxy_connect_timeout 90;
            proxy_send_timeout 90;
            proxy_read_timeout 90;
            proxy_buffer_size 4k;
            proxy_buffers 4 32k;
            proxy_busy_buffers_size 64k;
            proxy_temp_file_write_size 64k;
        }

        location /nginxstatus {
            stub_status on;
            access_log off;
        }
    }
}


Tomcat 配置文件:

参考:http://blog.csdn.net/mr__fang/article/details/40397449

Tomcat集群修改:

<Server port="18005"

<Connector port="18080"

<Connector port="18009" protocol="AJP/1.3"


server.xml 中Engine配置(集群中所有Tomcat配置一样):

<Engine defaultHost="www.fang.com" name="Catalina">

	<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="228.0.0.4"
					port="45564"
					frequency="500"
					dropTime="3000"/>
		<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
				  address="auto"
				  port="14000"
				  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"/>
	  </Channel>
	  <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>
	  <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
	  <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
	  <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
	</Cluster>

      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      </Realm>

      <Host name="www.fang.com" appBase="webapps" autoDeploy="true" unpackWARs="true">
        <Context path="" docBase="fang" reloadable="true" source="org.eclipse.jst.jee.server:fang"/>

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/>

      </Host>
    </Engine>

web.xml配置:

主要增加 <distributable/>  标签。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
	id="WebApp_ID" version="3.0">
	<display-name>fang</display-name>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	
	<distributable/>
</web-app>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值