• lvs+keepalived高可用负载均衡


    说明:
    lvs+keepalived-master 172.16.0.111
    lvs+keepalived-backup 172.16.0.112
    web-1 172.16.0.113
    web-2 172.16.0.114
    VIP 172.16.0.100
    lvs管理工具ipvsadm
    keepalived-1.3.5.tar.gz

    1.查看是否支持lvs

    [root@lvs-master ~]# cat /boot/config-2.6.32-573.el6.x86_64 
    [root@lvs-master ~]# modprobe -l |grep ipvs
    

    2.lvs主备服务器安装keepalived

    [root@lvs-master ~]# tar zxvf keepalived-1.3.5.tar.gz
    [root@lvs-master ~]# cd keepalived-1.3.5
    [root@lvs-master keepalived-1.3.5]# ./configure --prefix=/usr/local/keepalived
    [root@lvs-master keepalived]# make && make install

    3.配置keepalived用service命令启动

    a.复制/sbin/keepalived到/usr/sbin下

    [root@lvs-master ~]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
    

    b.复制sysconfig文件到/etc/sysconfig下

    [root@lvs-master ~]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

    c.复制启动脚本到/etc/init.d下

    [root@lvs-master ~]# cp  ~/keepalived-1.3.5/keepalived/etc/init.d/keepalived  /etc/init.d/
    

    d.keepalived默认会读取/etc/keepalived/keepalived.conf配置文件

    [root@lvs-master ~]# mkdir /etc/keepalived
    [root@lvs-master ~]# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf

    4.编辑keepalived配置文件
    a.主服务器上如下

    [root@lvs-master keepalived-1.3.5]# vim /etc/keepalived/keepalived.conf
    ! Configuration File for keepalived
    
    global_defs {
       notification_email {
         acassen@firewall.loc
         failover@firewall.loc
         sysadmin@firewall.loc
       }
       notification_email_from Alexandre.Cassen@firewall.loc
       smtp_server 192.168.200.1
       smtp_connect_timeout 30
       router_id LVS_DEVEL
       vrrp_skip_check_adv_addr
       vrrp_strict
       vrrp_garp_interval 0
       vrrp_gna_interval 0
    }
    
    vrrp_instance VI_1 {
        state MASTER
        interface eth0
        virtual_router_id 51
        priority 100
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            172.16.0.100
        }
    }
    
    virtual_server 172.16.0.100 80 {
        delay_loop 6
        lb_algo rr
        lb_kind DR
        persistence_timeout 50
        protocol TCP
    
        real_server 172.16.0.113 80 {
            weight 1
            TCP_CHECK {
                connect_timeout 10
                nb_get_retry 3
                delay_before_retry 3
            }
        }
        real_server 172.16.0.114 80 {
            weight 1
            TCP_CHECK {
                connect_timeout 10
                nb_get_retry 3
                delay_before_retry 3
                connect_port 80
            }
        }
    }
    

    b.备服务器上配置文件做如下修改

    state ------>BACKUP #与MASTER对应
    priority ------>90  #小于100

    c.启动

    [root@lvs-master ~]# service keepalived start
    [root@lvs-master ~]# chkconfig keepalived on

    5.配置web服务器

    [root@web-1 init.d]# vim /etc/init.d/realserver
    #!/bin/bash
    SNS_VIP=172.16.0.100
    /etc/rc.d/init.d/functions
    case "$1" in
    start)
           ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
           /sbin/route add -host $SNS_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 $SNS_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
    
    [root@web-1 init.d]# chmod 755 realserver
    [root@web-1 init.d]# service realserver start

    6.安装lvs管理工具

    [root@lvs-master ~]# yum install ipvsadm
    [root@lvs-master ~]# ipvsadm -Ln
    IP Virtual Server version 1.2.1 (size=4096)
    Prot LocalAddress:Port Scheduler Flags
      -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
    TCP  172.16.0.100:80 rr persistent 50
      -> 172.16.0.113:80              Route   1      0          0         
      -> 172.16.0.114:80              Route   1      0          0 

    7.测试

    参考链接:
    http://www.cnblogs.com/edisonchou/p/4281978.html

  • 相关阅读:
    第一章--linux基础
    深入浅出OOP(一): 多态和继承(早期绑定/编译时多态)
    LeetCode Letter Combinations of a Phone Number
    ios 仿android gallery控件
    android何如获取SIM卡提供国家代码(ISO)
    android 获取 imei号码
    overridePendingTransition的简介
    转 Android Activity之间动画完整版详解
    【android开发】使用PopupWindow实现页面点击顶部弹出下拉菜单
    Android 带你从源码的角度解析Scroller的滚动实现原理
  • 原文地址:https://www.cnblogs.com/fanren224/p/8457243.html
Copyright © 2020-2023  润新知