nginx+tomcat+memcached构建session共享集群

一、安装配置tomcat

配置前说明:

系统为centos7

m1.xsllqs.com地址为192.168.1.107

c1.xsllqs.com地址为192.168.1.114

c2.xsllqs.com地址为192.168.1.113

安装tomcat需要配合JDK使用,JDK有oracle JDK和open JDK两种

oracle JDK8的下载地址:http://www.oracle.com/technetwork/cn/java/javase/downloads/jdk8-downloads-2133151-zhs.html

tomcat的下载地址:http://tomcat.apache.org/

c1.xsllqs.com(192.168.1.114)下载安装jdk(建议加载到本地在传上去)和tomcat

[[email protected] ~]# wget http://download.oracle.com/otn-pub/java/jdk/8u73-b02/jdk-8u73-linux-x64.rpm
[[email protected] ~]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.0.36/bin/apache-tomcat-8.0.36.tar.gz
[[email protected] ~]# ls
apache-tomcat-8.0.36.tar.gz  jdk-8u73-linux-x64.rpm

[[email protected] ~]# yum install jdk-8u73-linux-x64.rpm
[[email protected] ~]# vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/latest
export PATH=$JAVA_HOME/bin:$PATH

[[email protected] ~]# . /etc/profile.d/java.sh
[[email protected] ~]# java -version
java version "1.8.0_73"

[[email protected] ~]# tar xf apache-tomcat-8.0.36.tar.gz -C /usr/local
[[email protected] ~]# cd /usr/local/
[[email protected] local]# ln -sv apache-tomcat-8.0.36 tomcat
"tomcat" -> "apache-tomcat-8.0.36"

[[email protected] tomcat]# vim /etc/profile.d/tomcat.sh
export CATALINA_HOME=/usr/local/tomcat
export PATH=$CATALINA_HOME/bin:$PATH

[[email protected] tomcat]# . /etc/profile.d/tomcat.sh

c2.xsllqs.com(192.168.1.113)下载安装jdk和tomcat

[[email protected] ~]# wget http://download.oracle.com/otn-pub/java/jdk/8u73-b02/jdk-8u73-linux-x64.rpm
[[email protected] ~]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.0.36/bin/apache-tomcat-8.0.36.tar.gz
[[email protected] ~]# ls
apache-tomcat-8.0.36.tar.gz  jdk-8u73-linux-x64.rpm
[[email protected] ~]# yum install jdk-8u73-linux-x64.rpm 
[[email protected] ~]# vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/latest
export PATH=$JAVA_HOME/bin:$PATH

[[email protected] ~]# . /etc/profile.d/java.sh
[[email protected] ~]# java -version
java version "1.8.0_73"

[[email protected] ~]# tar xf apache-tomcat-8.0.36.tar.gz -C /usr/local
[[email protected] ~]# cd /usr/local/
[[email protected] local]# ln -sv apache-tomcat-8.0.36 tomcat
"tomcat" -> "apache-tomcat-8.0.36"

[[email protected] tomcat]# vim /etc/profile.d/tomcat.sh
export CATALINA_HOME=/usr/local/tomcat
export PATH=$CATALINA_HOME/bin:$PATH

[[email protected] tomcat]# . /etc/profile.d/tomcat.sh

二、修改tomcat配置文件

[[email protected] tomcat]# cd /usr/local/tomcat/webapps/
[[email protected] webapps]# mkdir myapp/{lib,classes,WEB-INF,META-INF} -pv
[[email protected] webapps]# cd myapp/

添加c1和c2的主页文件

[[email protected] myapp]# vim indix.jsp
<%@ page language="java" %>
<html>
  <head><title>Tomcat1</title></head>
  <body>
    <h1><font color="red">c1.xsllqs.com</font></h1>
    <table align="centre" border="1">
      <tr>
        <td>Session ID</td>
    <% session.setAttribute("xsllqs.com","xsllqs.com"); %>
        <td><%= session.getId() %></td>
      </tr>
      <tr>
        <td>Created on</td>
        <td><%= session.getCreationTime() %></td>
     </tr>
    </table>
  </body>
</html>

[[email protected] myapp]# vim indix.jsp

