第三阶段基础
时 间:2023年6月19日
参加人:全班人员
内 容:
keepalived+LVS(DR)搭建部署
目录
一、作用
技术特点:
与nginx的区别:
安全性:
配置文件:
二、环境简介
三、操作步骤
部署web1服务器:
部署web2服务器:
部署LVS主调度器:
部署LVS备调度器:
测试结果:
1:使用keepalived解决lvs的单点故障
2:高可用集群,适合大型网络高可用
3:负载均衡
4:比HaProxy功能更加强大
8:转发策略比较多
传输层,四层,基于TCP
nginx属于第七层,应用层,基于HTTP
因为在上层,所以局限了,不太适合做大型商用
要安全就用HaProxy高可用数据集群
/etc/keepalived/keepalived.conf
1.准备6台虚拟机,2台做LVS主备调度器,2台做web服务器,1台做存储,1台客户机验证
2.LVS主调度器 master(192.168.1.107)
备调度器backup(192.168.1.108)
3.web1(192.168.1.136)
web2(192.168.1.145)
4.存储(192.168.1.128)
5.客户机(192.168.1.102)
6.虚拟ip(192.168.1.250)
步骤一:配置ARP参数
步骤二:安装http服务
yum -y install httpd
步骤三:写入一个用与测试的首页文件
echo "huyang" >/var/www/html/index.html
步骤四:创建虚拟ip
cp /etc/sysconfig/network-scripts/ifcfg-lo
/etc/sysconfig/network-scripts/ifcfg-lo:0
vim /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.1.250
NETMASK=255.255.255.255
ONBOOT=yes
NAME=loopback:0
步骤五:重启网卡
systemctl restart network
步骤六:添加回环路由
route add -host 192.168.1.250/32 dev lo:0
route -n
启动服务
systemctl start httpd
步骤一:配置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=2sysctl -p
步骤二:安装http服务
yum -y install httpd
步骤三:写入一个用与测试的首页文件
echo "zhoumaomao" >/var/www/html/index.html
步骤四:创建虚拟ip
cp /etc/sysconfig/network-scripts/ifcfg-lo
/etc/sysconfig/network-scripts/ifcfg-lo:0
vim /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.1.250
NETMASK=255.255.255.255
ONBOOT=yes
NAME=loopback:0
步骤五:重启网卡
systemctl restart network
步骤六:添加回环路由
route add -host 192.168.1.250/32 dev lo:0
route -n
启动服务
systemctl start httpd
步骤一:配置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 = 0sysctl -p
步骤二:配置 keepalived
安装:yum install -y keepalived ipvsadm
配置文件:/etc/keepalived/ keepalived.conf
! Configuration File for keepalived
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.250
}
}
virtual_server 192.168.1.250 80 {
delay_loop 6
lb_algo rr
lb_kind DR
#persistence_timeout 50
protocol TCP
real_server 192.168.1.136 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.145 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
步骤三:启动keepalived与ipvsadm服务
touch /etc/sysconfig/ipvsadm
systemctl start keepalived
systemctl start ipvsadm
master和backup加载ip_vs模块
modprobe ip_vs
查看lvs节点状态
ipvsadm -ln
步骤一:配置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 = 0sysctl -p
步骤二:配置 keepalived
安装:yum install -y keepalived ipvsadm
配置文件:/etc/keepalived/ keepalived.conf
! Configuration File for keepalived
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.250
}
}
virtual_server 192.168.1.250 80 {
delay_loop 6
lb_algo rr
lb_kind DR
#persistence_timeout 50
protocol TCP
real_server 192.168.1.136 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.145 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
步骤三:启动keepalived与ipvsadm服务
touch /etc/sysconfig/ipvsadm
systemctl start keepalived
systemctl start ipvsadm
master和backup加载ip_vs模块
modprobe ip_vs
查看lvs节点状态
ipvsadm -ln