标签:lvs
DR模式搭建1.三台机器
分发器
ip地址 188.130
rs1
ip地址 188.129
rs2
ip地址 188.133
vip
ip地址 188.200
2.编辑脚本:
[root@weixing01 ~]# vim /usr/local/sbin/lvs_dr.sh
#! /bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
ipv=/usr/sbin/ipvsadm
vip=192.168.188.200
rs1=192.168.188.129
rs2=192.168.188.133
#注意这里的网卡名字
ifdown ens33
ifup ens33
ifconfig ens33:2 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip dev ens33:2
$ipv -C
$ipv -A -t $vip:80 -s rr
$ipv -a -t $vip:80 -r $rs1:80 -g -w 1
$ipv -a -t $vip:80 -r $rs2:80 -g -w 1
3.执行脚本:
[root@weixing01 ~]# sh !$
sh /usr/local/sbin/lvs_dr.sh
成功断开设备 ‘ens33‘。
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConn
4.两个rs编写脚本:
[root@weixing-02 ~]# vim /usr/local/sbin/lvs_rs.sh
#/bin/bash
vip=192.168.188.200
#把vip绑定在lo上,是为了实现rs直接把结果返回给客户端
ifdown lo
ifup lo
ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip lo:0
#以下操作为更改arp内核参数,目的是为了让rs顺利发送mac地址给客户端
#参考文档www.cnblogs.com/lgfeng/archive/2012/10/16/2726308.html
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
5.执行脚本:
[root@weixing-02 ~]# sh !$
sh /usr/local/sbin/lvs_rs.sh
6.测试:
可以实现负载均衡
1.编辑配置文件:
[root@weixing01 ~]# vi /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
#备用服务器上为 BACKUP
state MASTER
#绑定vip的网卡为ens33,你的网卡和阿铭的可能不一样,这里需要你改一下
interface ens33
virtual_router_id 51
#备用服务器上为90
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass aminglinux
}
virtual_ipaddress {
192.168.188.200
}
}
virtual_server 192.168.188.200 80 {
#(每隔10秒查询realserver状态)
delay_loop 10
#(lvs 算法)
lb_algo wlc
#(DR模式)
lb_kind DR
2.测试:rs2上的nginx关闭在开启,发现转发器上面可以自动检测到
[root@weixing01 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.188.200:80 wlc persistent 60
-> 192.168.188.129:80 Route 100 0 0
-> 192.168.188.133:80 Route 100 0 0
[root@weixing01 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.188.200:80 wlc persistent 60
-> 192.168.188.129:80 Route 100 0 0
[root@weixing01 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.188.200:80 wlc persistent 60
-> 192.168.188.129:80 Route 100 0 0
-> 192.168.188.133:80 Route 100 0 0
标签:lvs
原文地址:http://blog.51cto.com/13517254/2097166