一、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. Ssm框架常见报错

    错误1: The origin server did not find a current representation for the target resource or is not willi ...

  2. ubuntu ufw防火墙

    由于LInux原始的防火墙工具iptables过于繁琐,所以ubuntu默认提供了一个基于iptable之上的防火墙工具ufw. ubuntu 9.10默认的便是UFW防火墙,它已经支持界面操作了.在 ...

  3. ubuntu17.10 安装ssh

    sudo apt-get install openssh-server sudo /etc/init.d/ssh start

  4. 3D 点云特征

    博客参考: https://blog.csdn.net/shaozhenghan/article/details/81346585 和 https://www.cnblogs.com/li-yao77 ...

  5. qt4代码到qt5代码出错

    1.error C2039: “toAscii”: 不是“QString”的成员 QT5.0.1把这个函数取消掉了,可以用toLatin1这个函数

  6. Java 设计模式系列(十五)观察者模式(Observer)

    Java 设计模式系列(十五)观察者模式(Observer) Java 设计模式系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) Java ...

  7. setPadding 与 setBackgroundDrawable

    这两个不能同时用,如果同时用,setPadding 将不会起作用,用的是 drawable里面自带的padding

  8. JAVA array,map 转 json 字符串

    public class User { private String username; private String password; public String getUsername() { ...

  9. [C#] == VS Equals

    声明:本篇博客翻译自:https://www.codeproject.com/Articles/1111680/equalsequals-VS-Equals-in-Csharp 由于水平(技术水平+英 ...

  10. task:scheduled cron 合法

    http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html task:scheduled o ...