Centos7 nginx的负载均衡概念与配置
一.负载均衡概念
负载均衡(Server Load Balancer)是将访问流量根据转发策略分发到后端多台 ECS 的流量分发控制服务。负载均衡可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。
负载均衡主要有如下几个功能点:
(1)负载均衡服务通过设置虚拟服务地址(IP),将位于同一地域(Region)的多台云服务器(Elastic Compute Service,简称ECS)资源虚拟成一个高性能、高可用的应用服务池;根据应用指定的方式,将来自客户端的网络请求分发到云服务器池中。
(2)负载均衡服务会检查云服务器池中ECS的健康状态,自动隔离异常状态的ECS,从而解决了单台ECS的单点问题,同时提高了应用的整体服务能力。在标准的负载均衡功能之外,负载均衡服务还具备TCP与HTTP抗DDoS攻击的特性,增强了应用服务器的防护能力。
(3)负载均衡服务是ECS面向多机方案的一个配套服务,需要同ECS结合使用。
二.负载均衡配置
1.首选准备三台服务器
分别是:
负载均衡调度器:192.168.1.208
WEB服务器1 :192.168.1.209
WEB服务器2 :192.168.1.197
2.将两个web服务器进行nginx网站部署
关于nginx部署web服务不多做介绍,需要的话详见:
WEB服务器1 :192.168.1.208
这边部署了豆瓣主页的网页:访问效果如下

WEB服务器2 :192.168.1.197
这边部署了斗鱼主页的网页:访问效果如下

3.对负责均衡调度器进行配置
配置如下:
#user nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on;
upstream web_upstream{
server 192.168.1.197;
server 192.168.1.209;
server www.maoyan.com;
}
server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
proxy_pass http://web_upstream;
root html;
index souhu.html index.htm;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }
其实就是这样:
在http代码块里面,添加配置
upstream web_upstram {
server 192.168.1.197;
server 192.168.1.209;
}
在location代码块内,添加
location / {
proxy_pass http://web_upstram;
root html;
index index.html index.htm;
}
在上面多加了一个负载均衡www.maoyan.com
4.测试负责均衡调度器
对负责均衡调度器:192.168.1.208进行访问
(1)测试1

(2)测试2

(3)测试3 这个测试中,因为用的是真的官网猫眼,可能是猫眼设置了代理屏蔽等,所有出现页面不存在问题

以上说明,访问负载均衡调度器,负责均衡生效,这样在生产中,每台web服务器部署相同的web服务,如果一台服务器挂了,就不会造成影响线上服务了.
Centos7 nginx的负载均衡概念与配置的更多相关文章
- Nginx专题(2):Nginx的负载均衡策略及其配置
本文介绍了Nginx的负载均衡策略,一致性hash分配原理,及常用的故障节点的摘除与恢复配置. 文章来源:宜信技术学院 & 宜信支付结算团队技术分享第一期-宜信支付结算八方数据团队高级技术经理 ...
- Centos7下lvs负载均衡lvs-tun模式配置
一.架构 director:172.28.18.69 vip:172.28.18.70 real server1:172.28.18.71 real server2:172.28.18.78 二.两台 ...
- Nginx之负载均衡配置(一)
前文我们聊了下nginx作为反向代理服务器,代理后端动态应用服务器的配置,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/12430543.html:今天我们来聊 ...
- Nginx网络负载均衡,负载均衡,网络负载,网络均衡
本节就聊聊采用Nginx负载均衡之后碰到的问题: Session问题 文件上传下载 通常解决服务器负载问题,都会通过多服务器分载来解决.常见的解决方案有: 网站入口通过分站链接负载(天空软件站,华军软 ...
- Nginx的负载均衡的几种方式
Nginx的负载均衡的那点事 本节就聊聊采用Nginx负载均衡之后碰到的问题: Session问题 文件上传下载 通常解决服务器负载问题,都会通过多服务器分载来解决.常见的解决方案有: 网站入口通过分 ...
- nginx的负载均衡的问题
本节就聊聊采用Nginx负载均衡之后碰到的问题: Session问题 文件上传下载 通常解决服务器负载问题,都会通过多服务器分载来解决.常见的解决方案有: 网站入口通过分站链接负载(天空软件站,华军软 ...
- Nginx + Tomcat 负载均衡配置详解
Nginx常用操作指南一.Nginx 与 Tomcat 安装.配置及优化1. 检查和安装依赖项 yum -y install gcc pcre pcre-devel zlib zlib-devel o ...
- 干货 | Nginx负载均衡原理及配置实例
一个执着于技术的公众号 Nginx系列导读 给小白的 Nginx 10分钟入门指南 Nginx编译安装及常用命令 完全卸载nginx的详细步骤 Nginx 配置文件详解 理解正向代理与反向代理的区别 ...
- Nginx负载均衡的详细配置及使用案例详解.
感谢看过这一些列博文和评论的小伙伴, 我把自己所看到的学到的拿到这里来分享是想和大家一起学习进步, 想听听园友给出的意见, 也是对自己学习过程的一个总结. 技术无止境, 我们仍需努力! 1,话不多说, ...
随机推荐
- [踩坑记录] windows10 应用商店打不开 代码: 0x80131500
在某博客看到的方法,供参考,可以尝试一下,我的也是这么解决的1.打开“运行”输入 inetcpl.cpl (“WINDOWS”+“R”键,输入 inetcpl.cpl亦可)2.点开高级往下拉,勾上&q ...
- 吴裕雄--天生自然神经网络与深度学习实战Python+Keras+TensorFlow:TensorFlow与神经网络的实现
import tensorflow as tf import numpy as np ''' 初始化运算图,它包含了上节提到的各个运算单元,它将为W,x,b,h构造运算部件,并将它们连接 起来 ''' ...
- leetcode 697
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the ma ...
- springboot多模块项目打war包
一.父模块配置 1,指定pakaging:pom 2,指定编译的版本:如下图: <properties> <project.build.sourceEncoding>UTF-8 ...
- Plastic Bottle Manufacturer Tips - Attention To Plastic Bottle Processing Technology
In fact, the processing technology of plastic bottles is actually quite strict. In fact, regular man ...
- ROS学习资源
1.ROS机器人操作系统自主学习实践环境 https://www.shiyanlou.com/courses/854 2.ROS官方网站 http://wiki.ros.org/ ROS中文官方网站 ...
- JDBC statement的常用方法
Statement接口: 用于执行静态SQL语句并返回它所生成结果的对象. 三种Statement类: Statement: 由createStatement创建,用于发送简单的SQL语句(最好是不带 ...
- JavaSE复习~基本数据类型
数据类型 java有两大类数据类型:基本数据类型 和 引用数据类型 基本数据类型 整数型:byte.short.int.long 浮点型:float.double 字符型:char 布尔型:boole ...
- WinForm开发(4)——使用Visual-Studio-2010-打包安装程序
打包程序: 1,解决方案—右键菜单“添加”—新建项目—其他项目类型—安装和部署—Visual Studio Installer—安装项目,输入名称Setup1,点“确定” 2,添加开始程序中的文件夹: ...
- springmvc项目的搭建
springmvc替代servlet的工作 Servlet - Springmvc jsp ->Servlet (Springmvc)->Jsp springmvc配置文件 ...