tomcat+nginx+memcache
Posted 正义的朋友
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tomcat+nginx+memcache相关的知识,希望对你有一定的参考价值。
tomcat安装
tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/
cd /usr/local/
ln -s jdk1.7.0_79/ java
]# vim /etc/profile 添加如下:
export JAVA_HOME=/usr/local/java
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
echo $JAVA_HOME
/usr/local/java
echo $CLASSPATH
.:/usr/local/java/lib:/usr/local/java/jre/lib
echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/nginx/sbin:/usr/local/java/bin
/etc/init.d/php-fpm start
Starting php-fpm done
nginx
cd
which java
/usr/local/java/bin/java
which javac
/usr/local/java/bin/javac
vim test.java
javac test.java
java test
# tar zxf apache-tomcat-7.0.90.tar.gz -C /usr/local/
cd /usr/local/
ln -s apache-tomcat-7.0.90/ tomcat
ll
cd tomcat/
bin/startup.sh
netstat -antlp
访问172.25.8.5:8080
cd /usr/local/tomcat/webapps/ROOT/
vim test.jsp
访问172.25.8.1:8080/test.jsp
nginx修改配置实现轮循
cd /usr/local/lnmp/nginx/conf/
vim nginx.conf
nginx -s reload
在server1中:
tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/
tar zxf apache-tomcat-7.0.90.tar.gz -C /usr/local
cd /usr/local/
ln -s jdk1.7.0_79/ java
ln -s apache-tomcat-7.0.90/ tomcat
vim /etc/profile
source /etc/profile
cd /usr/local/tomcat/
bin/startup.sh
cd /usr/local/tomcat/webapps/ROOT/
vim test.jsp
访问172.25.8.5/test.jsp 此时出现轮循
yum install memcached -y
/etc/init.d/memcached start
cd /usr/local/tomcat/conf/
vim context.xml(在两个节点处都写入,节点根据ip地址对应写入)
然后将jar包放入/usr/local/tomcat/lib中,
并在server1和server5中yum install telnet -y
cd /usr/local/tomcat/webapps/ROOT/
vim 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);
}
%>
<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
cd /usr/local/lnmp/nginx/conf
vim nginx.conf
添加了sticky算法
nginx -s reload 重新读取
然后访问172.25.8.1/test.jsp
将server1tomcat停掉
继续写入:
Ok
以上是关于tomcat+nginx+memcache的主要内容,如果未能解决你的问题,请参考以下文章