标签:gets dex orm 支持 ima image ons nbsp nts
安装jdk安装tomcat7
安装nginx
安装redis
tomcat-redis-session-manager项目目前只支持tomcat6和tomcat7
使用gradle编译
wget https://services.gradle.org/distributions/gradle-4.4.1-bin.zip
unzip gradle-4.4.1-bin.zip
然后将它的bin加到PATH环境变量就可以使用gradle命令了
编译tomcat-redis-session-manager
修改tomcat-redis-session-manager中的代码
https://github.com/jcoleman/tomcat-redis-session-manager
下载tomcat-redis-session-manager的zip文件
unzip tomcat-redis-session-manager-master.zip
修改build.gradle文件
vim build.gradle
注释掉47-49行,56-58行
47 //signing {
48 // sign configurations.archives
49 //}
56 // repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
57 // authentication(userName: sonatypeUsername, password: sonatypePassword)
58 // }
构建
到tomcat-redis-session-manager-master目录下
gradle build
#如果gradle没有加到PATH环境变量中,就用绝对路径
显示BUILD SUCCESSFUL说明构建成功
build/libs/下可以找到构建的tomcat-redis-session-manager-master-2.0.0.jar包
/root/.gradle/caches/目录下可以找到jedis-2.5.2.jar、commons-pool2-2.2.jar
将这三个包放到tomcat的libs目录下
设置nginx+tomcat的负载均衡
本次测试使用的一台机器,运行了tomcat双实例
服务 | 端口 | 主配置文件 |
nginx | 80 | /etc/nginx/conf.d/default.conf(yum安装) ${NGINX_HOME}/conf/nginx.conf(二进制安装) |
tomcat1 | 8080 | /tomcat1/conf/server.xml/ |
tomcat2 | 8081 | /tomcat2/conf/server.xml/ |
在tomcat中添加测试页面(路径自行修改)
tomcat1 | /tomcat1/webapps/ROOT/test.jsp |
tomcat2 | tomcat2 |
内容如下(out.println后面为输出信息,请自行修改)
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false"%>
SessionID:<%=session.getId()%><BR>
SessionIP:<%=request.getServerName()%> <BR>
SessionPort:<%=request.getServerPort()%>
<% out.println("This is Tomcat 1 !"); %>
启动tomcat访问测试
IP:PORT/test.jsp
设置nginx负载均衡
这里以yum安装的nginx为例
vim /etc/nginx/conf.d/default.conf
#设置upstream upstream tomcat_nginx { server 192.168.233.111:8080; server 192.168.233.111:8081; }
server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html;
# Load configuration files for the default server block. include /etc/nginx/default.d/*.conf;
#修改location location / { proxy_pass http://tomcat_nginx; # root html; # index index.html index.htm; }
error_page 404 /404.html; location = /40x.html { }
error_page 500 502 503 504 /50x.html; location = /50x.html { }
} |
启动nginx访问测试
修改tomcat的conf/context.xml实现将session存放在redis中
<Context> <!-- Default set of monitored resources --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" /> <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="127.0.0.1" port="6379" password="redhat" database="0" maxInactiveInterval="60" /> <!-- Uncomment this to disable session persistence across Tomcat restarts --> <!-- <Manager pathname="" /> --> <!-- Uncomment this to enable Comet connection tacking (provides events on session expiration as well as webapp lifecycle) --> <!-- <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> --> </Context> |
host是主机,password是密码,没有就删掉这行,post端口,注意Valve必须在Manager之前
启动redis,重启tomcat访问测试
##### 注意:tomcat-redis-session-manager项目不支持tomcat8,作者没弄,网上的都是在7的基础上进行的修改,不知道会有什么问题。
安装网上的弄tomcat8+redis老是报错,明天试试其他方法,试试memcache
标签:gets dex orm 支持 ima image ons nbsp nts
原文地址:http://blog.51cto.com/13323775/2058890