一、概述
功能强大
转发策略比较多
适合大型的网络高可用
二、作用
使用keepalived解决lvs的单点故障高可用集群
三、环境
1.准备6台虚拟机,2台做LVS主备调度器,2台做web服务器,1台做存储,1台客户机验证
2.LVS主备调度器 master(192.168.1.225)backup(192.168.1.226)
3.web1(192.168.1.221)web2(192.168.1.223)
4.存储(192.168.1.224)
5.客户机(192.168.1.228)
6.虚拟ip(192.168.1.227
四、应用场景
商业大型高可用集群
五、技术特点
第四层传输层中使用
安全性比较高
六、架构部署
1、部署lvs主从服务器
LVS主服务器
#调整master的ARP参数
vim /etc/sysctl.conf
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.ens33.send_redirects = 0
sysctl -p
#安装 keepalived ipvsadm
yum install -y keepalived ipvsadm
#配置/etc/keepalived/keepalived.conf(master)
global_defs {
router_id LVS_DEVEL1
}
vrrp_instance master {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.227
}
}
virtual_server 192.168.1.227 80 {
delay_loop 6
lb_algo rr
lb_kind DR
#persistence_timeout 50
protocol TCP
real_server 192.168.1.221 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.223 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
#启动master和backup的keepalived与ipvsadm
systemctl start keepalived
systemctl start ipvsadm
#master和backup加载ip_vs模块
modprobe ip_vs
#查看lvs节点状态
ipvsadm -ln
LVS从服务器
#调整master的ARP参数
vim /etc/sysctl.conf
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.ens33.send_redirects = 0
sysctl -p
#安装 keepalived ipvsadm
yum install -y keepalived ipvsadm
#配置/etc/keepalived/keepalived.conf(backup)
global_defs {
router_id LVS_DEVEL2
}
vrrp_instance backup {
state BACKUP
interface ens33
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.227
}
}
virtual_server 192.168.1.227 80 {
delay_loop 6
lb_algo rr
lb_kind DR
#persistence_timeout 50
protocol TCP
real_server 192.168.1.221 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.223 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
#启动master和backup的keepalived与ipvsadm
systemctl start keepalived
systemctl start ipvsadm
#master和backup加载ip_vs模块
modprobe ip_vs
#查看lvs节点状态
ipvsadm -ln
2、部署web1、web2服务器
集群节点1服务器
step1
调整ARP参数
vim /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore=1
net.ipv4.conf.all.arp_announce=2
net.ipv4.conf.default.arp_ignore=1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce=2
sysctl -p
step2
安装apache
yum -y install httpd
echo "web1" >/var/www/html/index.html
step3
创建虚拟ip
cd /etc/sysconfig/network-scripts/
cp ifcfg-lo ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.1.227
NETMASK=255.255.255.255
ONBOOT=yes
NAME=loopback:0
#重启网卡
systemctl restart network
step4
#创建并添加本地路由回环
route add -host 192.168.1.227/32 dev lo:0
#启用httpd
systemctl start httpd
集群节点2服务器
web service2
step1
调整ARP参数
vim /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore=1
net.ipv4.conf.all.arp_announce=2
net.ipv4.conf.default.arp_ignore=1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce=2
sysctl -p
step2
安装apache
yum -y install httpd
echo "web2" >/var/www/html/index.html
step3
创建虚拟ip
cd /etc/sysconfig/network-scripts/
cp ifcfg-lo ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.1.227
NETMASK=255.255.255.255
ONBOOT=yes
NAME=loopback:0
#重启网卡
systemctl restart network
step4
#创建并添加本地路由回环
route add -host 192.168.1.227/32 dev lo:0
#启用httpd
systemctl start httpd
3、测试
如果web1、web2处于正常状态
访问192.168.1.227:80如果web1宕机访问页面
web1停止服务访问192.168.1.227
4、部署nfs
#配置文件
vim /etc/exports
/data/www/html/ 192.168.1.224(rw,no_all_squash)
mkdir -p /data/www/html
echo "web 1 2" >/data/www/html/index.html
#安装nfs
web1、web2也安装
yum install -y nfs-utils
#启动nfs服务
systemctl start nfs
#查看共享文件夹
showmount -e
#web1、web2挂载共享文件夹
mount 192.168.1.224:/data/www/html /var/www/html/文章来源:https://www.toymoban.com/news/detail-493224.html
测试访问页面192.168.1.227文章来源地址https://www.toymoban.com/news/detail-493224.html
到了这里,关于LVS负载均衡(web网站负载均衡)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!