zoukankan      html  css  js  c++  java
  • 160513、nginx+tomcat集群+session共享(linux)

    第一步:linux中多个tomcat安装和jdk安装(略)

    第二步:nginx安装,linux中安装nginx和windows上有点不同也容易出错,需要编译,这里做介绍

    一、安装依赖

    gcc

    openssl-fips-2.0.2.tar.gz

    zlib-1.2.7.tar.gz

    pcre-8.21.tar.gz

    下载linux版本的安装包,如果不下载安装包,可以在线安装命令:

    yum install gcc-c++

    yum install -y pcre  pcre-devel

    yum install -y zlib zlib-devel

    yum install -y openssl openssl-devel

    如下通过安装包安装(下面是其中的一个例子)

    [root@localhost ~]# tar -zxvf openssl-fips-2.0.2.tar.gz 
    [root@localhost ~]# cd openssl-fips-2.0.2
    [root@localhost openssl-fips-2.0.2]# ./config [root@localhost openssl-fips-2.0.2]# make
    [root@localhost openssl-fips-2.0.2]# make install

    二、下载并安装nginx

    下载 nginx-1.2.6.tar.gz

    [root@localhost nginx-1.2.6]# ./configure
    --with-pcre=../pcre-8.21
     --with-zlib=../zlib-1.2.7
     --with-openssl=../openssl-fips-2.0.2
    [root@localhost nginx-1.2.6]# make
    [root@localhost nginx-1.2.6]# make install

     至此Nginx的安装完成!

    去到niginx的sbin目录检验是否成功

     

    [root@localhost nginx-1.2.6]# cd  /usr/local/nginx/sbin
    [root@localhost sbin]# ./nginx -t

    启动nginx(去到sbin目录下执行下面的命令)

    [root@localhost sbin]# ./nginx

    第三步:配置几个tomcat,每个里面分别将server.xml中8080,8005,8009这几个地方修改掉就可以了

    第四步:修改nginx.conf(注意添加红色部分就可以了)

    worker_processes  1;

    events {

        worker_connections  1024;

    }

    http {

        include       mime.types;

        default_type  application/octet-stream;

        sendfile        on;

        keepalive_timeout  65;

    upstream server_lb{#server_lb跟下面的一样

    server localhost:8090;#这里是tomcat的地址

    server localhost:8091;

    }

        server {

            listen       80;

            server_name  localhost;

            location / {

                root   html;

        proxy_pass http://server_lb;

                index  index.html index.htm index.jspf index.jsp;

        proxy_redirect  default;

            }

            error_page   500 502 503 504  /50x.html;

            location = /50x.html {

                root   html;

            }

        }

    }

    至此,nginx+tomcat集群就完成了,可以通过访问http://localhost来查看

    第五步:session共享,因为在linux中不支持tomcat的广播机制,所以不能像windows中使用修改web.xml和servcer.xml来实现(前面文章中有介绍)。我需要借助mencache或redis等技术来实现。这个技术在后面将会介绍。这里分享给大家一个redis学习视频,大家可以先了解。

    注:另外附上我搜集的redis教学视频,给需要的人...

  • 相关阅读:
    宽屏手机显示9.png的图片拉伸不均衡
    android中 System.exit(0)的理解
    android 由于界面控件过多耗时处理办法
    iOS开发笔记--sqlite3 语句总结
    iOS开发笔记--iOS应用架构谈
    iOS开发笔记--iOS 学习资料整理
    iOS开发笔记--iOS、mac开源项目及库汇总
    iOS开发笔记--iphone练习之手势识别(双击、捏、旋转、拖动、划动、长按)UITapGestureRecognize
    iOS开发笔记--Masonry介绍与使用实践:快速上手Autolayout
    iOS开发笔记--使用CocoaPods来管理iOS项目的依赖库
  • 原文地址:https://www.cnblogs.com/zrbfree/p/5495766.html
Copyright © 2011-2022 走看看