keepalived 高可用,监控web服务器状态

 

一、keepalived 高可用,监控web服务器状态

4.1 安装 两台机器,一组一丛

 

yum install -y keepalived

 

主机器配置,虚拟ip为:192.168.1.100

vrrp_instance VI_1 {
    state MASTER  # 备用服务器上为BACKUP
    interface eth0
    virtual_router_id 51
    priority 100 #备用服务器上为90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.100
    }
}
 
virtual_server 192.168.1.100 80 {
    delay_loop 6 # 每个6秒查询Realserver状态
    lb_algo rr   # lvs算法
    lb_kind DR   # Direct Route
    persistence_timeout 0 # 同一IP链接60秒内被分配到同一台realserver
    protocol TCP            #用tcp协议检查realserver状态
 
    real_server 192.168.1.27 80{
        weight 100
        TCP_CHECK {
            connect_timeout 10 #10秒钟无响应超时
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
        }
    }
 
    real_server 192.168.1.28 80{
        weight 100
        TCP_CHECK {
            connect_timeout 10 #10秒钟无响应超时
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
        }
    }
}

 

keepalived从机器上

 

vrrp_instance VI_1 {
    state BACKUP  # 备用服务器上为BACKUP
    interface eth0
    virtual_router_id 51
    priority 90 #备用服务器上为90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.100
    }
}
 
virtual_server 192.168.1.100 80 {
    delay_loop 6 # 每个6秒查询Realserver状态
    lb_algo rr   # lvs算法
    lb_kind DR   # Direct Route
    persistence_timeout 0 # 同一IP链接60秒内被分配到同一台realserver
    protocol TCP            #用tcp协议检查realserver状态
 
    real_server 192.168.1.27 80{
        weight 100
        TCP_CHECK {
            connect_timeout 10 #10秒钟无响应超时
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
        }
    }
 
    real_server 192.168.1.28 80{
        weight 100
        TCP_CHECK {
            connect_timeout 10 #10秒钟无响应超时
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
        }
    }
}

 

启动主和备用机器的keepalived服务

/etc/init.d/keepalived start

 

查看端口转发规则

ipvsadm -ln 

 

你可能感兴趣的:(keepalived,Linux)