hyzqb 发表于 2018-12-30 13:25:59

lvs(DR)

  实验环境:
  ipvsadm-1.26-4.el6.x86_64
  system:centos-6.6.x86_64
  kernel:2.6.32-504.el6.x86_64
  keepalived-1.2.13-4.el6.x86_64
  

  配置DR:
# sysctl -w net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.all.send_redirects = 0
# sysctl -w net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.default.send_redirects = 0
# sysctl -w net.ipv4.conf.eth2.send_redirects=0
net.ipv4.conf.eth2.send_redirects = 0
# service ipvsadm stop
# ipvsadm -A -t 192.168.150.200:80 -s rr
# ipvsadm -a -t 192.168.150.200:80 -r 192.168.150.129 -g -w 1
# ipvsadm -a -t 192.168.150.200:80 -r 192.168.150.142 -g -w 1
# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
# service ipvsadm save  

  配置real server:
# 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
# ifconfig lo:0 192.168.150.200/32
# route add -host 192.168.150.200 dev lo:0
# setenforce 0
# yum install httpd
# service httpd start  

  配置keepalived:
global_defs {
   notification_email {
   acassen@firewall.loc
   failover@firewall.loc
   sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 220.181.12.11
   smtp_connect_timeout 30
   router_id haproxy_DEVEL
}
vrrp_instance VI_1 {
    state MASTER    #另一端为SLAVE
    interface eth3    #根据自己网卡情况而定
    virtual_router_id 51
    priority 100    #另一端为80
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1234
    }
   virtual_ipaddress {
      192.168.150.200/24 dev eth3
    }
}
virtual_server 192.168.150.200/24 80 {   
    delay_loop 6   
    lb_algo rr   
    lb_kind DR   
    persistence_timeout 50   
    protocol TCP   
    real_server 192.168.150.129 80 {   
      weight 3   
      TCP_CHECK {   
      connect_timeout 10   
      nb_get_retry 3   
      delay_before_retry 3   
      connect_port 80   
      }   
}
   real_server 192.168.150.142 80 {   
      weight 3   
      TCP_CHECK {   
      connect_timeout 10   
      nb_get_retry 3   
      delay_before_retry 3   
      connect_port 80   
      }   
    }   
}
# service keepalived start  

  

  

  检测结果:
  查看是否正常调度:
http://s3.运维网.com/wyfs02/M02/58/7E/wKiom1SzHMXz6higAAD-m88IeLU690.jpg
  

  

  

  查看MASTER,获得vip:192.168.150.200,及检查后端

  

http://s3.运维网.com/wyfs02/M00/58/7A/wKioL1SzHFviG8MgAAM0uTPkHBk205.jpghttp://s3.运维网.com/wyfs02/M00/58/7A/wKioL1SzHJbh8_0aAAGjzijmnZ8643.jpg
  查看SLAVE,及检查后端服务:
http://s3.运维网.com/wyfs02/M00/58/7E/wKiom1SzG8WwkBTaAAGzFB9Z19U144.jpg
  故障转移:
  停掉MASTER的keepalived,查看SLAVE是否自动切换为MASTER
  # service keepalived stop
http://s3.运维网.com/wyfs02/M01/58/7A/wKioL1SzHPeizEsnAAP6z5lSf_k088.jpg
http://s3.运维网.com/wyfs02/M01/58/7E/wKiom1SzHC-hf2pJAAGpadT2C3I733.jpg
  

  检测后端检查:
  停掉其中一台后端httpd
  # service hdttp stop
http://s3.运维网.com/wyfs02/M02/58/7A/wKioL1SzHWOisXsaAAIQtodFOSY797.jpg



页: [1]
查看完整版本: lvs(DR)