Linux(CentOS)下Nginx+Tomcat集群+Redis共享Session搭建
2018-03-08 16:43
681 查看
Linux(CentOS7)下Nginx+Tomcat集群+Redis共享Session搭建
版本:CentOS7+Nginx1.12.2+Tomcat7.085+Redis3.2.1+Java7
b)修改conf/nginx.conf:upstream tomcats {
server 127.0.0.1:18080 weight=2 max_fails=3 fail_timeout=15;
server 127.0.0.1:28080 weight=1;
server 127.0.0.1:38080 weight=1;
}
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://tomcats; }
a) 修改tomcat(所有的tomcat)文件夹中conf/context.xml文件,在context节点下添加如下配置:注意官方给的有误,很多博客也跟着传,我也掉坑里了。复制我的就好。如下:<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve"/>
<Manager className="com.radiadesign.catalina.session.RedisSessionManager"
host="localhost"
port="6379"
database="0"
maxInactiveInterval="60"/>
b)conf/server.xml文件中的端口根据规划依次修改。要改三个地方:
我的是在端口前都加了1,2,3等等
1. <Server port="18005"shutdown="SHUTDOWN">
2. <Connector port="18080"protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
3 <Connector port="18009" protocol="AJP/1.3"redirectPort="8443" />
c)在tomcat的lib文件夹下分别添加6个jar文件,这个地方jar文件的版本有可能会有冲突,配置的时候需要多尝试.
版本:CentOS7+Nginx1.12.2+Tomcat7.085+Redis3.2.1+Java7
1. 下载安装Nginx(直接解压就行)
a) 安装Nginxb)修改conf/nginx.conf:upstream tomcats {
server 127.0.0.1:18080 weight=2 max_fails=3 fail_timeout=15;
server 127.0.0.1:28080 weight=1;
server 127.0.0.1:38080 weight=1;
}
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://tomcats; }
2. 下载tomcat解压复制几份(看项目需求)
a) 修改tomcat(所有的tomcat)文件夹中conf/context.xml文件,在context节点下添加如下配置:注意官方给的有误,很多博客也跟着传,我也掉坑里了。复制我的就好。如下:<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve"/>
<Manager className="com.radiadesign.catalina.session.RedisSessionManager"
host="localhost"
port="6379"
database="0"
maxInactiveInterval="60"/>
b)conf/server.xml文件中的端口根据规划依次修改。要改三个地方:
我的是在端口前都加了1,2,3等等
1. <Server port="18005"shutdown="SHUTDOWN">
2. <Connector port="18080"protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
3 <Connector port="18009" protocol="AJP/1.3"redirectPort="8443" />
c)在tomcat的lib文件夹下分别添加6个jar文件,这个地方jar文件的版本有可能会有冲突,配置的时候需要多尝试.
3. 安装redis,并且启动
4. 在三个tomcat的webapps/ROOT目录下,修改index.jsp
<%@ pagelanguage="java" %> <html> <head><title>TomcatA</title></head> <body> <tablealign="centre" border="1"> <tr> <td>Session ID</td> <td><%= session.getId() %></td> </tr> <tr> <td>Created on</td> <td><%= session.getCreationTime() %></td> </tr> </table> </body> </html> sessionID:<%=session.getId()%> <br> SessionIP:<%=request.getServerName()%> <br> SessionPort:<%=request.getServerPort()%> <% //为了区分,第二个可以是222 out.println("This is Tomcat Server 333333333333"); %>测试结果:
相关文章推荐
- Nginx+Tomcat搭建集群,Spring Session+Redis实现Session共享
- Nginx+Tomcat搭建集群,Spring Session+Redis实现Session共享
- Nginx+Tomcat搭建集群,Spring Session+Redis实现Session共享
- 【原创】搭建Nginx(负载均衡)+Redis(Session共享)+Tomcat集群
- 搭建Nginx(负载均衡)+Redis(Session共享)+Tomcat集群
- Nginx+Tomcat搭建集群,Spring Session+Redis实现Session共享
- 搭建Nginx(负载均衡)+Redis(Session共享)+Tomcat集群
- 使用nginx搭建集群tomcat8,redis实现session共享,文件共享问题
- Linux高可用(HA)之Nginx+Redis+Tomcat集群实现session保持和共享
- Nginx+Tomcat+Redis搭建共享SESSION集群
- Nginx +Tomcat集群搭建 Redis实现session共享
- 搭建Nginx(负载均衡)+Redis(Session共享)+Tomcat集群
- linux下实现redis共享session的tomcat集群
- 使用nginx搭建集群tomcat8,redis实现session共享,文件共享问题
- linux下实现redis共享session的tomcat集群
- Nginx+Tomcat搭建集群,Spring Session+Redis实现Session共享
- 搭建Nginx(负载均衡)+Redis(Session共享)+Tomcat集群
- Linux+Nginx+Tomcat+Redis实现负载均衡,应用集群及session共享
- 搭建Nginx(负载均衡)+Redis(Session共享)+Tomcat集群
- Linux下搭建Nginx+Keepalived+Redis+Tomcat实现session共享 、负载均衡、高可用