lijm1522 发表于 2017-4-17 22:38:15

部署lvs+keepalived

  1.总共需要四台机器,五个ip, 两台机器作为负载均衡director,两台机器作为real server, 一人ip作为虚拟ip,供外网用。
  2.部署director master:
  a. 安装keepalived:yum install keepalived
  b.安装ipvs: yum install ipvsadm
  c.配置keepalived:
  cd /etc/keepalived/
  vi keepalived.conf
  内容如下:
  ! Configuration File for keepalived
vrrp_instance VI_1 {
    state MASTER
    interface eth1
    virtual_router_id 46
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass kevin_kocla
    }
    virtual_ipaddress {
       192.168.77.142
    }
}
  virtual_server 192.168.77.142 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 3600
    protocol TCP
  real_server 192.168.77.42 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 30
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
        }
    }
  real_server 192.168.77.44 80 {
        weight 2
        TCP_CHECK {
            connect_timeout 30
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
        }
    }
}
其中192.168.77.142为虚拟ip.
  3.部署director backup:
  方法同2,整个配置文件拷过来修改,配置文件中
  state MASTER 改为:state BACKUP
  priority 100 改为:priority 80
  4.部署real server, 在/etc/init.d目录下增加lvsrs文件,并赋予755权限,lvsrs内容如下:
  #!/bin/bash
#description : Start Real Server
VIP=192.168.77.142
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo " Start LVS of Real Server "
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
    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
    ;;
     stop)
/sbin/ifconfig lo:0 down
    echo "close LVS Director server"
    echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
    echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
    echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
    echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
    ;;
     *)
    echo "Usage: $0 {start|stop}"
    exit 1
esac
注意在windows环境下编辑,在linux上有可以不能执行。
  5. 部署另一台 real server.
  6. 依次启动:
  director master:    service keepalived start
  director backup:   service keepalived start
  real server 1 :       service lvsrs start
  rela server 2:        service lvsrs start
  7.测试访问。
  可能用到命令:
  ip add
  ip add list
页: [1]
查看完整版本: 部署lvs+keepalived