实验环境

192.168.200.111 web1 centos7
192.168.200.112 web2 centos7
192.168.200.113 wev3 centos7

三台主机环境:

都安装Nginx、以192.168.200.111为主环境实验

web3(192.168.200.113)操作为例

[root@web3 ~]# cd /usr/local/nginx/conf/
[root@web3 conf]# vim nginx.conf

user  nginx nginx;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 10240;
}
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;
client_header_timeout 60;
client_body_timeout 60;
server_tokens off;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
#upstream用于定义负载均衡组
upstream web_pool {
server 192.168.200.113 weight=5;
server 192.168.200.112 weight=5;
server 192.168.200.111 weight=5 backup;
}
server {
listen 80;
server_name www.etiantion.org;
charset utf-8;
location / {
root html;
index index.html index.html;
proxy_pass http://web_pool;
}
#status用于采集用户访问数量
location /status {
stub_status on;
access_log off;
}
}
}

设置映射关系

[root@web3 ~]# cat /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.113 www.etiantian.org

测试负载均衡器到web服务器之间能否ping通

在nginx主配置文件中我们未指定算法,所以默认时轮询算法

轮询算法

[root@web3 conf]# curl 192.168.200.113
192.168.200.111
[root@web3 conf]# curl 192.168.200.113
192.168.200.112
[root@web3 conf]# curl 192.168.200.113
192.168.200.111
[root@web3 conf]# curl 192.168.200.113
192.168.200.112
[root@web3 conf]# curl 192.168.200.113
192.168.200.111
[root@web3 conf]# curl 192.168.200.113
192.168.200.112

ip-hash算法

 #upstream用于定义负载均衡组
upstream web_pool {
ip_hash;
server 192.168.200.111 weight=5;
server 192.168.200.112 weight=5;
server 192.168.200.113 weight=5 ; #此时backup要删除,用backup会报错
}

[root@web conf]# curl 192.168.200.113
192.168.200.112
[root@web conf]# curl 192.168.200.113
192.168.200.112
[root@web conf]# curl 192.168.200.113
192.168.200.112
[root@web conf]# curl 192.168.200.113
192.168.200.112
[root@web conf]# curl 192.168.200.113
192.168.200.112
[root@web conf]# curl 192.168.200.113
192.168.200.112

权重算法:权值越大分配几率越大,一般按权值比来分配

 #upstream用于定义负载均衡组
upstream web_pool {
server 192.168.200.113 weight=1;
server 192.168.200.112 weight=5;
server 192.168.200.111 weight=5 backup;
}

[root@web conf]# curl 192.168.200.113
192.168.200.112
[root@web conf]# curl 192.168.200.113
192.168.200.112
[root@web conf]# curl 192.168.200.113
192.168.200.111
[root@web conf]# curl 192.168.200.113
192.168.200.112
[root@web conf]# curl 192.168.200.113
192.168.200.112
[root@web conf]# curl 192.168.200.113
192.168.200.112

