[root@server1 ~]# tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/
[root@server1 ~]# cd /usr/local/
[root@server1 local]# ln -s jdk1.7.0_79/ java
[root@server1 local]# ls
[root@server1 local]# vim /etc/profile
nginx+tomcat+memcached
[root@server1 local]# source /etc/profile
[root@server1 ~]# vim test.java
nginx+tomcat+memcached
[root@server1 ~]# javac test.java
[root@server1 ~]# java test
Hello World
server2和server1同样
部署tomcat
[root@server1 ~]# tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/
[root@server1 ~]# cd /usr/local/
[root@server1 local]# ls
apache-tomcat-7.0.37 etc include jdk1.7.0_79 lib64 sbin src
bin games java lib libexec share
[root@server1 local]# ln -s apache-tomcat-7.0.37/ tomcat
[root@server1 local]# ls
apache-tomcat-7.0.37 etc include jdk1.7.0_79 lib64 sbin src
bin games java lib libexec share tomc
[root@server1 local]# cd tomcat/
[root@server1 tomcat]# bin/startup.sh
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
[root@server1 tomcat]# netstat -antlp
nginx+tomcat+memcached
nginx+tomcat+memcached
[root@server1 tomcat]# cd webapps/ROOT/
[root@server1 ROOT]# vim test.jsp
The time is: <%=new java.util.Date() %>
server2同上
server3安装nginx
[root@server3 ~]# tar zxf nginx-1.10.1.tar.gz
[root@server3 ~]# tar zxf nginx-sticky-module-ng.tar.gz
[root@server3 ~]# cd nginx-1.10.1
[root@server3 nginx-1.10.1]# vim auto/cc/gcc #注释掉
nginx+tomcat+memcached
[root@server3 nginx-1.10.1]# yum install gcc pcre-devel openssl-devel -y 安装依赖

[root@server3 nginx-1.10.1]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-threads --user=nginx --group=nginx --add-module=/root/nginx-sticky-module-ng
[root@server3 nginx-1.10.1]# make && make install 编译安装
[root@server3 nginx-1.10.1]# cd /usr/sbin/
[root@server3 sbin]# nginx
[root@server3 sbin]# cd /usr/local/lnmp/nginx/conf/
[root@server3 conf]# vim nginx.conf
[root@server3 conf]# pwd
/usr/local/lnmp/nginx/conf

[root@server3 conf]# vim nginx.conf

17 http {
18 upstream tomcat { #负载均衡模块
19 sticky;
20 server 192.168.122.12:8080; #后端tomcat
21 server 192.168.122.13:8080;
22 }
23
24 include mime.types;
25 default_type application/octet-stream;

68 location ~ .jsp$ { #所有jsp页面交给tomcat处理,动静分离
69 proxy_pass http://tomcat;
70 }

[root@server3 logs]# nginx -t
测试:
[root@server3 conf]# curl 172.25.135.1:8080/test.jsp
[root@server3 conf]# curl 172.25.135.2:8080/test.jsp

配置session
server1,2上
把如下软件包放置到/usr/local/tomcat/lib 目录中
kryo-1.03.jar
kryo-serializers-0.8.jar
memcached-2.5.jar
memcached-session-manager-1.5.1.jarmemcached-session-manager-tc7-1.5.1.jar
minlog-1.2.jar
msm-kryo-serializer-1.5.1.jar
reflectasm-0.9.jar
[root@server1 ROOT]# cd /usr/local/tomcat/lib/
[root@server1 lib]# ls
annotations-api.jar jsp-api.jar spymemcached-2.7.3.jar
asm-3.2.jar kryo-1.04.jar tomcat-api.jar
catalina-ant.jar kryo-serializers-0.10.jar tomcat-coyote.jar
catalina-ha.jar memcached-session-manager-1.6.3.jar tomcat-dbcp.jar
catalina.jar memcached-session-manager-tc6-1.6.3.jar tomcat-i18n-es.jar
catalina-tribes.jar memcached-session-manager-tc7-1.6.3.jar tomcat-i18n-fr.jar
ecj-4.2.1.jar minlog-1.2.jar tomcat-i18n-ja.jar
el-api.jar msm-kryo-serializer-1.6.3.jar tomcat-jdbc.jar
jasper-el.jar reflectasm-1.01.jar tomcat-util.jar
jasper.jar servlet-api.jar
[root@server1 lib]# cd ..
[root@server1 tomcat]# cd conf/
[root@server1 conf]# pwd
/usr/local/tomcat/conf

[root@server1 conf]# vim context.xml

<?xml version='1.0' encoding='utf-8'?>
<Context>

<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />

<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:172.25.135.1:11211,n2:172.25.135.2:11211"

failoverNodes="n1" 在 node2(server3) 上此项设置为“n2 (坏了找自己)

requestUriIgnorePattern=".*.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>

[root@server1 conf]# yum install -y memcached 安装
[root@server1 conf]# /etc/init.d/memcached start
[root@server1 conf]# vim /usr/local/tomcat/webapps/ROOT/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>");
System.out.println( name + " = " + value);
}
%>

server2相同配置