nginx memcache Tomcat

来源:互联网 发布:淘宝培训机构 编辑:程序博客网 时间:2024/05/22 10:25

node1:172.25.50.1 nginx Tomcat memcached
node2:172.25.50.2 Tomcat memcached

这里写图片描述
<下图来自于网络>
这里写图片描述

一、memcache
安装包:memcache-2.2.5.tgz
解压
配置

vim ~/.bash_profile  --> PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/binsource ~/.bash_profilephpize./configure --enable-memcache       //编译make        make installvim /usr/local/lnmp/php/etc/php.ini    --> 851 extension=memcache.socd /memcache-2.2.5    vim memcache.php    -->23 define('ADMIN_PASSWORD','westos');      // Admin Password    28 $MEMCACHE_SERVERS[] = '172.25.50.1:11211'; // add more as an array    cp example.php memcache.php /usr/local/lnmp/nginx/htmlyum install memcached -y    //并且打开服务

测试:
这里写图片描述
这里写图片描述

二、Tomcat
安装包:
apache-tomcat-7.0.37.tar.gz jdk-7u79-linux-x64.tar.gz
jdk:Java语言的软件开发工具包
tomcat:应用(Java)服务器,是apache的扩展
解压
配置

tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/    cd /usr/local    ln -s jdk1.7.0_79/ javavim /etc/profile    -->  80 export JAVA_HOME=/usr/local/java         81 export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib         82 export PATH=$PATH:$JAVA_HOME/bin

测试java包是否安装好,写一个java脚本,再进行编译测试。
vim test.java
–> public class test
{
public static void main(String[] args){
System.out.println(“Hello World!”);
}
}

javac test.java[root@server1 ~]# java testHello world!
tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local    cd /usr/local    ln -s apache-tomcat-7.0.37/ tomcat##开启tomcat                      ##为8080端口##  为tomcat目录下的bin/startup.sh##  关闭为bin/shutdown.shvim /usr/local/lnmp/nginx/conf/nginx.conf    --> 70         location ~ \.jsp$ {        71                 proxy_pass http://172.25.50.1:8080;        72         }  

测试是否安装成功:
这里写图片描述
也可写一个脚本测试:

vim /usr/local/tomcat/webapps/ROOT/test.jsp    -->server1 time is: <%= new java.util.Date() %>

这里写图片描述
将jar目录中的内容全部放在tomcat下面的lib中,删除掉memcached-session-manager-tc6-1.5.1.jar

vim /usr/local/tomcat/conf/context.xml  //在最后加上    <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"    memcachedNodes="172.25.50.1:11211,n2:172.25.50.2:11211"    failoverNodes="n1" #在node2上此项设置为“n2”    requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"    transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"    />启动该服务的命令为 /usr/local/tomcat/bin/startup.sh关闭命令为       /usr/local/tomcat/bin/shutdown.sh

三、配置nginx

vim /usr/local/lnmp/nginx/conf/nginx.conf--> http {        upstream westos {        sticky;        server 172.25.50.1:8080;        server 172.25.50.2:8080;    }    location ~ \.jsp$ {     proxy_pass http://westos;    }

最后也可以自写测试页
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);}%><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>
原创粉丝点击