一、启动tomcat
1.安装jdk
Server2和server3
24 tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local
25 cd/usr/local/
26 ls
27 ln-s jdk1.7.0_79/ java ###建立软链接
28 ls
29 vim /etc/profile ###系统的环境变量
exportJAVA_HOME=/usr/local/java
exportCLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
exportPATH=$PATH:$JAVA_HOME/bin
30 source /etc/profile
31 cd
32 vim test.java
public class test{
public static void main(String[] arge){
System.out.println("helloworld");
}
}
33 javac test.java ###编写java文件
34 java test
35 tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local
36 cd/usr/local/
37 ls
38 ln-s apache-tomcat-7.0.37/ tomcat ###建立软链接
39 ls
40 cdtomcat/
41 ls
42 cdbin/
43 ls
44 netstat -antlp
45 ./startup.sh
46 netstat -antlp
48 cd/usr/local/tomcat/webapps/ROOT
49 ls
50 vim test.jsp
the time is:<%=new java.util.Date()%>
测试:物理机浏览器:
二、nginx->tomcat(无缓存)
Server1
2 cd/usr/local/lnmp/nginx/
3 ls
4 cd conf
5 /etc/init.d/php-fpm start
7 nginx
8 vim nginx.conf
location ~\.jsp${
proxy_pass http://172.25.21.2:8080
}
9 nginx -t
18 nginx -s reload
测试:输入ip:
输入ip/test.jsp:只能看到server2
21 vim nginx.conf
截图:
22 nginx-t
23 nginx -s reload
测试:输入ip/test.jsp:可以server2和server3
在server2和server3操作:粘贴:
在 /usr/local/tomcat/webapps/ROOT/test.jsp里
复制粘贴
<%@ pagecontentType="text/html; charset=GBK" %>
<%@ pageimport="java.util.*" %>
<html><head><title>ClusterApp 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>Sessionlist</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);
}
%>
<formaction="test.jsp" method="POST">
name:<inputtype=text size=20 name="dataName">
<br>
key:<inputtype=text size=20 name="dataValue">
<br>
<inputtype=submit>
</form>
</body>
</html>
测试:你可以看到:如下图 你输入内容存储方式是轮询。
24 vim nginx.conf
取消ip_hash的注释
25 nginx -s reload
测试 :你输入内容是存储是在一个上,只有一个挂了,才会切到另一个。
三、Nginx+tomcat+memcache
物理机;
scp jar/* root@172.25.21.3:/usr/local/tomcat/lib
scp jar/* root@172.25.21.2:/usr/local/tomcat/lib
Server2,server3同理
[root@server2 ~]#yum install memcached -y
root@server2 ~]#/etc/init.d/memcached start
[root@server2 ~]#cd /usr/local/tomcat/lib
[root@server2lib]# ls
[root@server2lib]# rm -fr memcached-session-manager-tc6-1.6.3.jar
[root@server2lib]# cd ..
[root@server2tomcat]# ls
[root@server2tomcat]# bin/shutdown.sh
[root@server2tomcat]# bin/startup.sh
[root@server2tomcat]# tail -f logs/catalina.out
[root@server2tomcat]# telnet localhost 11211
[root@server3tomcat]# /etc/init.d/memcached stop
Server2和server3
vim /usr/local/tomcat/conf/context.xml
<Context>
......
<ManagerclassName="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:192.168.0.91:11211,n2:192.168.0.92:11211"
failoverNodes="n1"
#在 node2 上此项设置为“n2”
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>
/usr/local/tomcat/bin/startup.sh启动 tomcat
/usr/local/tomcat/bin/shutdown.sh 关闭 tomcat
memcached 安装
yum installmemcached -y
service memcachedstart
测试;
tail -f logs/catalina.out
四、添加sticky
解压sticky模块包、重新安装nginx
server1:
34 tar zxf nginx-1.10.1.tar.gz
39 tar zxf nginx-goodies-nginx-sticky-module-ng-c78b7dd79d0d.tar.gz
41 cdnginx-1.10.1
44 ./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-threads --with-file-aio--with-http_ssl_module --with-http_stub_status_module--add-module=/root/nginx-goodies-nginx-sticky-module-ng-c78b7dd79d0d
45 make
47 make install
56 cd/opt/nginx/
57 ls
58 cdconf
59 ls
60 vim nginx.conf
location ~ \.jsp${
proxy_pass http://westos;
upstream westos{
sticky;
server 172.25.21.2:8080;
server 172.25.21.3:8080;
}
61 nginx -t
62 nginx -s reload
测试: