Windows下使用最新nginx+redis+tomcat实现session共享集群

nginx1.8.0+tomcat8.0.28+redis2.8.2104+Spring Session1.0.2 实现集群和session共享(Winsows版)

 

最近公司需要一个布设一个项目进行业务数据查询,希望使用集群负载均衡,同时需要session共享,由于个人喜欢追逐最新版本,故写出此文记录下成功过程,希望可以帮助同样有疑惑的人.

准备文件:

 
 

tomcat8.0.28 点我下载(64位)

 

redis2.8.2104 点我下载(64位 MSOpenTech提供)

Spring Session1.0.2需要一些依赖包大家可以去spring官网去找到下载方法

 

部署过程:

1.安装redis

推荐使用设置成windows服务和使用默认端口6379

扫描二维码关注公众号,回复: 469083 查看本文章

2.配置tomcat

将下载好的tomcat压缩包解压重命名为两个文件夹

打开apache-tomcat-8.0.28-18080\conf\server.xml

更改三个默认端口

同理将apache-tomcat-8.0.28-18081中三个端口也修改

3.安装配置nginx

更改nginx.conf文件

upstream tomcatserver {  
      #根据ip计算将请求分配各那个后端tomcat,许多人误认为可以解决session问题,其实并不能。  
      #同一机器在多网情况下,路由切换,ip可能不同  
      #ip_hash;   
      server localhost:18080;  
      server localhost:18081;  
    }
    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://tomcatserver;
        }

程序添加

1.jar引入

确认springsession需要的jar全部引入项目

2.web.xml

  	<!-- spring session filter -->	
  	<filter>
	    <filter-name>springSessionRepositoryFilter</filter-name>
	    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
	</filter>
	<filter-mapping>
	    <filter-name>springSessionRepositoryFilter</filter-name>
	    <url-pattern>/*</url-pattern>
	</filter-mapping>

3.spring.xml

<span style="white-space:pre">	</span><!-- spring session redis -->
	<context:annotation-config/>
	<bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
	<span style="white-space:pre">	</span><property name="maxInactiveIntervalInSeconds" value="1800"></property>
	</bean>
	<bean class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"/>

总结

至此所有配置完成,第一次写博客,不成熟地方请指正,如果此篇文章对你有所帮助,希望能对博主进行小小的赞助~
 

猜你喜欢

转载自wangzhekid.iteye.com/blog/2258998
今日推荐