lvs+keepalived高可用

lvs

这里配置DR模式


image.png

客户端ip 192.168.200.177
lvs1 192.168.200.178
lvs2 192.168.200.179
rs1 192.168.200.180
rs2 192.168.200.181
虚拟VIP 192.168.200.182

lvs1 lvs2

yum install -y ipvsadm

vi /etc/sysctl.conf
#添加如下内容并保存退出
net.ipv4.ip_forward = 1
#执行如下命令使修改生效
sysctl -p


ifconfig ens33:9 192.168.200.182/24
ifconfig
image.png

查看

ipvsadm -Ln 查看
image.png

rs1 rs2
yum install -y httpd
echo this is RS01 > /var/www/html/index.html

echo 1 > /proc/sys/net/ipv4/conf/ens33/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/ens33/arp_announce

# 配置VIP到l0网卡
ifconfig lo:9 192.168.200.182 netmask 255.255.255.255
#查看
ifconfig
image.png

设置规则

#rr表示采用轮询
#-g表示采用DR模式
ipvsadm -A -t 192.168.200.182:80 -s rr
ipvsadm -a -t 192.168.200.182:80 -r 192.168.200.180 -g
ipvsadm -a -t 192.168.200.182:80 -r 192.168.200.181 -g
ipvsadm -Ln
image.png

keepalived

查看keepalived.conf如何配置

man 5 keepalived.conf

master 178

! Configuration File for keepalived

global_defs {
   router_id LVS_178
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    #192.168.200.182/24 dev ens33 label ens33:9
    192.168.200.182
    }
}

virtual_server 192.168.200.182 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 0
    protocol TCP

    real_server 192.168.200.180 80 {
        weight 1
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }

    real_server 192.168.200.181 80 {
        weight 1
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
}


backup 179

! Configuration File for keepalived

global_defs {
   router_id LVS_178
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    #192.168.200.182/24 dev ens33 label ens33:9
    192.168.200.182
    }
}

virtual_server 192.168.200.182 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 0
    protocol TCP

    real_server 192.168.200.180 80 {
        weight 1
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }

    real_server 192.168.200.181 80 {
        weight 1
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
}


最后启动

service keepalived start
ipvsadm -Ln

master配置文件 192.168.200.178
keepalived作用层是三层(网络层) 四层 五层
keepalived给real server 发送一个TCMP的数据包,心跳检查

你可能感兴趣的:(lvs+keepalived高可用)