一、Nginx负载均衡原理

  目前很多大型网站都应用Nginx服务器作为后端网站程序的反向代理及负载均衡器,提升整个站点的负载并发能力

  Nginx负载均衡是通过反向代理实现的

  

二、部署Tomcat 

  本案例以Nginx作为负载均衡器,Tomcat作为应用服务器,具体安装方法请见本人其他文章

  此案例为了测试搭建两个内容不同的网站可以创建/web/webapp1目录,修改server.xml,将网站文件目录更改到/web/webapp1/路径下,并建立测试页index.jsp,进行测试。

三、部署Nginx

 安装Nginx
[root@localhost ~]# yum -y install pcre-devel zlib-devel
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
[root@localhost ~]# tar -zxvf nginx-1.6.0.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/nginx-1.6.0/
[root@localhost nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --
group=nginx --with-file-aio --with-http_stub_status_module --with-http_gzip_static_module --
with-http_flv_module --with-http_ssl_module
[root@localhost nginx-1.6.0]# make && make install
[root@localhost ~]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@localhost ~]# nginx -t
[root@localhost ~]# nginx
[root@localhost ~]# netstat -anpt | grep 80
[root@localhost ~]# killall -s HUP nginx
[root@localhost ~]# killall -s QUIT nginx
[root@localhost ~]# nginx
验证:
[root@localhost ~]# firefox http://localhost/ & 设置权重
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
在http{ }中添加:
upstream tomcat_server {
server 192.168.1.10:8080 weight=1; #两台服务器权重相同,为轮询算法
server 192.168.1.20:8080 weight=1; #两台服务器权重相同,为轮询算法
}
location / { }中添加:
proxy_pass http://tomcat_server; #访问请求转发给Tomcat 重启Nginx服务
[root@localhost ~]# killall -s QUIT nginx
[root@localhost ~]# nginx
[root@localhost ~]# netstat -anpt | grep nginx 验证
[root@localhost ~]# firefox http://192.168.1.1/ &
验证结果:分别显示Tomcat1和Tomcat2上的网站页面。

Nginx+Tomcat负载均衡群集的更多相关文章

  1. Nginx+Tomcat负载均衡、动静分离群集

    Nginx+Tomcat负载均衡.动静分离群集 目录 Nginx+Tomcat负载均衡.动静分离群集 一.Tomcat 1. Tomcat简介 2. Tomcat重要目录 二.Nginx负载均衡原理 ...

  2. nginx+tomcat负载均衡

    最近练习nginx+tomcat负载均衡.根据一些资料整理了大体思路,最终实现了1个nginx+2个tomcat负载均衡. 安装JDK 1>进入安装目录,给所有用户添加可执行的权限 #chmod ...

  3. linux+nginx+tomcat负载均衡,实现session同步

    linux+nginx+tomcat负载均衡,实现session同步 花了一个上午的时间研究nginx+tomcat的负载均衡测试,集群环境搭建比较顺利,但是session同步的问题折腾了几个小时才搞 ...

  4. Nginx + Tomcat 负载均衡配置详解

    Nginx常用操作指南一.Nginx 与 Tomcat 安装.配置及优化1. 检查和安装依赖项 yum -y install gcc pcre pcre-devel zlib zlib-devel o ...

  5. Linux下Nginx+Tomcat负载均衡和动静分离配置要点

    本文使用的Linux发行版:CentOS6.7 下载地址:https://wiki.centos.org/Download 一.安装Nginx 下载源:wget http://nginx.org/pa ...

  6. Nginx+tomcat负载均衡时静态页面报404

    百度到的问题解决BLOG http://os.51cto.com/art/201204/326843.htm nginx+2台tomcat负载均衡,应用程序已部署,单独访问tomcat时,可以访问到所 ...

  7. nginx+tomcat负载均衡策略

    測试环境均为本地,測试软件为: nginx-1.6.0,apache-tomcat-7.0.42-1.apache-tomcat-7.0.42-2.apache-tomcat-7.0.42-3 利用n ...

  8. nginx+tomcat负载均衡和session复制

    本文介绍下传统的tomcat负载均衡和session复制. session复制是基于JVM内存的,当然在当今的互联网大数据时代,有更好的替代方案,如将session数据保存在Redis中. 1.安装n ...

  9. nginx+tomcat负载均衡实验

    导言: 本次实验,tomcat就直接使用录原生的主页,只是简单修改主页识别主机,nginx也是直接在欢迎页上面修改的,直接实现负载均衡. 主机1:192.168.100.156 nginx+tomca ...

随机推荐

  1. Add words to your picture

    [Add words to your picture] How to add text to your photo, and then style it with the Type tool. 1.O ...

  2. 46. Permutations (Back-Track,Sort)

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...

  3. for 续7

    ----------siwuxie095                 for 中的变量:     FOR 变量参照的替换已被增强.您现在可以使用下列选项语法: ~I - 删除任何引号(" ...

  4. SQLSERVER CROSS APPLY 与 OUTER APPLY 的应用

    日常开发中遇到多表查询时,首先会想到 INNER JOIN 或 LEFT OUTER JOIN 等等,但是这两种查询有时候不能满足需求.比如,左表一条关联右表多条记录时,我需要控制右表的某一条或多条记 ...

  5. java关于split分割字符串,空的字符串不能得到的问题

    java关于split分割字符串,空的字符串不能得到的问题   class T { public static void main(String args[]) { String num[] = ne ...

  6. ACTIVIT 5.15.1修改记录

    1.ProcessDefinitionEntity 将 protected transient ActivitiEventSupport eventSupport; 修改成: protected  A ...

  7. spark standalone集群部署 实践记录

    本文记录了一次搭建spark-standalone模式集群的过程,我准备了3个虚拟机服务器,三个centos系统的虚拟机. 环境准备: -每台上安装java1.8 -以及scala2.11.x (x代 ...

  8. jquery.fn.extend() 与 $.jquery 作用及区别

    原文:http://www.cnblogs.com/liu-l/p/3928373.html jQuery.extend()这个方法,主要是用来拓展个全局函数啦,例如$.ajax()这种,要不就是拓展 ...

  9. C++ 的Tool工具收集

    C++ 的Tool工具收集 1. muparser - Fast Math Parser Library 数学公式解析函数,开源工具库 网址: http://muparser.beltoforion. ...

  10. 在spark中启动standalone集群模式cluster问题

    spark-submit --master spark://master:7077 --deploy-mode cluster --driver-cores 2 --driver-memory 100 ...