• 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

  • 相关阅读:
    编写有效用例_阅读笔记05
    编写有效用例_阅读笔记04
    编写有效用例_阅读笔记03
    编写有效用例_阅读笔记02
    软件需求与分析课堂讨论一
    编写有效用例_阅读笔记01
    问题账户需求分析
    【知识总结】动态 DP
    【知识总结】数论全家桶
    【知识总结】多项式全家桶(三点五)(拆系数解决任意模数多项式卷积)
  • 原文地址:https://www.cnblogs.com/jpfss/p/10281011.html
Copyright © 2020-2023  润新知