原料
tomcat-7.0.42
nginx-1.9.2
memcached-win32-1.4.4-14
安装方法这里就不再说明一大堆
注意:这里需要注意的是tomcat里需要memcached jar包
链接:http://pan.baidu.com/s/1pLRICUB
密码:u72i
下载完把jar直接放到tomcat的lib文件下
1.第一步tomcat配置
⑴ conf/context.xml中在
<Context></Context>
节点中加入以下配置每个tomcat1,tomcat2各配置一个
<Manager
className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:localhost:11211"
sticky="false"
sessionBackupAsync="false"
lockingMode="uriPattern:/path1|/path2"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"/>
⑵ conf/server.xml 加入 jvmRoute=”tomcat7-1”
依次类推tomcat2,jvmRoute=”tomcat7-2”<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat7-1">
2.第二步nginx配置
这是我的nginx配置,在upstream 里配置了俩个服务
#user nobody;
worker_processes auto;
worker_rlimit_nofile 100000;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 204800;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 10;
#gzip on;
server_names_hash_max_size 512;
server_names_hash_bucket_size 128;
upstream localhost {
server 192.168.23.24:8080 weight=1 fail_timeout=5s;
server 192.168.23.24:8012 weight=5 fail_timeout=5s;
}
server {
listen 80;
server_name 192.168.23.24;
location / {
root html;
index index.html index.htm;
proxy_pass http://localhost;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 10;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
}
3.第三测试页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>session测试页面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
SessionID:<%=session.getId()%>
<BR>
SessionIP:<%=request.getServerName()%>
<BR>
SessionPort:<%=request.getServerPort()%>
<BR>
</body>
</html>
赏
使用支付宝打赏
使用微信打赏
若你觉得我的文章对你有帮助,欢迎点击上方按钮对我打赏
扫描二维码,分享此文章