负载均衡
2、加权最少链接 wlc
调度器可以自动问询真实服务器的负载情况,并动态调整权值带权重的谁不干活就给谁分配,机器配置好的权重高
3、基于局部性的最少连接调度算法 lblc
这个算法是请求数据包的目标 IP 地址的一种调度算法,该算法先根据请求的目标 IP 地址寻找最近的该目标 IP 地址所有使用的服务器,如果这台服务器依然可用,并且有能力处理该请求,调度器会尽量选择相同的服务器,否则会继续选择其它可行的服务器
4、复杂的基于局部性最少的连接算法 lblcr
记录的不是要给目标 IP 与一台服务器之间的连接记录,它会维护一个目标 IP 到一组服务器之间的映射关系,防止单点服务器负载过高。
5、最少期望延迟 sed
不考虑非活动链接,谁的权重大,优先选择权重大的服务器来接收请求,但权重大的机器会比较忙
6、永不排队 nq
无需队列,如果有realserver的连接数为0就直接分配过去
六、搭建HTTP负载均衡集群
1.搭建搭建lvs-nat模式的http负载集群
环境说明:
主机名 |
主机作用 |
IP/DIP |
VIP |
DR |
LVS服务器(DR) |
192.168.111.141 |
172.25.0.100 |
RS1 |
apache服务器1(RS) |
192.168.111.142 |
网关为DR网关 |
RS2 |
apache服务器2(RS) |
192.168.111.143 |
网关为DR网关 |
client |
客户端(用于测试) |
192.168.111.144 |
客户端不需要VIP |
DR配置
#关闭防火墙和selinux
[root@DR ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@DR ~]# setenforce 0
[root@DR ~]# systemctl disable --now firewalld
#添加网卡
#我这里添加的是仅主机模式网卡,以便区分,网段为:172.25.0.0
[root@DR ~]# nmcli connection show
NAME UUID TYPE DEVICE
ens33 d169a480-a2e3-4fe5-89ba-f1f0e022a80f ethernet ens33
Wired connection 1 d0f7070b-e2d8-324b-b396-d3d13b0c3c4c ethernet ens37
[root@DR ~]# nmcli connection modify Wired\ connection\ 1 con-name ens37 ipv4.addresses 172.25.0.100/24 ipv4.dns 114.114.114.114 ipv4.method manual autoconnect yes
[root@DR ~]# nmcli connection up ens37
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
#开启转发功能
[root@DR ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
[root@DR ~]# sysctl -p
net.ipv4.ip_forward = 1
RS1配置
#关闭防火墙和selinux
[root@RS1 ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@RS1 ~]# setenforce 0
[root@RS1 ~]# systemctl disable --now firewalld
#配置ip
[root@RS1 ~]# nmcli connection modify ens33 ipv4.addresses 192.168.111.142/24 ipv4.gateway 172.25.0.100 ipv4.dns 114.114.114.114 ipv4.method manual autoconnect yes
[root@RS1 ~]# nmcli connection up ens33
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
#配置好httpd,配置网站首页
[root@RS1 ~]# dnf -y install httpd
[root@RS1 ~]# echo "RS1" > /var/www/html/index.html
[root@RS1 ~]# systemctl enable --now httpd
RS2配置
#关闭防火墙和selinux
[root@RS2 ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@RS2 ~]# setenforce 0
[root@RS2 ~]# systemctl disable --now firewalld
#配置ip
[root@RS2 ~]# nmcli connection modify ens33 ipv4.addresses 192.168.111.143/24 ipv4.gateway 172.25.0.100 ipv4.dns 114.114.114.114 ipv4.method manual autoconnect yes
[root@RS2 ~]# nmcli connection up ens33
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
#配置好httpd,配置网站首页
[root@RS2 ~]# dnf -y install httpd
[root@RS2 ~]# echo "RS2" > /var/www/html/index.html
[root@RS2 ~]# systemctl enable --now httpd
配置好好两台web服务器后,最后再安装ipvsadm并添加规则
[root@DR ~]# dnf -y install ipvsadm
[root@DR ~]# ipvsadm -A -t 172.25.0.100:80 -s rr
[root@DR ~]# ipvsadm -a -t 172.25.0.100:80 -r 192.168.111.142:80 -m
[root@DR ~]# ipvsadm -a -t 172.25.0.100:80 -r 192.168.111.143:80 -m
[root@DR ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.0.100:80 rr
-> 192.168.11