nginx反向代理实战之轮询、Ip_hash、权重的更多相关文章

  1. 原创:Nginx反向代理实战部署

    均衡负载服务器 10.0.0.9 [root@web03 conf]# vim nginx.conf worker_processes  1; events { worker_connections  ...

  2. Centos 7.6配置nginx反向代理,直接yum安装

    一,实验介绍 利用三台centos7虚拟机搭建简单的nginx反向代理负载集群, 三台虚拟机地址及功能介绍 192.168.2.76    nginx负载均衡器 192.168.2.82    web ...

  3. Linux之nginx反向代理三台web

    作业三:nginx反向代理三台web 实现基于轮询的方式调度三台web,并验证结果 实现基于权重的方式调度三台web,并验证结果 实现基于hash的方式调用三台web,并验证结果 [root@loca ...

  4. Nginx反向代理+DNS轮询+IIS7.5 千万PV 百万IP 双线 网站架构案例

    原文地址:http://www.jb51.net/article/31844.htm Nginx  ("engine x") 是一个高性能的 HTTP 和反向代理服务器,也是一个 ...

  5. Linux实战教学笔记30:Nginx反向代理与负载均衡应用实践

    1.1 集群简介 简单地说,集群就是指一组(若干个)相互独立的计算机,利用高速通信网络组成的一个较大的计算机服务系统,每个集群节点(即集群中的每台计算机)都是运行各自服务的独立服务器.这些服务器之间可 ...

  6. nginx 反向代理实现负载均衡*配置实战

    重要点: 1配置反向代理多虚拟主机节点服务器 2经过反向代理后的节点服务器记录用户IP 3与反向代理配置相关的更多参数说明 4根据URL目录地址转发 (1)根据URL中的目录地址实现代理转发(动静分离 ...

  7. 实战 | 一文带你读懂Nginx反向代理

    一个执着于技术的公众号 前言 在前面的章节中,我们已经学习了nginx基础知识: 给小白的 Nginx 10分钟入门指南 Nginx编译安装及常用命令 完全卸载nginx的详细步骤 Nginx 配置文 ...

  8. Nginx 反向代理与负载均衡详解

    序言 Nginx的代理功能与负载均衡功能是最常被用到的,关于nginx的基本语法常识与配置已在Nginx 配置详解中有说明,这篇就开门见山,先描述一些关于代理功能的配置,再说明负载均衡详细. Ngin ...

  9. nginx反向代理与负载均衡讲解

    Nginx的代理功能与负载均衡功能是最常被用到的,关于nginx的基本语法常识与配置已在上篇文章中有说明,这篇就开门见山,先描述一些关于代理功能的配置,再说明负载均衡详细. Nginx代理服务的配置说 ...

随机推荐

  1. js的全局变量与var关键字

    var a = '1'; 如果定义在函数外,就是全局变量.如果定义在函数内,就不是全局变量,只能在函数内调用. 但是:如果在函数内定义变量,没有加var关键字,默认表示该变量是全局的.

  2. [python]Python 字典(Dictionary) update()方法

    update() 函数把字典dict2的键/值对更新到dict里.如果后面的键有重复的会覆盖前面的语法dict.update(dict2) dict = {'Name': 'Zara', 'Age': ...

  3. (matlab)自定义图像(matlab)

    clc;clear all;A=[0 230 255 60 30 100];A=uint8(A);imshow(A,'InitialMagnification','fit') 如图: clc;clea ...

  4. 解决安装mysql时出现的三种问题

    MySQL v5.0.96 for windows 安装版         链接:http://pan.baidu.com/s/1slmE2k9 密码:tadp MySQLAdministratort ...

  5. 计算几何-HPI

    This article is made by Jason-Cow.Welcome to reprint.But please post the article's address.   在线笛卡尔坐 ...

  6. ASA升级

    1.开启TFTP server,并且保证设备和TFTP server可达.2.上传镜像文件到ASA:ciscoasa# copy tftp: disk0: >>>>拷贝镜像到A ...

  7. Spring - jdbcTemplate - 调试代码: PreparedStatementCreator 生成的语句, update 之后没有 自增id, 已解决

    1. 概述 解决 jdbcTemplate 下, update 结果不带 自增id 的问题 2. 场景 看书 Spring in Action 5th 3.1.4 listing 3.10 saveT ...

  8. yii components文件到底应该放些什么代码

    项目全局用的代码,比如项目所有controller和model的共通操作或者放一些第三方的组件.插件之类的项目全局用的代码

  9. 记一道简单的re--BUUctf reverse1

    1.首先拖进ida里,看到了左面一百多function...还是shift+f12 查看敏感字符串吧 2.发现了这两个比较可疑的字符串,然后双击this is the right flag 进入到了他 ...

  10. Django+Celery+redis kombu.exceptions.EncodeError:Object of type is not JSON serializable报错

    在本文中例子中遇到问题的各种开发版本如下: Python3.6.8 Django==2.2 celery==4.4.0 kombu==4.6.7 redis==3.3.0 大概的报错如下截图: 是在开 ...