Nginx作为目前最流行的开源反向代理HTTP Server,实现资源缓存、web server负载均衡等功能,Tomcat提供动态web内容,redis提供高效缓存构成一个完美web站点组合,但必须借助redis-session-manager-tomcat.jar包才能实现session共享。session-manager负责会话管理,commons-pool是共享池,jedis是连接redis组件,三者协调共享,缺一不可。
特别注意:redis-session-manager-tomcat.jar是通过maven打包而成,与context.xml内容相对应,commons-pool.jar jedis.jar版本要求严格,千万不能轻视。
架构图
实验环境
IP Roles port
station11192.168.1.11 nginx centos6.8 端口:80 版本:1.10.2
station11192.168.1.11 redis 2.4.10 端口:6379
station12192.168.1.12 tomcatA centos6.8 端口:8080
station13192.168.1.13 tomcatB centos6.8 端口:8080 版本:Jdk:1.8.0_91 Tomcat: 7.0.75
Station11 安装redis
[root@station11 ~]# yum -y install redis
redis-2.4.10-1.el6.x86_64
[root@station11 ~]# mkdir -pv /data/redis
[root@station11 ~]# chown -R redis.root /data/redis
[root@station11 ~]# vim /etc/redis.conf
1
2
3
4
5
|
daemonize
yes
bind 192.168.1.11
logfile
/var/log/redis/redis
.log
dir
/data/redis
requirepass redhat
|
[root@station11 ~]# echo vm.overcommit_memory=1 >> /etc/sysctl.conf
[root@station11 ~]# sysctl vm.overcommit_memory=1
[root@station11 ~]# chown redis.root /var/log/redis/redis.log
[root@station11 ~]#service redis start
[root@station11 ~]# netstat -nutlp | grep redis
1
|
tcp 0 0 192.168.1.11:6379 0.0.0.0:* LISTEN 3568
/redis-server
|
[root@station11 ~]# redis-cli -h 192.168.1.11 -p 6379 -a redhat
1
2
|
redis 192.168.1.11:6379>
select
0
OK
|
[root@station12 ~]# ls
apache-tomcat-7.0.75.tar.gz jdk-8u91-linux-x64.tar.gz
[root@station12 ~]# tar zxvf jdk-8u91-linux-x64.tar.gz -C /usr/local/
[root@station12 ~]# ln -sv /usr/local/jdk1.8.0_91/ /usr/local/java
[root@station12 ~]# cat > /etc/profile.d/java.sh << EOF
1
2
3
4
5
|
JAVA_HOME=
/usr/local/java/
JRE_HOME=
/usr/local/java/
PATH=$JAVA_HOME
/bin
:$PATH
export
JAVA_HOME JRE_HOME PATH
EOF
|
[root@station12 ~]# java -version
1
2
3
|
java version
"1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
|
[root@station12 ~]# tar zxvf apache-tomcat-7.0.75.tar.gz -C /usr/local/
[root@station12 ~]# ln -sv /usr/local/apache-tomcat-7.0.75/ /usr/local/tomcat
[root@station12 ~]# cat > /etc/profile.d/tomcat.sh << EOF
1
2
3
|
export
CATALINA_HOME=
/usr/local/tomcat
export
PATH=$CATALINA_HOME
/bin
:$PATH
EOF
|
[root@station12 ~]#. /etc/profile.d/tomcat.sh
[root@station12 ~]# catalina.sh version
1
2
3
4
5
6
7
8
9
10
11
12
13
|
Using CATALINA_BASE:
/usr/local/tomcat
Using CATALINA_HOME:
/usr/local/tomcat
Using CATALINA_TMPDIR:
/usr/local/tomcat/temp
Using JRE_HOME:
/usr/local/java/
Using CLASSPATH:
/usr/local/tomcat/bin/bootstrap
.jar:
/usr/local/tomcat/bin/tomcat-juli
.jar
Server version: Apache Tomcat
/7
.0.75
Server built: Jan 18 2017 20:54:42 UTC
Server number: 7.0.75.0
OS Name: Linux
OS Version: 2.6.32-642.el6.x86_64
Architecture: amd64
JVM Version: 1.8.0_91-b14
JVM Vendor: Oracle Corporation
|
[root@station12 ~]#vim /etc/init.d/tomcat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#!/bin/sh
# Tomcat init script for Linux.
#
# chkconfig: 2345 96 14
# description: The Apache Tomcat servlet/JSP container.
# JAVA_OPTS='-Xms64m -Xmx128m'
#-Xms64m指的是java虚拟机启动时占用的内存为64M -Xmx128m指的是java虚拟机最大能使用的内存为128M;
JAVA_HOME=
/usr/local/java
CATALINA_HOME=
/usr/local/tomcat
export
JAVA_HOME CATALINA_HOME
case
$1
in
start)
exec
$CATALINA_HOME
/bin/catalina
.sh start ;;
stop)
exec
$CATALINA_HOME
/bin/catalina
.sh stop;;
restart)
$CATALINA_HOME
/bin/catalina
.sh stop
sleep
2
exec
$CATALINA_HOME
/bin/catalina
.sh start ;;
*)
echo
"Usage: `basename $0` {start|stop|restart}"
exit
1
;;
esac
|
[root@station12 ~]# chmod +x /etc/init.d/tomcat
[root@station12 ~]# chkconfig --add tomcat
[root@station12 tomcat]# service tomcat start
[root@station12 tomcat]# netstat -nutlp | grep java
1
2
3
|
tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 1977
/java
tcp 0 0 :::8009 :::* LISTEN 1977
/java
tcp 0 0 :::8080 :::* LISTEN 1977
/java
|
[root@station12 ~]# cd /usr/local/tomcat
[root@station12 tomcat]# vim webapps/ROOT/test.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<%@ page language=
"java"
%>
<
head
>
/title
><
/head
>
你可能感兴趣的:(Linux) |