LVS-DR模式部署流程

Posted liming-linux-python

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LVS-DR模式部署流程相关的知识,希望对你有一定的参考价值。

情景一

一、环境介绍
1)RIP、VIP、DIP为同一物理网络
2)LVS
Hostname:lvs
eth0:DIP-192.168.3.31
eth0:0:VIP-192.168.3.10
3)RS1
Hostname:web1
eth0:RIP-192.168.3.32
lo:0:VIP-192.168.3.10
4)RS2
Hostname:web2
eth0:RIP-192.168.3.33
lo:0:VIP-192.168.3.10
5)Client
Hostname:user
eth0:CIP-192.168.3.25
6)所有主机均使用Centos7

二、安装配置
1、清空节点防火墙规则
[[email protected] ~]# for i in filter nat mangle;do iptables -t $i -F && iptables -t $i -X && iptables -t $i -Z;done
[[email protected] ~]# for i in filter nat mangle;do iptables -t $i -F && iptables -t $i -X && iptables -t $i -Z;done
[[email protected] ~]# for i in filter nat mangle;do iptables -t $i -F && iptables -t $i -X && iptables -t $i -Z;done
[[email protected] ~]# for i in filter nat mangle;do iptables -t $i -F && iptables -t $i -X && iptables -t $i -Z;done
# 生产环境,防火墙规则根据实际情况进行配置

2、配置LVS-VIP
[[email protected] ~]# ifconfig eth0:0 192.168.3.10/32 broadcast 192.168.3.10 up # 注意子网掩码为32位;【broadcast 192.168.3.10】为可选配置,用以实现仅广播给自己
[[email protected] ~]# route add -host 192.168.3.10 dev eth0:0 # 此选项为可选配置,而RS必须如此配置
[[email protected] ~]# ifconfig eth0:0

[[email protected] ~]# ping -c 1 192.168.3.10 &>/dev/null && echo ok || echo false
ok
[[email protected] ~]# ping -c 1 192.168.3.10 &>/dev/null && echo ok || echo false
ok

3、配置RS-VIP
[[email protected] ~]# echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
[[email protected] ~]# echo "1" >/proc/sys/net/ipv4/conf/eth0/arp_ignore # 仅配置all即可,但为确保万无一失,同时为eth0进行配置
[[email protected] ~]# echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
[[email protected] ~]# echo "2" >/proc/sys/net/ipv4/conf/eth0/arp_announce
[[email protected] ~]# ifconfig lo:0 192.168.3.10/32 broadcast 192.168.3.10 up # 注意子网掩码为32位;【broadcast 192.168.3.10】用以实现仅广播给自己
[[email protected] ~]# route add -host 192.168.3.10 dev lo:0 # 确保必须由lo:0接口发送响应报文,以实现响应报文的源IP地址为VIP

[[email protected] ~]# echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
[[email protected] ~]# echo "1" >/proc/sys/net/ipv4/conf/eth0/arp_ignore
[[email protected] ~]# echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
[[email protected] ~]# echo "2" >/proc/sys/net/ipv4/conf/eth0/arp_announce
[[email protected] ~]# ifconfig lo:0 192.168.3.10/32 broadcast 192.168.3.10 up
[[email protected] ~]# route add -host 192.168.3.10 dev lo:0

[[email protected] ~]# ping -c 1 192.168.3.10 &>/dev/null && echo ok || echo false
ok
[[email protected] ~]# arp -a|grep 192.168.3.10|egrep -o "..:..:..:..:..:.."
00:0c:29:b2:e4:ec
[[email protected] ~]# ifconfig eth0:0|egrep -o "..:..:..:..:..:.."
00:0c:29:b2:e4:ec

4、配置RS-WEB
[[email protected] ~]# yum install -y nginx && echo "$HOSTNAME" > /usr/share/nginx/html/index.html && nginx && curl 127.0.0.1
web1
[[email protected] ~]# yum install -y nginx && echo "$HOSTNAME" > /usr/share/nginx/html/index.html && nginx && curl 127.0.0.1
web2

[[email protected] ~]# curl 192.168.3.32 192.168.3.33
web1
web2

5、配置LVS-IPVS
[[email protected] ~]# yum install -y ipvsadm
[[email protected] ~]# ipvsadm -A -t 192.168.3.10:80 -s rr
[[email protected] ~]# ipvsadm -a -t 192.168.3.10:80 -r 192.168.3.32 -g
[[email protected] ~]# ipvsadm -a -t 192.168.3.10:80 -r 192.168.3.33 -g

[[email protected] ~]# for i in {1..4};do curl 192.168.3.10;done
web1
web2
web1
web2

情景二


一、环境介绍
1)RIP、DIP为同一物理网络,VIP不与RIP、DIP在同一物理网络
2)LVS
Hostname:lvs
eth0:DIP-192.168.30.129
eth0:0:VIP-192.168.3.10
3)RS1
Hostname:web1
eth0:RIP-192.168.30.137
lo:0:VIP-192.168.3.10
4)RS2
Hostname:web2
eth0:RIP-192.168.30.131
lo:0:VIP-192.168.3.10
5)Client
Hostname:user
eth0:CIP-192.168.3.25
6)Route
Hostname:route
eth0:192.168.3.34
eth1:192.168.30.138
7)所有主机均使用Centos7

二、安装配置














































































































以上是关于LVS-DR模式部署流程的主要内容,如果未能解决你的问题,请参考以下文章

LVS负载均衡群集部署——DR模式的介绍及搭建步骤

LVS负载均衡群集DR模式+Keepalived部署!

LVS负载均衡群集DR模式+Keepalived部署!

直接进去正题!LVS-DR模式keppalived及LVS-DR-keepalived部署!

负载均衡LVS-DR模式群集部署实操

负载均衡LVS-DR模式群集部署实操