Nginx+Tomcat负载均衡群集
一、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负载均衡群集的更多相关文章
- Nginx+Tomcat负载均衡、动静分离群集
Nginx+Tomcat负载均衡.动静分离群集 目录 Nginx+Tomcat负载均衡.动静分离群集 一.Tomcat 1. Tomcat简介 2. Tomcat重要目录 二.Nginx负载均衡原理 ...
- nginx+tomcat负载均衡
最近练习nginx+tomcat负载均衡.根据一些资料整理了大体思路,最终实现了1个nginx+2个tomcat负载均衡. 安装JDK 1>进入安装目录,给所有用户添加可执行的权限 #chmod ...
- linux+nginx+tomcat负载均衡,实现session同步
linux+nginx+tomcat负载均衡,实现session同步 花了一个上午的时间研究nginx+tomcat的负载均衡测试,集群环境搭建比较顺利,但是session同步的问题折腾了几个小时才搞 ...
- Nginx + Tomcat 负载均衡配置详解
Nginx常用操作指南一.Nginx 与 Tomcat 安装.配置及优化1. 检查和安装依赖项 yum -y install gcc pcre pcre-devel zlib zlib-devel o ...
- Linux下Nginx+Tomcat负载均衡和动静分离配置要点
本文使用的Linux发行版:CentOS6.7 下载地址:https://wiki.centos.org/Download 一.安装Nginx 下载源:wget http://nginx.org/pa ...
- Nginx+tomcat负载均衡时静态页面报404
百度到的问题解决BLOG http://os.51cto.com/art/201204/326843.htm nginx+2台tomcat负载均衡,应用程序已部署,单独访问tomcat时,可以访问到所 ...
- 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 ...
- nginx+tomcat负载均衡和session复制
本文介绍下传统的tomcat负载均衡和session复制. session复制是基于JVM内存的,当然在当今的互联网大数据时代,有更好的替代方案,如将session数据保存在Redis中. 1.安装n ...
- nginx+tomcat负载均衡实验
导言: 本次实验,tomcat就直接使用录原生的主页,只是简单修改主页识别主机,nginx也是直接在欢迎页上面修改的,直接实现负载均衡. 主机1:192.168.100.156 nginx+tomca ...
随机推荐
- Layer Comps
[What is Layer Comps] Designers often create multiple compositions(comps) of a page layout to show c ...
- Android开发之百度地图的简单使用
越来越多的App运用到了定位,导航的这些功能,其实实现一个自己的百度地图也是非常的简单,这篇博客将会教你简单的实现一个百度地图.看一下效果图: 第一步:要使用百度地图,必须要有百度地图的Key,要获得 ...
- [leetcode]253. Meeting Rooms II 会议室II
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- Linux内核分析 - 网络[十四]:IP选项
Linux内核分析 - 网络[十四]:IP选项 标签: linux内核网络structsocketdst 2012-04-25 17:14 5639人阅读 评论(1) 收藏 举报 分类: 内核协议栈 ...
- Java程序设计8——抽象类、接口与内部类
1 抽象类 当编写一个类时,常常会为该类定义一些方法,这些方法用以描述该类的行为方式,那么这些方法都有具体的方法体.但在某些情况下,某个父类并不需要实现,因为它只需要当做一个模板,而具体的实现,可以由 ...
- swift pop实现动感按钮动画
// // MyButton.swift // PopInstall // // Created by su on 15/12/11. // Copyright © 2015年 tian. A ...
- 如何在Windows环境下安装Linux系统虚拟机
如何在Windows环境下安装Linux系统虚拟机 本篇经验写给想要入门学习C语言的小白们.Windows系统因为使用窗口图形化,操作简单,功能多样,所以我们在Windows环境下可以做到很多,但想要 ...
- java程序练习
数组求和作业 开发环境:java 工具:eclipse 两种数据类型excel和csv 在同学建议下,我选择用csv文件打开,这就引来了第一个问题,在java中如何调用csv文件.以下是我百度的结果 ...
- memory leak-----tomcat日志warn
web应用借助于结构:spring mvc + quartz结构,部署到tomcat容器时,shutdown时的error信息: appears to have started a thread na ...
- Solr 从文件创建索引
http://blog.csdn.net/clj198606061111/article/details/21492457 http://wiki.apache.org/solr/Extracting ...