一、nginx负载均衡集群介绍:

1.反向代理与负载均衡概念简介
严格地说, nginx仅仅是作为 Nginx Proxy反向代理使用的,因为这个反向代理功能表现的效果是负载均衡集群的效果,所以本文称之为nginx负载均衡。那么,反向代理和负载均衡有什么区别呢?
普通负载均衡软件,例如大名鼎鼎的LVS,其实现的功能只是对请求数据包的转发(也可能会改写数据包)、传递,其中DR模式明显的特征是从负载均衡下面的节点服务器来看,接收到的请求还是来自访问负载均衡器的客户端的真实用户,而反向代理就不样了,反向代理接收访问用户的请求后,会代理用户重新发起请求代理下的节点服务器,最后把数据返回给客户端用户,在节点服务器看来,访问的节点服务器的客户端用户就是反向代理服务器了,而非真实的网站访问用户。句话,LVS等的负载均衡是转发用户请求的数据包,而 nginx反向代理是接收用户的请求然后重新发起请求去请求其后面的节点。

2、实现负载均衡的组件说明:

实现负载均衡的组件主要有两个:

ngx_http_proxy_module           proxy代理模块,用于把请求后抛给服务器节点或upstream服务器池
ngx_http_upstream_module 负载均衡模块,可以实现网站的负载均衡功能及结点的健康检查

二、环境准备:

系统:CentOS Linux release 7.5.1804 (Core)
LB01    192.168.100.105        nginx主负载均衡器
LB02    192.168.100.106        nginx辅负载均衡器
Web01    192.168.100.107        Web01服务器
Web02    192.168.100.108        Web02服务器

nginx版本:1.8.1

三、安装nginx软件
在以上4台服务器上安装nginx

编译安装nginx请参考:https://www.cnblogs.com/Mr-Ding/p/9502529.html

nginx启动脚本参考:https://www.cnblogs.com/Mr-Ding/p/9502972.html

四、配置用于测试的web服务

nginx web01和web02配置如下:

cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
access_log logs/access.log main;
}
} 重启服务:
systemctl reload nginx web01下面写入:
[root@web01 conf]# echo "192.168.100.107" > ../html/index.html web02下面写入:
[root@web02 conf]# echo "192.168.100.108" > ../html/index.html 配置hosts: web01:
[root@web01 conf]# tail -1 /etc/hosts
192.168.100.107 www.dmtest.com web02:
[root@web02 conf]# tail -1 /etc/hosts
192.168.100.108 www.dmtest.com 测试:
[root@web01 conf]# curl www.dmtest.com
192.168.100.107 [root@web02 conf]# curl www.dmtest.com
192.168.100.108

五、 实现一个简单的负载均衡

在LB01上作如下操作:
[root@lb01 conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream www_server_pools { #这里是定义web服务器池,包含了107和108两个web节点;
server 192.168.100.107:80 weight=1;
server 192.168.100.108:80 weight=1;
}
server { #这里是定义代理的负载均衡域名虚拟主机;
listen 80;
server_name www.dmtest.com;
location / {
proxy_pass http://www_server_pools; #访问www.dmtest.com,请求发送给www_server_pools里面的节点;
} }
} 检查语法并重启nginx服务
[root@lb01 conf]# ../sbin/nginx -t
nginx: the configuration file /application/nginx-1.8.1/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.8.1/conf/nginx.conf test is successful
[root@lb01 conf]# systemctl restart nginx 测试:
[root@lb01 conf]# tail -1 /etc/hosts
192.168.100.105 www.dmtest.com [root@lb01 conf]# curl www.dmtest.com
192.168.100.107 [root@lb01 conf]# curl www.dmtest.com
192.168.100.108 [root@lb01 conf]# curl www.dmtest.com
192.168.100.107 [root@lb01 conf]# curl www.dmtest.com
192.168.100.108

