LVS+Keepalived实现高可用集群 二

时间:2021-10-04 01:21:03

五.利用Keepalvied实现负载均衡和和高可用性

1.配置在主负载均衡服务器上配置keepalived.conf

#vi /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 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

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 {
        192.168.2.170
    }
}

virtual_server 192.168.2.170 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    persistence_timeout 60
    protocol TCP
  
    real_server 192.168.2.171 80 {
        weight 3            
        TCP_CHECK {
        connect_timeout 10  
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
 } 
    }

    real_server 192.168.2.172 80 {
        weight 3
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80

        }

     }

}

 

在备用调度器上:

#vi /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 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.2.170
    }
}

virtual_server 192.168.2.170 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    persistence_timeout 60
    protocol TCP
  
    real_server 192.168.2.171 80 {
        weight 3            
        TCP_CHECK {
        connect_timeout 10  
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
 } 
    }

    real_server 192.168.2.172 80 {
        weight 3
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80

        }

     }

}

 

2. BACKUP服务器同上配置,先安装lvs再按装keepalived,仍后配置/etc/keepalived/keepalived.conf,只需将红色标示的部分改一下即可.

3. vi /etc/rc.local
   #/usr/local/sbin/lvs-dr.sh  
lvs-dr.sh这个脚本注释掉。
   #/usr/local/sbin/lvs-dr.sh stop
停止lvs-dr脚本
   #/etc/init.d/keepalived start  
启动keepalived 服务,keepalived就能利用keepalived.conf
   
文件,实现负载均衡和高可用.

4.
查看lvs服务是否正常
  

#watch ipvsadm –ln

 

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddressort Scheduler Flags

  -> RemoteAddressort           Forward Weight ActiveConn InActConn

TCP  61.164.122.8:80 wrr persistent 60

  -> 61.164.122.10:80            Route   3      0          0

  -> 61.164.122.9:80             Route   3      0          0

复制代码

#tail –f /var/log/message  监听日志,查看状态,测试LVS负载均衡及高可用性是否有效。

5
.停Master服务器的keepalived服务,查看BAKCUP服务器是否能正常接管服务。


四.相关参考

1LVS 基础知识汇总


LVS
的算法介绍            http://www.linuxtone.org/viewthread.php?tid=69
学习LVS的三种转发模式     http://www.linuxtone.org/viewthread.php?tid=77
LVS
中的IP负载均衡技术     http://www.linuxtone.org/viewthread.php?tid=68

更多的请到http://www.linuxtone.org 负载均衡版查看

Keepalived
相关参考资料。
   
http://www.keepalived.org/documentation.html

原文地址 http://blog.chinaunix.net/u/18630/showart_1889903