LVS+keepalived配置備忘

來源:互聯網
上載者:User

LVS+keepalived配置備忘 LVS + keepalived實現負載平衡的文檔很多,這裡不再重複說明,只記錄在配置過程中容易忘記的地方。 1. 確保IP轉寄功能開啟 Shell代碼  # sysctl -a | grep ip_forward  net.ipv4.ip_forward = 1   方法有san種   1)sysctl net.ipv4.ip_forward=1   2) echo "1" > /proc/sys/net/ipv4/ip_forward   3) 修改sysctl.conf, net.ipv4.ip_forward = 1, 執行sysctl -p命令  2. virtual ip的配置   keepalived 採用RD轉寄模式   測試拓撲結構                  linux director                  ip:192.168.1.199                 vip:192.168.1.210 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++           |                          | real server                    real server ip: 192.168.1.13               ip: 192.168.1.14 vip: 192.168.1.210             vip: 192.168.1.210  lvs用戶端也就是real server的vip,要和linux director的vip保持一致 lvs-real.sh Shell代碼  #!/bin/bash  VIP=192.168.1.210  /etc/rc.d/init.d/functions  case "$1" in  start)         ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP         /sbin/route add -host $VIP dev 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         sysctl -p >/dev/null 2>&1         echo "RealServer Start OK"         ;;  stop)         ifconfig lo:0 down         route del $VIP >/dev/null 2>&1         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 "RealServer Stoped"         ;;  *)         echo "Usage: $0 {start|stop}"         exit 1  esac  exit 0    linux director上keepalived.conf Shell代碼  ! Configuration File for keepalived    global_defs {     notification_email {          #huaying@staff.sina.com.cn     }     #notification_email_from Alexandre.Cassen@firewall.loc     #smtp_server 127.0.0.1     #smtp_connect_timeout 30     router_id LVS_DEVEL  }    virtual_server 192.168.1.210 80 {     delay_loop 3     lb_algo rr     lb_kind DR     persistence_timeout 120     protocol TCP       real_server 192.168.1.13 80 {       weight 100       TCP_CHECK {          connect_timeout 3          nb_get_retry 3          delay_before_retry 3          connect_port 80       }     }       real_server 192.168.1.14 80 {       weight 100       TCP_CHECK {          connect_timeout 3          nb_get_retry 3          delay_before_retry 3          connect_port 80       }     }  }    說明:由於是測試lvs負責均衡功能,沒有配置vrrp_instance,在實際應用中,可以配置雙linux director。所以在linux director上手工添加vip:192.168.1.210,可以使用如下方法 Shell代碼  # ip addr add 192.168.1.210 dev eth0    3. keepalived DR轉寄模式,需要將real server的ip與virtual ip設定在同一個網段  4. linux director 需要安裝ipvsadm,當ipvsadm啟動後可以查看它是否被載入 Shell代碼  # lsmod | grep ip_vs  ip_vs                  94742  5     #lpvsadm -ln  IP Virtual Server version 1.2.1 (size=4096)  Prot LocalAddress:Port Scheduler Flags    -> RemoteAddress:Port           Forward Weight ActiveConn InActConn  TCP  192.168.1.210:80 rr persistent 120    -> 192.168.1.13:80              Route   100    0          0             -> 192.168.1.14:80              Route   100    0          0       5. 如果配置都正確,需要考慮是否將ipvs架構編譯進keepalived 6. 如還不行,考慮其它原因  XXX TODO:NAT轉寄模式的配置再測試 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.