tomcat之redis

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tomcat之redis相关的知识,希望对你有一定的参考价值。

nginx服务器:
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
upstream tomcat_pool {
server 192.168.200.112:8080 weight=1 max_fails=1 fail_timeout=10s;
server 192.168.200.113:8080 weight=1 max_fails=1 fail_timeout=10s;
}
location / {
root html;
index index.html index.htm;
proxy_pass http://tomcat_pool;
proxy_set_header Host $http_host;
}
[root@nginx ~]# killall -1 nginx
Tomcat服务器:112
[root@node1~]# yum -y install gcc gcc-c++
[root@node1~]# tar fx redis-3.2.5.tar.gz -C /usr/src/
[root@node1~]# cd /usr/src/redis-3.2.5/
[root@node1redis-3.2.5]# make
[root@localhost redis-3.2.5]# mkdir -p /usr/local/redis/{bin,etc,var}
[root@localhost redis-3.2.5]# cd src/
[root@localhost src]# cp redis-benchmark redis-check-aof redis-cli redis-server /usr/local/redis/bin/
[root@localhost src]# cp ../redis.conf /usr/local/redis/etc
[root@localhost src]# vim /usr/local/redis/etc/redis.conf
daemonize no --> daemonize yes
bind 127.0.0.1 --> bind 0.0.0.0
[root@localhost src]# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
[root@localhost src]# netstat -lnpt | grep redis-server
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 11619/redis-server
[root@localhost redis-3.2.5]# cp *.jar /usr/local/tomcat7/lib
[root@localhost redis-3.2.5]# /usr/local/redis/bin/redis-di -p 6379 monitor //监控共享session
[root@localhost redis-3.2.5]# vim /usr/local/tomcat7/conf/context.xml
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve"/>
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="192.168.200.112" port="6379" database="0" maxInactiveInterval="60"/>
[root@localhost ~]# /usr/local/tomcat7/bin/shutdown.sh
[root@localhost ~]# /usr/local/tomcat7/bin/startup.sh
[root@localhost ~]# vim /usr/local/tomcat7/webapps/ROOT/session.jsp
Session ID:<%= session.getId() %> <BR>
SessionPort:<%= request.getServerPort() %>
<% out.println("This tomcat server 192.168.200.112"); %>
Tomcat服务器:113
[root@node1~]# yum -y install gcc gcc-c++
[root@node1~]# tar fx redis-3.2.5.tar.gz -C /usr/src/
[root@node1~]# cd /usr/src/redis-3.2.5/
[root@node1redis-3.2.5]# make
[root@localhost redis-3.2.5]# mkdir -p /usr/local/redis/{bin,etc,var}
[root@localhost redis-3.2.5]# cd src/
[root@localhost src]# cp redis-benchmark redis-check-aof redis-cli redis-server /usr/local/redis/bin/
[root@localhost src]# cp ../redis.conf /usr/local/redis/etc
[root@localhost src]# vim /usr/local/redis/etc/redis.conf
daemonize no --> daemonize yes
bind 127.0.0.1 --> bind 0.0.0.0
[root@localhost src]# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
[root@localhost src]# netstat -lnpt | grep redis-server
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 11619/redis-server
[root@localhost redis-3.2.5]# cp *.jar /usr/local/tomcat7/lib
[root@localhost redis-3.2.5]# /usr/local/redis/bin/redis-di -p 6379 monitor //监控共享session
[root@localhost redis-3.2.5]# vim /usr/local/tomcat7/conf/context.xml
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve"/>
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="192.168.200.112" port="6379" database="0" maxInactiveInterval="60"/>
[root@localhost ~]# /usr/local/tomcat7/bin/shutdown.sh
[root@localhost ~]# /usr/local/tomcat7/bin/startup.sh
[root@localhost ~]# vim /usr/local/tomcat7/webapps/ROOT/session.jsp
Session ID:<%= session.getId() %> <BR>
SessionPort:<%= request.getServerPort() %>
<% out.println("This tomcat server 192.168.200.113"); %>

以上是关于tomcat之redis的主要内容,如果未能解决你的问题,请参考以下文章

JavaWeb之Tomcat - Tomcat的目录结构

centos之tomcat安装

SpringBoot源码之Tomcat加载原理分析

Tomcat 之 tomcat安装和组件介绍

Linux之tomcat安装

tomcat 之 tomcat实例配置