126.3. HAProxy and Keepalived (Virtual IP)

简介:
# yum install -y keepalived
# chkconfig keepalived on 
		
# echo "net.ipv4.ip_nonlocal_bind = 1" >> /etc/sysctl.conf
# sysctl -p		
		

例 126.2. /etc/keepalived/keepalived.conf

Master

vrrp_script chk_haproxy {
   script "killall -0 haproxy"   # verify the pid existance
   interval 2                    # check every 2 seconds
   weight 2                      # add 2 points of prio if OK
}
 
vrrp_instance VI_1 {
   interface eth0                # interface to monitor
   state MASTER
   virtual_router_id 51          # Assign one ID for this route
   priority 101                  # 101 on master, 100 on backup
   virtual_ipaddress {
       192.168.10.100            # the virtual IP
   }
   track_script {
       chk_haproxy
   }
}
			

Slave

vrrp_script chk_haproxy {
   script "killall -0 haproxy"   # verify the pid existance
   interval 2                    # check every 2 seconds
   weight 2                      # add 2 points of prio if OK
}
 
vrrp_instance VI_1 {
   interface eth0                # interface to monitor
   state MASTER
   virtual_router_id 51          # Assign one ID for this route
   priority 100                  # 101 on master, 100 on backup
   virtual_ipaddress {
       192.168.10.100            # the virtual IP
   }
   track_script {
       chk_haproxy
   }
}			
			


启动keepalived

/etc/init.d/keepalived start
		

检查IP地址与主从状态

SLB1 IP:

$ ip a | grep -e inet.*eth0
 inet 192.168.10.101/24 brd 192.168.10.255 scope global eth0
 inet 192.168.10.100/32 scope global eth0
LB1 Keepalived state:

$ cat /var/log/messages | grep VRRP_Instance
Apr 19 15:47:25 lb1 Keepalived_vrrp[6146]: VRRP_Instance(VI_1) Transition to MASTER STATE
Apr 19 15:47:25 lb1 Keepalived_vrrp[6146]: VRRP_Instance(VI_1) Entering MASTER STATE
		

SLB2 IP:

$ ip a | grep -e inet.*eth0
 inet 192.168.10.102/24 brd 192.168.10.255 scope global eth0
LB2 Keepalived state:

$ cat /var/log/messages | grep VRRP_Instance
Apr 19 15:47:25 lb2 Keepalived_vrrp[6146]: VRRP_Instance(VI_1) Transition to MASTER STATE
Apr 19 15:47:25 lb2 Keepalived_vrrp[6146]: VRRP_Instance(VI_1) Received higher prio advert
Apr 19 15:47:25 lb2 Keepalived_vrrp[6146]: VRRP_Instance(VI_1) Entering BACKUP STATE
		




原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
相关文章
|
负载均衡 监控 Linux
LVS + keepalived
LVS + keepalived
260 1
基于keepalived+lvs支持多虚拟IP
好久没写博客了,这篇是今年的第一篇博客哈!上周五加班到凌晨3点多,对系统进行了升级合并,对于keepalived+lvs支持一个虚拟IP变更成支持多个虚拟IP。为什么要用到多个虚拟IP,因为系统要和别的服务系统有数据传输,另一方面和客户端有交互,所以定于和服务系统走的内网传输,和客户端用外网传输,这样下来的话我们会节省外网网卡的带宽资源,减轻外网网卡的压力,实际上有个很简单的办法,就是用单个的虚拟IP,然后虚拟IP在防火墙上映射为一个外网IP地址供客户端使用,但是经过与网络部沟通,告知防火墙上做不了映射,原因我就没细问了,所以才产生了上述所说的这个方案。
1526 0
|
移动开发 网络协议 Shell
LVS+KEEPALIVED 安装与配置实例
--------------------------------------master--------------------------------------- echo "1" > /proc/sys/net/ipv4/ip_forward wget http://www.
1322 0
|
网络协议
KEEPALIVED 做LVS+HA实例安装与配置
--------------------------------------master------------------------------------------------------- wget http://www.
1043 0
|
网络协议 MySQL 关系型数据库
|
网络协议 开发工具

热门文章

最新文章