[root@server1 ~]# tar zxf openresty-1.13.6.1.tar.gz
[root@server1 ~]# cd openresty-1.13.6.1
[root@server1 openresty-1.13.6.1]# ./configure --prefix=/usr/local/lnmp/openresty
[root@server1 openresty-1.13.6.1]# gmake && gmake instal
[root@server1 ~]# vim /usr/local/lnmp/openresty/nginx/conf/nginx.conf
19 upstream memcache {
20 server 172.25.12.1:11211;
21 keepalive 512;
22 }
53 location /memc {
54 internal;
55 memc_connect_timeout 100ms;
56 memc_send_timeout 100ms;
57 memc_read_timeout 100ms;
58 set $memc_key $query_string;
59 set $memc_exptime 300;
60 memc_pass memcache;
61 }
80 location ~ \.php$ {
81 set $key $uri$args;
82 srcache_fetch GET /memc $key;
83 srcache_store PUT /memc $key;
84 root html;
85 fastcgi_pass 127.0.0.1:9000;
86 fastcgi_index index.php;
87 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
88 include fastcgi.conf;
89 }
[root@server1 ~]# /etc/init.d/memcached start
Starting memcached: [ OK ]
[root@server1 ~]# /etc/init.d/php-fpm start
Starting php-fpm done
##Server1主机已经配置过nginx,所以这里启动openresty采用绝对路径
[root@server1 ~]# /usr/local/lnmp/openresty/nginx/sbin/nginx
[kiosk@foundation12 Desktop]$ ab -c 1 -n 1000 http://172.25.12.1/example.php
Time taken for tests: 0.762 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Requests per second: 1728.62 [#/sec] (mean)
[kiosk@foundation12 Desktop]$ ab -c 1 -n 1000 http://172.25.12.1/index.php
Time taken for tests: 2.328 seconds
Complete requests: 1000
Failed requests: 97
Requests per second: 429.56 [#/sec] (mean)
[kiosk@foundation12 Desktop]$ ab -c 1 -n 1000 http://172.25.12.1/example.php
Time taken for tests: 0.405 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Requests per second: 2468.97 [#/sec] (mean)
[kiosk@foundation12 Desktop]$ ab -c 1 -n 1000 http://172.25.12.1/index.php
Time taken for tests: 0.491 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Requests per second: 2037.92 [#/sec] (mean)
[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]# vim /etc/profile
##写入配置文件,source命令当前shell环境加载
export JAVA_HOME=/usr/local/java
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin
[root@server1 ~]# source /etc/profile
[root@server1 ~]# . /etc/profile ##在当前shell更新环境变量
[root@server1 ~]# sh /etc/profile ##在新的shell中更新环境变量
##加载后查看是否成功
[root@server1 local]# echo $JAVA_HOME
/usr/local/java
[root@server1 local]# echo $CLASSPATH
.:/usr/local/java/lib:/usr/local/java/jre/lib
[root@server1 local]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin/:/usr/local/java/bin
[root@server1 ~]# vim test.java
##java语言格式
public class test {
public static void main(String[] args){
System.out.println("Hello World!");
}
}
##javac编译".java"脚本,java运行脚本
[root@server1 ~]# javac test.java
[root@server1 ~]# java test
Hello World!
[root@server1 ~]# tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/
[root@server1 ~]# cd /usr/local/
[root@server1 local]# ln -s apache-tomcat-7.0.37/ tomcat
[root@server1 ~]# cd /usr/local/tomcat/bin/
[root@server1 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 ROOT]# pwd
/usr/local/tomcat/webapps/ROOT
[root@server1 ROOT]# vim test.jsp
[root@server1 ROOT]# cat test.jsp
the time is: <%=new java.util.Date() %>
[root@server1 ROOT]# vim /usr/local/lnmp/nginx/conf/nginx.conf
48 location / {
49 # root html; ##修改nginx的默认发布目录
50 root /usr/local/tomcat/webapps/ROOT;
51 index index.php index.html index.htm;
52 }
69 location ~ \.jsp$ {
70 proxy_pass http://172.25.12.1:8080;
71 }
[root@server1 ROOT]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server1 ROOT]# nginx
##访问 172.25.12.1/index.jsp 测试
root@server1 ROOT]# vim /usr/local/lnmp/nginx/conf/nginx.conf
20 upstream tomcat {
21 server 172.25.12.1:8080;
22 server 172.25.12.2:8080;
23 }
76 location ~ \.jsp$ {
77 proxy_pass http://tomcat;
78 }
[root@server1 ROOT]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server1 ROOT]# nginx -s reload
[root@server2 ROOT]# cat test.jsp
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.util.*" %>
<html><head><title>Cluster App Testtitle>head>
<body>
Server Info:
<%
out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"
");%>
<%
out.println("
ID " + session.getId()+"
");
String dataName = request.getParameter("dataName");
if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue);
}
out.print("Session list");
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println( name + " = " + value+"
");
System.out.println( name + " = " + value);
}
%>
<form action="test.jsp" method="POST">
name:<input type=text size=20 name="dataName">
<br>
key:<input type=text size=20 name="dataValue">
<br>
<input type=submit>
form>
body>
html>
[root@server1 ROOT]# vim /usr/local/lnmp/nginx/conf/nginx.conf
20 upstream tomcat {
21 ip_hash;
22 server 172.25.12.1:8080;
23 server 172.25.12.2:8080;
24 }
[root@server1 ROOT]# nginx -s reload
cookie测试效果一样,只是原理不同
注意:server1 和 server2 主机保持一致,配置文件稍作修改;
[root@server1 lib]# pwd ##下载模块
/usr/local/tomcat/lib
[root@server1 lib]# ls
annotations-api.jar asm-3.2.jar catalina-ant.jar
catalina-ha.jar catalina.jar catalina-tribes.jar
ecj-4.2.1.jar el-api.jar jasper-el.jar
jasper.jar jsp-api.jar kryo-1.04.jar
kryo-serializers-0.10.jar memcached-session-manager-1.6.3.jar
memcached-session-manager-tc6-1.6.3.jar memcached-session-manager-tc7-1.6.3.jar
minlog-1.2.jar msm-kryo-serializer-1.6.3.jar reflectasm-1.01.jar
servlet-api.jar spymemcached-2.7.3.jar tomcat-api.jar
tomcat-coyote.jar tomcat-dbcp.jar tomcat-i18n-es.jar
tomcat-i18n-fr.jar tomcat-i18n-ja.jar tomcat-jdbc.jar tomcat-util.jar
[root@server1 lib]# rm -fr memcached-session-manager-tc6-1.6.3.jar
[root@server1 lib]# yum install -y memcached
[root@server1 lib]# /etc/init.d/memcached start
Starting memcached: [ OK ]
[root@server1 conf]# pwd
/usr/local/tomcat/conf
[root@server1 conf]# vim context.xml
"de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:172.25.12.1:11211,n2:172.25.12.2:11211"
failoverNodes="n2" ##注意server1主机为 n2,server2主机为 n1!!
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
[root@server1 tomcat]# bin/shutdown.sh
[root@server1 tomcat]# bin/startup.sh
[root@server1 tomcat]# cat logs/catalina.out
##出现下列信息说明ok
INFO: MemcachedSessionService finished initialization, sticky true, operation timeout 1000, with node ids [n2] and failover node ids [n1]
Server Info: 172.25.12.2 : 8080
ID 51EAC4845CCD9734F0D21988CC4A1938-n2
Session listuser2 = 222
user1 =
user4 = 444
user3 = 333
user5 = 555
name:
key:
[root@server2 tomcat]# telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.
get 51EAC4845CCD9734F0D21988CC4A1938-n2
VALUE 51EAC4845CCD9734F0D21988CC4A1938-n2 2048 149
Wdcj�dcj�01dcj�+dcj�=#51EAC4845CCD9734F0D21988CC4A1938-n2user5555user2222user1user4444user3333
END