1、集群分类
(1)高性能计算集群(HPC)
(2)负载均衡集群(LB)
(3)高可用集群(HA)
LB和HA在企业中用的更多。
2、服务器架构
《大型网站技术架构》李智慧
lvs项目介绍
linux虚拟服务器(lvs)
可以实现
前端:负载均衡层
中间:服务器
DirectorServer调试服务器
RealServer真实服务器
vip虚拟ip地址
rip真实ip地址
dip节点ip地址
LVS:Linux虚拟服务器
1、工作模式
(1)tun隧道模式:很少使用
(2)nat模式:相对较少
(3)dr模式:路由模式,应用最多
(4)fullnat:在很少规模环境下使用
负载均衡调度算法
LVS目前实现了10种调度算法
常用调度算法有4种
轮询 rr
加权轮询 wrr
最少连接 lc
加权最少连接wlc
基于局部的最少连接lblc
带复制的基于局部的最少连接lblcr
源地址散列sh
目标地址散列
最短的期望的延迟
最少队列调度
配置LVS-NAT模式
1、修改两台WEB服务器为其添加网关192.168.4.4
[root@vh02html]# ifdown eth0;ifup eth0
成功断开设备'eth0'。
连接已成功激活(D-Bus活动路径:/org/freedesktop/NetworkManager/ActiveConnection/4)
[root@vh02html]# route -n
KernelIP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.4.4 0.0.0.0 UG 100 0 0 eth0
192.168.4.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@vh03html]#
21 nmtui
22 ifdown eth0;ifup eth0
23 route -n
24*scp -r/etc/yum.repos.d/rhel7.repo 192.168.4.4:/etc/yum.repos.d/
25 \c
26 scp -r /etc/yum.repos.d/rhel7.repo 192.168.4.4:/etc/yum.repos.d/
2、创建虚拟机node4
eth0:192.168.4.4 eth2:201.1.1.4
3、打开路由功能
[root@vh04~]# sysctl -a | grep ip_forward
net.ipv4.ip_forward= 1
net.ipv4.ip_forward_use_pmtu= 0
sysctl:reading key "net.ipv6.conf.all.stable_secret"
sysctl:reading key "net.ipv6.conf.default.stable_secret"
sysctl:reading key "net.ipv6.conf.eth0.stable_secret"
sysctl:reading key "net.ipv6.conf.eth1.stable_secret"
sysctl:reading key "net.ipv6.conf.eth2.stable_secret"
sysctl:reading key "net.ipv6.conf.eth3.stable_secret"
sysctl:reading key "net.ipv6.conf.lo.stable_secret"
sysctl:reading key "net.ipv6.conf.virbr0.stable_secret"
sysctl:reading key "net.ipv6.conf.virbr0-nic.stable_secret"
[root@vh04~]# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.
sysctl.conf sysctl.d/
[root@vh04~]# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.
sysctl.conf sysctl.d/
[root@vh04~]# echo "net.ipv4.ip_forward = 1" >>/etc/sysctl.conf
[root@vh04~]# sysctl -p
net.ipv4.ip_forward= 1
[root@vh04~]#
4、配置node4作为LVS服务器
yum-y install ipvsadm
ipvsadm-A -t 201.1.1.4:80 -s rr //rr轮询调度算法
ipvsadm-a -t 201.1.1.4:80 -r 192.168.4.2 -m //NAT模式
ipvsadm-a -t 201.1.1.4:80 -r 192.168.4.3 -m -w 2 //w权重
3、检查
ipvsadm-Ln
Active….
4、验证
在两台
vim/var/http/html
index.html
ctrl+F5
删除虚拟机服务器
ipvsadm-d -t 201.1.1.4:80 -r 192.168.4.3
ipvsadm-D -t 201.1.1.4:80
manipvsadm /scheduler
history| grep ipvsadm
修改调度算法为wrr
ipvsadm-E -t 201.1.1.4:80 -s wrr
[root@vh04~]# ipvsadm -Ln
IPVirtual Server version 1.2.1 (size=4096)
ProtLocalAddress:Port Scheduler Flags
->RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 201.1.1.4:80 wrr
->192.168.4.2:80 Masq 1 0 0
->192.168.4.3:80 Masq 2 0 0
NAT是networkaddress translation 的缩写网络地址转换
watch-n1
[root@vh02html]# systemctl stop httpd
[root@vh02html]# systemctl start httpd
[root@vh02html]#
[root@vh03html]# systemctl stop httpd
[root@vh03html]# systemctl start httpd
[root@vh03html]#
[root@vh04~]# cat monitor.sh
#!/bin/bash
VIP=201.1.1.4:80
RIP1=192.168.4.2
RIP2=192.168.4.3
while:
do
forIP in $RIP1 $RIP2
do
curlhttp://$IP &> /dev/null
web_stat=$?
ipvsadm -Ln | grep $IP &> /dev/null
web_in_lvs=$?
if[ $web_stat -ne 0 -a $web_in_lvs -eq 0 ]; then
ipvsadm-d -t $VIP -r $IP
elif[ $web_stat -eq 0 -a $web_in_lvs -ne 0 ]; then
ipvsadm-a -t $VIP -r $IP -m
fi
done
sleep1
done
vim
:7,17s///g
[root@vh04~]# bash monitor.sh &
[1]5378
[root@vh04~]# kill 5378
[root@vh04~]# watch -n1 bash monitor.sh