<%@ page language="java" %>
<html>
  <head><title>Tomcat2</title></head>
  <body>  
    <h1><font color="blue">c2.xsllqs.com</font></h1>
    <table align="centre" border="1">
      <tr>    
        <td>Session ID</td> 
    <% session.setAttribute("xsllqs.com","xsllqs.com"); %>
        <td><%= session.getId() %></td> 
      </tr>   
      <tr>    
        <td>Created on</td> 
        <td><%= session.getCreationTime() %></td> 
     </tr>   
    </table>
  </body> 
</html>

修改tomcat-user.xml(c1和c2都要改)

[[email protected] conf]# vim /usr/local/tomcat/conf/tomcat-users.xml
#在</tomcat-users>中添加
  <role rolename="manager-gui"/>
  <role rolename="admin-gui"/>
  <user username="tomcat" password="<tomcat>" roles="manager-gui,admin-gui"/>

修改server.xml(c1和c2都要改)

[[email protected] conf]# vim /usr/local/tomcat/conf/server.xml
#修改主配置文件,appBase后面是应用的相对路径也可以是绝对路径
<Host name="localhost"  appBase="webapps"
unpackWARs="true" autoDeploy="true">
#这里是访问日志的设置
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
#这里设置Context调用msm需要的组件,m1为主c2为备,因为我这里只有3台机器所以把c2作为备,正常情况是4台,2台memcached和2台tomcat
<Context path="/myapp" docBase="/usr/local/tomcat/webapps/myapp" reloadable="true">
              <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
               memcachedNodes="m1:192.168.1.107:11211,c2:192.168.1.113:11211"
                failoverNodes="m1"
                requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
                transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
              />
             </Context>

测试配置文件

[[email protected] ~]# catalina.sh configtest
[[email protected] ~]# catalina.sh configtest
[[email protected] ~]# catalina.sh start
[[email protected] ~]# catalina.sh start

三、安装msm

c1和c2上下载msm需要的jar包

[[email protected] ~]# wget http://repo1.maven.org/maven2/de/javakaffee/msm/memcached-session-manager/1.9.4/memcached-session-manager-1.9.4.jar
[[email protected] ~]# wget http://repo1.maven.org/maven2/de/javakaffee/msm/memcached-session-manager-tc8/1.9.4/memcached-session-manager-tc8-1.9.4.jar
[[email protected] ~]# wget http://repo1.maven.org/maven2/de/javakaffee/msm/msm-javolution-serializer/1.9.4/msm-javolution-serializer-1.9.4.jar
[[email protected] ~]# wget http://repo1.maven.org/maven2/net/spy/spymemcached/2.11.1/spymemcached-2.11.1.jar
[[email protected] ~]# wget http://www.java2s.com/Code/JarDownload/javolution/javolution-5.4.3.1.jar.zip

[[email protected] ~]# mv javolution-5.4.3.1.jar memcached-session-manager-1.9.4.jar memcached-session-manager-tc8-1.9.4.jar msm-javolution-serializer-1.9.4.jar spymemcached-2.11.1.jar /usr/local/tomcat/lib/

m1和c2上安装memcached

[[email protected] ~]# yum install memcached
[[email protected] ~]# yum install memcached

m1上安装nginx修改nginx的配置文件

[[email protected] ~]# yum install nginx
[[email protected] ~]# vim /etc/nginx/nginx.conf
#server外加入
upstream tcsrvs {
    server 192.168.1.114:8080;
    server 192.168.1.113:8080;
}
#server内加入
    location ~* \.(jsp|do)$ {
        proxy_pass http://tcsrvs;
    }
[[email protected] ~]# nginx -t

启动服务

[[email protected] ~]# systemctl start nginx.service
[[email protected] ~]# systemctl start memcached
[[email protected] ~]# systemctl start memcached

四、测试

时间: 2024-10-07 03:37:15

nginx+tomcat+memcached构建session共享集群的相关文章

【电商】nginx+tomcat+memcached实现session共享集群

在分布式多tomcat web集群环境下,首先要解决的是session的共享问题,一般的实现思路有: (1) session复制:多tomcat之间进行session的同步,集群中的tomcat存储相同的session信息 (2) 共享session存储:将session集中存储在同一个地方,如redis/memcached,甚至DB.tomcat本身的内存中并不存储session (3) session粘性:其实session粘性并不是session共享的方案,而是多tomcat的集群方案,配

