session共享机制
来源:互联网 发布:金字塔期货交易软件 编辑:程序博客网 时间:2024/06/05 18:47
session共享机制tomcat将缓存信息备份存在memcache中
1.tomcat和nginx的使用
[root@server1 conf]# cd /usr/local/lnmp/nginx/conf/
[root@server1 conf]# /etc/init.d/php-fpm start
Starting php-fpm done
[root@server1 conf]# nginx##开启服务
[root@server1 conf]# vim nginx.conf
[root@server1 conf]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server1 conf]# nginx -s reload
(18)http { upstream westos{ ip_hash;##开启ip_hash固定一个主机访问的后端服务器 server 172.25.39.2:8080; server 172.25.39.3:8080;} (90) location ~ \.jsp$ { proxy_pass http://westos; ##所有以.jsp结尾的都转换 }
[root@server1 conf]# cat nginx.conf—–所有没有大规模注释的文件内容如下
用;这里表示注释;user nobody;worker_processes 2;worker_cpu_affinity 01 10;;error_log logs/error.log;;error_log logs/error.log notice;error_log logs/error.log info;;pid logs/nginx.pid;events { worker_connections 65535;}http { upstream westos{ ip_hash; server 172.25.78.2:8080; server 172.25.78.3:8080;} include mime.types; default_type application/octet-stream; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; location / { root html; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }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.conf;}location ~ \.jsp$ { proxy_pass http://westos; } } server { listen 443 ssl; server_name localhost; ssl_certificate cert.pem; ssl_certificate_key cert.pem; 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; } }server {listen 80;server_name www.westos.org;location / {proxy_pass http://westos;}}}
测试页码的编写
[root@server2 ~]# cd /usr/local/tomcat/webapps/ROOT/
[root@server2 ROOT]# vim test.jsp
内容从老吴文档复制
<%@ page contentType="text/html; charset=GBK" %><%@ page import="java.util.*" %><html><head><title>Cluster App Test</title></head><body>Server Info:<%out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"<br>");%><%out.println("<br> ID " + session.getId()+"<br>");String dataName = request.getParameter("dataName");if (dataName != null && dataName.length() > 0) {String dataValue = request.getParameter("dataValue");session.setAttribute(dataName, dataValue);}out.print("<b>Session list</b>");Enumeration e = session.getAttributeNames();while (e.hasMoreElements()) {String name = (String)e.nextElement();String value = session.getAttribute(name).toString();out.println( name + " = " + value+"<br>");Enumeration e = session.getAttributeNames();while (e.hasMoreElements()) {String name = (String)e.nextElement();String value = session.getAttribute(name).toString();out.println( name + " = " + value+"<br>");System.out.println( name + " = " + value);}%><form action="test.jsp" method="POST">name:<input type=text size=20 name="dataName"><br>key:<input type=text size=20 name="dataValue"><br><input type=submit></form></body></html>
scp test.jsp 172.25.39.3:/root/tomcat/webapps/ROOT##给3
中复制相同的页
nginx+tomcat+memcache####共享的实现
1.
get {—from 老吴
asm-3.2.jar
kryo-1.04.jar
kryo-serializers-0.10.jar
memcached-session-manager-1.6.3.jar
memcached-session-manager-tc6-1.6.3.jar
memcached-session-manager-tc7-1.6.3.jar
minlog-1.2.jar
msm-kryo-serializer-1.6.3.jar
reflectasm-1.01.jar
spymemcached-2.7.3.jar }
因为使用的tomcat是7的所以把6的删掉
2.把这些东西放到/usr/local/tomcat/lib
3.打开server2和server3的memc
/etc/init.d/memecached start
- vim /usr/local/tomcat/conf/context.xml
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"memcachedNodes="n1:172.25.39.2:11211,n2:172.25.39.3:11211"failoverNodes="n1"##在server2和server3上分别弄n1和n2如果tomcat1 故障了那么就n1取缓存数据否则就是取自己的缓存---n1就相当于上课讲解的memc2requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"/>
. \ / .
. X .
. / \ .
Tomcat-1 (T1) 将 session 存储在 memcached-2 (T2)上。只有当 M2 不可用时,T1 才将 session 存储在 memcached-1 上(M1 是 T1 failoverNode)。使用这种配置的好处是,当 T1 和 M1 同时崩溃时也不会丢失 session 会话,避免单点故障。
5.打开tomcat服务
/usr/local/tomcat/bin/startup.sh(关闭服务)
/usr/local/tomcat/bin/shutdown.sh
cd /usr/local/tomcat
tail -f logs/catalina.out 试验服务打开是否成功
(INFO: MemcachedSessionService finished initialization, sticky true, operation timeout 1000, with node ids [n1] and failover node ids [n2])证明成功
6.yum install telnet -y两台都做—–telnet作用监控
测试
172.25.78.1/test.jsp
telnet localhost 11211远程监控本地的11211端口 监控存储
[root@server3 lib]# telnet localhost 11211Trying ::1...Connected to localhost.Escape character is '^]'.get 48844C8F70F022944863813004730A7E-n2VALUE 48844C8F70F022944863813004730A7E-n2 2048 136W]hB8]h01]h)]h)#48844C8F70F022944863813004730A7E-n2user2456user3789user8888usr1123END
- 集群session共享机制
- 集群session共享机制
- session共享机制
- cookie,Session机制的本质,跨应用程序的session共享
- 共享Session
- session共享
- session共享
- session 共享
- session共享
- session共享
- session共享
- session共享
- session共享
- session共享
- Session共享
- session共享
- session共享
- session共享
- 离散事件模拟-银行管理
- hdu 6053 TrickGCD [2017 Multi-University Training Contest
- Ubuntu 14.04的基本配置
- HDU 6053 TrickGCD DP(筛法)
- 练习(三)
- session共享机制
- 程序员眼中世界上最远的距离
- Android 性能优化<九> RecyclerView替代Listview用法
- js基础 事件基础一
- C++实现顺序表基本函数以及增删查改
- C# DataSet和DataTable详解(一)
- 购物车
- 权限,网络请求,判断,XlistVIew的依赖
- Wooden Sticks HDU