admin 发表于 2021-12-15 02:00:22

LVS环境配合Keepalived部署

1.环境说明
      六台服务器,两台作为director,四台作为两组real server。

director为
10.8.80.110(keepalived master)和10.8.80.111(keepalived backup),

vip:10.8.80.112。
两组real server
   为10.8.80.101:80,10.8.80.102:80和10.8.80.105:8889,10.8.80.106:8889

2.安装和配置LVS
      两台director上安装ipvadm

yum install -y ipvsadm
      两台director上编写DR模式脚本

vim /usr/local/sbin/lvs_dr.sh
      添加内容

#! /bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
ipv=/sbin/ipvsadm
vip=10.8.80.112
rs1=10.8.80.101
rs2=10.8.80.102
rs3=10.8.80.105
rs4=10.8.80.106
$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
$ipv -A -t $vip:8889 -s rr
$ipv -a -t $vip:8889 -r $rs3:8889 -g -w 1
$ipv -a -t $vip:8889 -r $rs4:8889 -g -w 1
      然后在四台real server上编写脚本

vim /usr/local/sbin/lvs_dr_rs.sh
      添加内容

#! /bin/bash
vip=10.8.80.112
ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip lo:0
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
3.安装Keepalived
      两台director上执行

yum install -y keepalived
      两台director上编辑配置文件

vim /etc/keepalived/keepalived.conf
      加入配置

vrrp_instance VI_1 {
    state MASTER   //备上为BACKUP
    interface eno16777984    //备的网卡名
    #lvs_sync_daemon_inteface eno16777984
    virtual_router_id 51
    priority 100    //备为90
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      10.8.80.112
    }
}
virtual_server 10.8.80.112 80 {
    delay_loop 3
    lb_algo wlc
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 60
    protocol TCP
    real_server 10.8.80.101 80 {
      weight 100
      TCP_CHECK {
      connect_timeout 10
      nb_get_retry 3
      delay_before_retry 3
      connect_port 80
      }
    }
    real_server 10.8.80.102 80 {
      weight 100
      TCP_CHECK {
      connect_timeout 10
      nb_get_retry 3
      delay_before_retry 3
      connect_port 80
      }
    }
}
virtual_server 10.8.80.112 8889 {
    delay_loop 3
    lb_algo wlc
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 60
    protocol TCP
    real_server 10.8.80.105 8889 {
      weight 100
      TCP_CHECK {
      connect_timeout 10
      nb_get_retry 3
      delay_before_retry 3
      connect_port 8889
      }
    }
    real_server 10.8.80.106 8889 {
      weight 100
      TCP_CHECK {
      connect_timeout 10
      nb_get_retry 3
      delay_before_retry 3
      connect_port 8889
      }
    }
}
4.启动LVS+Keepalived
      两台director执行脚本
1
sh /usr/local/sbin/lvs_dr.sh
      两台director启动keepalived
1
systemctl start keepalived
      四台real server执行脚本
1
sh /usr/local/sbin/lvs_dr_rs.sh
      LVS+Keepalived部署完成
页: [1]
查看完整版本: LVS环境配合Keepalived部署