nginx+tomcat+memcached实现session共享

一.工作原理及原理图<img class="alignnone wp-image-31" src="http://119.29.25.60/wp-content/uploads/2016/04/图片1.bmp" alt="图片1" width="342" height="254" />工作原理        Tomcat中自带缓存功能.Memcached时一个集中式缓存器,可以利用tomcat和

构建session共享集群

一.安装配置tomcat 配置前说明: 系统为centos7 m1.xsllqs.com地址为192.168.1.107 c1.xsllqs.com地址为192.168.1.114 c2.xsllqs.com地址为192.168.1.113 安装tomcat需要配合JDK使用,JDK有oracle JDK和open JDK两种 oracle JDK8的下载地址:下载 tomcat的下载地址:http://tomcat.apache.org/ c1.xsllqs.com(192.168.1.114

搭建LVS+Keepalived+nginx+tomcat高可用性,高性能jsp集群

LVS-master:192.168.0.210 LVS-backup:192.168.0.211 LVS-VIP:192.168.0.209 nginx+tomcat:192.168.0.212 nginx+tomcat:192.168.0.227 安装nginx所需包: Nginx-1.6.0.tar.gz和pcre-8.35.zip 一.安装pcre-8.35 1 #unzip pcre-8.35.zip 2 #cd pcre-8.35 3 #./configure 4 #make 5 #

【Tomcat】Tomcat + Memcached 实现session共享

概述 web项目中,Tomcat的访问量总是有限的,这时候就需要用到Tomcat集群,多个Tomcat的时候就要考虑Session共享的问题,这里介绍一种使用Memcached做Session共享的解决方案 环境 操作系统:Linux( centOS 6..5 版) 软件:Tomcat7    Memcached 实现原理 Tomcat + Memcached 实现session共享流程图 配置 安装Tomcat 2个和Memcached 1个,参考[Linux]Tomcat安装及一个服务器配置

nginx+tomcat8+memcached实现session 共享

操作环境: iP地址 角色 安装软件 10.43.2.135 nginx方向代理 memcached服务器 nginx   memcached 10.43.2.134 tomcat服务器 2个tomcat(端口分别为8080 8081) 实验中使用的软件如下: 实现思路: 第一步:针对10.43.2.134的操作 1.在10.43.2.134上安装2个tomcat 2.在$CATALINA/webapps/ROOT/下建立测试页面t.jsp 3.分别启动2个tomcat服务 4.打开http:/

nginx+tomcat8+memcached实现session共享具体操作

本次试验用到的软件包的版本如下: 一.针对10.43.2.134的操作 1.安装jdk环境 tar zxf jdk-8u5-linux-x64.tar.gz mkdir /usr/java mv jdk1.8.0_05/ /usr/java/ 编辑/etc/profile 在文档的末尾追加如下5行内容: JAVA_HOME=/usr/java/jdk1.8.0_05 JRE_HOME=/usr/java/jdk1.8.0_05/jre PATH=$PATH:$JAVA_HOME/bin:$JRE

keepalived+nginx+tomcat搭建高性能web服务器集群

使用keepalived+nginx+tomcat搭建高性能web服务器集群,系统采用centos6.9,前端用nginx做反向代理实现负载均衡,同时结合keepalived对nginx实现高可用,后端使用两台tomcat做动态jsp解析,实现了动静分离. 搭建环境 准备四台服务器 vip: 192.168.75.130master: 192.168.75.131 (安装nginx做反向代理实现负载匀衡,结合keepalived实现高可用)backup: 192.168.75.132 (同上)w

solr安装-tomcat+solrCloud构建稳健solr集群

solr安装-tomcat+solrCloud构建稳健solr集群 2014-05-29 12:17 11985人阅读 评论(2) 收藏 举报  分类: solr(1)  版权声明:本文为博主原创文章,未经博主允许不得转载. solrCloud的搭建可以有两种方式:使用solr内嵌的jetty来搭建:使用外部web容器tomcat来搭建.对于使用jett来搭建参考solr官方的手册照着做肯定ok,下面我主要讲的是如何使用tomcat来搭建solrCloud. 废话不多说,开始我们的工作! 1.搭