zoukankan      html  css  js  c++  java
  • Nginx+Tomcat关于Session的管理

    前言

    Nginx+Tomcat对Session的管理一直有了解,但是一直没有实际操作一遍,本文从最简单的安装启动开始,通过实例的方式循序渐进的介绍了几种管理session的方式。

    nginx安装配置

    1.安装nginx

    [root@localhost ~]# yum install nginx

    提示报如下错误:

    No package nginx available.

    解决办法安装epel:EPEL是企业版 Linux 附加软件包的简称,EPEL是一个由Fedora特别兴趣小组创建、维护并管理的,针对 红帽企业版 Linux(RHEL)及其衍生发行版(比如 CentOS、Scientific Linux、Oracle Enterprise Linux)的一个高质量附加软件包项目;

    [root@localhost ~]# yum install epel-release

    安装完之后,即可成功安装nginx;

    2.启动、停止nginx

    先进入nginx的目录

    [root@localhost nginx]# cd /usr/sbin/

    执行命令

    ./nginx 开启
    ./nginx -s stop  使用kill命令强制杀掉进程
    ./nginx -s quit  待nginx进程处理任务完毕进行停止
    ./nginx -s reload

    nginx+tomcat负载均衡

    1.准备2个tomcat,分别指定端口为8081,8082

    drwxr-xr-x. 9 root root      4096 May  7 14:16 apache-tomcat-7.0.88_8081
    drwxr-xr-x. 9 root root      4096 May  7 14:16 apache-tomcat-7.0.88_8082

    修改webapps/ROOT的index.jsp,方便测试

    <%
    if(request.getSession().getAttribute("key")==null){
       out.println("key is null,ready init.....");   
       request.getSession().setAttribute("key","value");
    }else{
       out.println("key is not null,key="+request.getSession().getAttribute("key"));  
    }
    %>
    <br> 
    sessionID:<%=session.getId()%>   
    <br>   
    sessionCreateTime:<%= session.getCreationTime() %>
    <br>
    <% 
    out.println("tomcat port 8081");   
    %> 

    最后的输出在两个tomcat下面指定各自的端口号8081和8082

    2.nginx配置负载均衡(默认策略)

    修改/etc/nginx/下面的nginx.conf

  • 相关阅读:
    数据收集
    数据展现
    一场媲美“超女”海选的招聘狂潮
    时机论:早起的鸟儿也要选对“用户”季节
    程序设计实践(评注版) 评注者序
    “三低”用户养活的互联网
    芯故事 心感动:英特尔企业文化的力量
    初始化游戏状态数据
    初始化游戏状态数据二
    几个常用的JavaScript字符串处理函数 – split()、join()、substring()和indexOf()
  • 原文地址:https://www.cnblogs.com/jpfss/p/10281011.html
Copyright © 2011-2022 走看看