Nginx实现负载均衡,redis实现session 共享

负载均衡:通过redis 来进行共享session,使用集群。
Nginx-反向代理服务器,也是一个http 服务器。

发送一个请求,请求先会交给反向代理服务器nginx,nginx会根据你的权重,合理的分配给其中的服务器,当其中的一个服务器宕掉,就可以调用其它的服务器,其他的服务器不会受影响。

集群的概念:主要指的是集群服务器

首先,需要一个negix服务器,还应该有两个tomcat服务器,

1、在tomcat中的conf配置server的配置
主要做的是 改变tomcat的port 端口,要同时开启必须改变其中的端口
2、在negix中的conf 中配置negix.xml,在其中主要配置的是他的服务集群,和他们的权重
upstream jeffrey.com{#服务器集群名称
server 127.0.0.1:18080 weight=1;#服务器配置,weight是权重,权重越大,分配的概率越大。
server 127.0.0.1:28080 weight=2;
}
3、通过redis进行session共享,在tomcat的conf配置context.xml (RedisSessionManager)

 <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />

<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
            host="localhost"
            port="6379"
            database="0"
maxInactiveInterval="60" />

猜你喜欢

转载自blog.csdn.net/weixin_41665588/article/details/84783141