Nginx1.9+Tomcat8+Spring4+Shiro-redis2.4.2.1搭建HA Cluster

5 篇文章 0 订阅
5 篇文章 0 订阅

nginx配置(nginx.conf)

#服务进程数量,一般等于CPU数量
worker_processes  1;

error_log  /save/savefe-nginx-logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
	#epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能.Linux建议使用epoll,FreeBSD建议使用kqueue.
    use epoll;
	#一个worker_processe允许的最近并发连接数量
    worker_connections  1024;
}


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

    #log_format  main  '$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  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
	
	upstream savefe {     

	   server 10.32.8.33:8080;     

	   server 10.32.8.34:8080;

	}
	
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
			proxy_pass http://savefe/;
			
			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;  
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

 tomcat配置(没啥配置,就配了个JVM,catalina.sh)

 

JAVA_OPTS="-Xms1g -Xmx1g -Xmn512m -XX:PermSize=256m -XX:MaxPermSize=512m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0 -XX:CMSInitiatingOccupancyFraction=70"

 

shiro-redis配置(基于spring)

 

1、maven

<dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-spring</artifactId>
    <version>1.2.4</version>
</dependency>

<dependency>
    <groupId>org.crazycake</groupId>
    <artifactId>shiro-redis</artifactId>
    <version>2.4.2.1-RELEASE</version>
</dependency>

 2、beans-shiro-redis.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
			http://www.springframework.org/schema/beans/spring-beans.xsd 
			http://www.springframework.org/schema/mvc 
			http://www.springframework.org/schema/mvc/spring-mvc.xsd 
			http://www.springframework.org/schema/context 
			http://www.springframework.org/schema/context/spring-context.xsd 
			http://www.springframework.org/schema/aop 
			http://www.springframework.org/schema/aop/spring-aop.xsd 
			http://www.springframework.org/schema/tx 
			http://www.springframework.org/schema/tx/spring-tx.xsd ">

	<!--shiro的配置,关键两点,配置SecurityManager和依赖的RealM -->
	<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
		<property name="securityManager" ref="securityManager" />
		<property name="loginUrl" value="/loginIndex" />
		<property name="successUrl" value="/" />
		<property name="unauthorizedUrl" value="/unauthorized" />
		<property name="filters">
			<map>
				<entry key="anno" value-ref="anno" />
				<entry key="authc" value-ref="authc" />
			</map>
		</property>
		<property name="filterChainDefinitionMap">
			<map>
				<entry key="anon" value="anon" />
				<entry key="authc" value="authc" />
			</map>
		</property>
		<property name="filterChainDefinitions">
			<value>
				/common/**=anon
				/login=anon
				/logout=logout
				/**=authc
			</value>
		</property>
	</bean>
	<bean id="authc"
		class="org.apache.shiro.web.filter.authc.FormAuthenticationFilter">
		<property name="usernameParam" value="uname"></property>
		<property name="passwordParam" value="upass"></property>
	</bean>
	<bean id="logout" class="org.apache.shiro.web.filter.authc.LogoutFilter">
        <property name="redirectUrl" value="/loginIndex" />
    </bean> 
	<bean id="anno" class="org.apache.shiro.web.filter.authc.AnonymousFilter" />
	<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
		<property name="realm" ref="loginRealm" />
		<property name="sessionMode" value="http"></property>  
		<!-- cacheManager -->
		<property name="cacheManager" ref="cacheManager" />  
		<!-- sessionManager -->  
        <property name="sessionManager" ref="sessionManager"></property>  
	</bean>
	
	<!-- 登录校验器 -->
	<bean id="loginRealm" class="com.spl.savefe.component.LoginRealm" />
	
    <!-- session管理器 -->  
    <bean id="sessionManager"  
        class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">  
        <!-- 设置全局会话超时时间,默认30分钟(1800000) -->  
        <property name="globalSessionTimeout" value="1800000" />  
        <!-- 是否在会话过期后会调用SessionDAO的delete方法删除会话 默认true -->  
        <property name="deleteInvalidSessions" value="true" />  
        <!-- 会话验证器调度时间 -->  
        <property name="sessionValidationInterval" value="1800000" />  
        <!-- session存储的实现 -->  
        <property name="sessionDAO" ref="redisSessionDAO" /> 
        <!-- sessionIdCookie的实现,用于重写覆盖容器默认的JSESSIONID -->  
        <property name="sessionIdCookie" ref="sharesession" />  
        <!-- 定时检查失效的session -->  
        <property name="sessionValidationSchedulerEnabled" value="true" />  
    </bean> 
    
    <!-- sessionIdCookie的实现,用于重写覆盖容器默认的JSESSIONID -->  
    <bean id="sharesession" class="org.apache.shiro.web.servlet.SimpleCookie">  
        <!-- cookie的name,对应的默认是 JSESSIONID -->  
        <constructor-arg name="name" value="SHAREJSESSIONID" />  
        <!-- jsessionId的path为 / 用于多个系统共享jsessionId -->  
        <property name="path" value="/" />  
        <property name="httpOnly" value="true"/>  
    </bean>  
    
    
    <!-- shiro redisManager -->
	<bean id="redisManager" class="org.crazycake.shiro.RedisManager">
	    <property name="host" value="${mvn.redis.host}"/>
	    <property name="port" value="${mvn.redis.port}"/>
	    <property name="expire" value="${mvn.redis.expire}"/>
	    <!-- optional properties:
	    <property name="timeout" value="10000"/>
	    <property name="password" value="123456"/>
	    -->
	</bean>  
	
	<!-- redisSessionDAO -->
	<bean id="redisSessionDAO" class="org.crazycake.shiro.RedisSessionDAO">
	    <property name="redisManager" ref="redisManager" />
	</bean>
	
	<!-- cacheManager -->
	<bean id="cacheManager" class="org.crazycake.shiro.RedisCacheManager">
	    <property name="redisManager" ref="redisManager" />
	</bean>
    
</beans>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值