负载均衡实验需要三台虚拟机
01 192.168.211.130 作为负载均衡机器
02 192.168.211.128
03 192.168.211.129
1,关闭防火墙
iptables -F sed -i 's/enforcing/disabled/' /etc/selinux/config systemctl stop firewalld systemctl disable firewalld
2, 将02,03机器的index.html写入内容
3, 给01 机器的配置文件中写入
http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream node { server 192.168.211.129; server 192.168.211.128; } server { listen 80; server_name 192.168.211.130; location / { proxy_pass http://node; } } }
4, 然后访问01机器的web,反复刷新
二, nginx负载均衡调度算法
调度算法 概述 轮询 按时间顺序逐一分配到不同的后端服务器(默认) weight 加权轮询,weight值越大,分配到的访问几率越高 ip_hash 每个请求按访问IP的hash结果分配,这样来自同一IP的固定访问一个后端服务器 url_hash 按照访问URL的hash结果来分配请求,是每个URL定向到同一个后端服务器 least_conn 最少链接数,那个机器链接数少就分发
1.轮询(不做配置,默认轮询)
2.weight权重(优先级)
3.ip_hash配置,根据客户端ip哈希分配,不能和weight一起用