Memcached安装

下载memcached所需关联包libevent

wget http://www.monkey.org/~provos/libevent-1.2.tar.gz

安装:

tar fvxz libevent-1.2.tar.gz

cd libevent-1.2

./configure –prefix=/usr

make

make install

测试libevent是否安装成功

ls –al /usr/lib |grep libevent


安装memcached

wget http://www.danga.com/memcached/dist/memcached-1.2.0.tar.gz

tar fvxz memcached-1.2.0.tar.gz

cd memcached-1.2.0

./configure –prefix=/usr

make

make install

测试是否安装成功

ls –al /usr/local/bin/mem*


启动memcached

/usr/local/bin/memcached –d –m 10 –c 256 –uroot

连接memcached

telnet IP地址 11211 memcached默认端口)

stats查看


JDK 1.7.0_25安装

Mkdir/usr/java/

Tar fvxz jdk-7u25-linux-x64.tar.gz–C /usr/java

Vim/root/.bash_profile

ll/usr/javajdk版本

将其它注释

添加三条变量

vim/root/.bash_profile

exportJAVA_HOME=/usr/java/jdk1.7.0版本对应

exportPATH=$PATH:$JAVA_HOME/bin

exportCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar

exit

java –version

Tomcat 7.0.42安装

Tar fvxz apache-tomcat-7.0.42.tar.gz–C /usr/local

Cd/usr/local

Mv apache-tomcat-7.0.42tomcat


Nginx 1.5.1安装

yum –yinstall gcc*

yum –yinstall make*

解压 tar fvxz nginx-1.5.1.tar.gz

./configure–prefix=/usr/local/nginx

Yum –yinstall pcre-devel

Yum –yinstall zlib-devel

./configure–prefix=/usr/local/nginx

Make makeinstall

/usr/local/nginx/sbin/nginx

Lsof –i:80




配置Nginx

添加参数:

 tcp_nodelay on;


  client_body_buffer_size  512k;

  proxy_connect_timeout    5;

  proxy_read_timeout       60;

  proxy_send_timeout       5;

  proxy_buffer_size        16k;

  proxy_buffers            4 64k;

  proxy_busy_buffers_size 128k;

  proxy_temp_file_write_size 128k;


   gzipon;

  gzip_min_length  1k;

  gzip_buffers     4 16k;

  gzip_http_version 1.1;

  gzip_comp_level 2;

  gzip_types       text/plainapplication/x-javascript text/css application/xml;

gzip_varyon;


upstreamzkx.9anbi.com  {

               server 192.168.1.11:8080weight=1;

               server 192.168.1.12:8080weight=1;

}

   server {

       listen       80;

 server_name zkx.9anbi.com;


       charset koi8-r;


       #access_log  logs/host.access.log  main;


       location / {

           root   html;

           index  index.html index.htm;

           proxy_pass          http://zkx.9anbi.com;

           proxy_set_header X-Real-IP$remote_addr;

           proxy_set_header Host $host;

       }



       location ~ ^/(WEB-INF)/ {

       deny all;

       }



http://code.google.com/p/memcached-session-manager/downloads/list网站下载memcached所需的jar包放在tomcat/lib

memcached-2.6.jar

memcached-session-manager-1.5.1.jar

memcached-session-manager-tc7-1.5.1.jar

msm-javolution-serializer-1.5.1.jar

msm-kryo-serializer-1.5.1.jar

msm-xstream-serializer-1.5.1.jar

http://memcached-session-manager.googlecode.com/files/javolution-5.4.3.1.jar下载

Javolution-5.4.3.1.jar


tomcat/usr/local/tomcat/conf/context.xml内的段内添加

  memcachedNodes="n1:localhost:11211"

   requestUriIgnorePattern=".*\.(png|gif|jpg|css|js)$"

   sessionBackupAsync="false"

   sessionBackupTimeout="100"

  copyCollectionsForSerialization="false"

  transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"/>

memcachedNodes=配置memcached的节点多个memcached用,分开。Localhost改成memcached所在的IP地址。


两台tomcat必须都下载jar包和添加以上内容


测试nginx+tomcat+memcachedsession共享

在两台tomcat/webapps/Root内写测试页test.jsp

第一台

SessionID:<%=session.getId()%>


SessionIP:<%=request.getServerName()%>


SessionPort:<%=request.getServerPort()%>

<%

out.println("Thisis Tomcat Server 111111");

%>


第二台

SessionID:<%=session.getId()%>


SessionIP:<%=request.getServerName()%>


SessionPort:<%=request.getServerPort()%>

<%

out.println("Thisis Tomcat Server 222222");

%>


打开网页访问nginx

zkx.9anbi.com/test.jsp

反复刷新页面,如果sessionID一直不变,下面的sessionPort的内容不断变化则说明配置成功

nginx+tomcat+memcached的session共享_第1张图片