关于lvs:用eBPFXDP来替代LVS
前文剖析了 LVS 作为负载平衡的原理。随着 eBPF 的倒退,咱们曾经能够将 eBPF/XDP 程序间接部署在一般服务器上来实现负载平衡,从而节俭掉用于专门部署 LVS 的机器。 本文不打算间接到这一步,而是首先看看如何用 eBPF/XDP 依照惯例模式来代替 LVS,也就是说咱们还是将负载平衡程序(software load balance 简称 SLB)部署在专用机器上,只不过不必 LVS,而是用 eBPF/XDP 来实现。 试验步骤创立网络环境# 不同发行版命令不一样systemctl start dockerdocker network create south --subnet 172.19.0.0/16 --gateway 172.19.0.1# checkdocker network inspect south# orip link# 先用 ifconfig 取得刚创立的 network 应的 bridge# 后续则能够在宿主机上抓取这个 network 的所有 IP 包tcpdump -i br-3512959a6150 ip# 也能够取得某个容器的 veth ,抓取这个容器进出的所有包tcpdump -i vethf01d241 ip# 当然,如果是 offload 的模式,则调试的确不易,须要嗅探本地网络的数据包并抓取了# 在容器网络里,咱们尚有宿主机这个上帝视角,在裸机网络里,则可能得去捯饬路由器了 创立两个RSecho "rs-1" > rs1.htmlecho "rs-2" > rs2.htmldocker run -itd --name rs1 --hostname rs1 --privileged=true --net south -p 8888:80 --ip 172.19.0.2 --mac-address="02:42:ac:13:00:02" -v "$(pwd)"/rs1.html:/usr/share/nginx/html/index.html:ro nginx:stabledocker run -itd --name rs2 --hostname rs2 --privileged=true --net south -p 9999:80 --ip 172.19.0.3 --mac-address="02:42:ac:13:00:03" -v "$(pwd)"/rs2.html:/usr/share/nginx/html/index.html:ro nginx:stable# check on hostcurl 127.0.0.1:8888curl 127.0.0.1:9999另:即便是 nginx 对于咱们调试负载平衡也不是足够简略,调试阶段能够用 nc 来进行调试dnf install nc or apt install netcatserver side nc -l -vv -p 5000client side nc 172.19.0.2 5000 ...