ngin负载均衡集群(一)的更多相关文章

  1. nginx负载均衡集群

    nginx负载均衡集群  0.前言:nginx 负载均衡,属于网络7层模型中的应用层,说白了就是一个代理,要用 upstrem 模块实现,代理则用proxy模块 1.可以针对域名做转发,lvs只能针对 ...

  2. LVS+Keepalived搭建MyCAT高可用负载均衡集群

    LVS+Keepalived 介绍 LVS LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国 ...

  3. LB(Load balance)负载均衡集群--{LVS-[NAT+DR]单实例实验+LVS+keeplived实验} 菜鸟入门级

    LB(Load balance)负载均衡集群 LVS-[NAT+DR]单实例实验 LVS+keeplived实验 LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一 ...

  4. 测试LVS+Keepalived高可用负载均衡集群

    测试LVS+Keepalived高可用负载均衡集群 1. 启动LVS高可用集群服务 此时查看Keepalived服务的系统日志信息如下: [root@localhost ~]# tail -f /va ...

  5. 通过LVS+Keepalived搭建高可用的负载均衡集群系统

    1. 安装LVS软件      (1)安装前准备操作系统:统一采用Centos6.5版本,地址规划如下: 服务器名 IP地址 网关 虚拟设备名 虚拟ip Director Server 192.168 ...

  6. windows配置nginx实现负载均衡集群

    windows配置nginx实现负载均衡集群2014-08-20 09:44:40   来源:www.abcde.cn   评论:0 点击:617 网上大部分关于nginx负载均衡集群的教程都是lin ...

  7. Apache+tomcat+mod_jk+centos6.2负载均衡集群配置--转载

    转载地址:http://blog.163.com/chenhui_java/blog/static/17267249420128101191860/ 注: 由于长期受转载毒害,所以本人日志均是原创:其 ...

  8. LVS负载均衡集群服务搭建详解(二)

    lvs-nat模型构建 1.lvs-nat模型示意图 本次构建的lvs-nat模型的示意图如下,其中所有的服务器和测试客户端均使用VMware虚拟机模拟,所使用的CentOS 7 VS内核都支持ipv ...

  9. LVS负载均衡集群服务搭建详解(一)

    LVS概述 1.LVS:Linux Virtual Server 四层交换(路由):根据请求报文的目标IP和目标PORT将其转发至后端主机集群中的某台服务器(根据调度算法): 不能够实现应用层的负载均 ...

随机推荐

  1. 解决tomcat闪退问题

    https://blog.csdn.net/zh2nd/article/details/79068680 转载此博客链接内容,非常感谢博主 本文参考CSDN博主 哈克沃德.的<Tomcat8启动 ...

  2. spring boot test MockBean

    使用spring boot , MockBean @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) p ...

  3. HDU 5917 Instability ramsey定理

    http://acm.hdu.edu.cn/showproblem.php?pid=5917 即世界上任意6个人中,总有3个人相互认识,或互相皆不认识. 所以子集 >= 6的一定是合法的. 然后 ...

  4. C# Thread类 线程优先级

    1.C#对线程进行操作时,通过Thread类,可以对线程进行创建.挂起.恢复.休眠.终止及设置优先级. Thread类位于System.Threading命名空间下,该命名空间还包含一个ThreadP ...

  5. webservice初识,SOAP1.1版本

    客户端与服务端模式,非web端发布 1.1      [Jax-ws第一个例子] 1.1.1     第一步:服务端开发 编写SEI(Service Endpoint Interface),SEI在w ...

  6. Android入门:封装一个HTTP请求的辅助类

    前面的文章中,我们曾经实现了一个HTTP的GET 和 POST 请求: 此处我封装了一个HTTP的get和post的辅助类,能够更好的使用: 类名:HttpRequestUtil 提供了如下功能: ( ...

  7. Quartz 定时器,同时运用多个定时器

    效果:每天执行两个定时器,两个定时器不相关联.jar版本Quartz 2.2.3 Java工程结构图  jar 包下载: 链接: https://pan.baidu.com/s/1-7dh620k9P ...

  8. Today is the first day of the rest of your life.

    Today is the first day of the rest of your life. 今天是你余下人生的第一天.

  9. 【经验总结】datagrid锁定列后重新加载时出现错位问题的解决

    [问题描述]:有时候datagrid设置了锁定列后,在重新加载datagrid数据时,出现锁定列与非锁定列数据错位的问题,如图: [问题分析]:查看css样式我们发现,锁定的列和非锁定的列属于两个不同 ...

  10. jQuery遍历Table表格的行和列

    遍历Table表格的行和列,在开发中比较常用的功能,特别是前端开发人员,不多说,直接上代码,下面代码只是弹出第一列字段,请各位自己根据需求修改和扩展! <!DOCTYPE html PUBLIC ...