LVS的DR模式+keepalived
keepalived+LVS-DR模式
---------client---------主LVS---------从LVS---------WEB1---------WEB2--------
192.168.6.1 192.168.6.20 192.168.6.200 192.168.6.30 192.168.6.50
lo:0:192.168.6.254 lo:0:192.168.6.254
1、配置主LVS
1).配置IP,虚拟IP不用配置,让群集IP代替
2).调整响应参数(主从配置一样)
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
3).安装ipvsadm(主从配置一样)
modprobe ip_vs
yum -y install ipvsadm keepalived
4).配置主Keepalived
vim /etc/keepalived/keepalived.conf
修改:
router_id LVS_DEVEL-r1
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.6.254
}
}
virtual_server 192.168.6.254 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.6.30 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.6.50 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
systemctl restart keepalived
5).查看
ip add //有群集地址
ipvsadm -ln //有节点服务器地址
2、配置WEB节点服务器(两台配置一样,配置两台)
1).配置IP地址,并安装配置httpd
2).设置VIP
cd /etc/sysconfig/network-scripts/
cp ifcfg-lo ifcfg-lo:0
vim ifcfg-lo:0
修改:
DEVICE=lo:0
IPADDR=192.168.6.254
NETMASK=255.255.255.255
ONBOOT=yes
systemctl restart network
3).添加路由
route add -host 192.168.6.254 dev lo:0
4).调整响应参数
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
vim /usr/local/httpd/htdocs/index.html
systemctl restart httpd
5).客户端验证
firefox 192.168.6.254(比较慢) //刷新测试在两个httpd间互相调度
3、配置从keepalived
1).配置IP,虚拟IP不用配置,让群集IP代替
2).调整响应参数(主从配置一样)
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
3).安装ipvsadm(主从配置一样)
modprobe ip_vs
yum -y install ipvsadm keepalived
4).配置从Keepalived
vim /etc/keepalived/keepalived.conf
修改:
router_id LVS_DEVEL-r2
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.6.254
}
}
virtual_server 192.168.6.254 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.6.30 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.6.50 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
systemctl restart keepalived
在此inet 192.168.6.254/32 scope global ens33是应用不上的
断掉主的网卡,回到从
记得切换回来重启keepalived
在此inet 192.168.6.254/32 scope global ens33是已经应用上了的
L