$ cd /path/to/dpdk-stable-18.11.2/ $ export RTE_SDK=$PWD $ cd /path/to/dpvs $ make $ make install # 查看bin目录下的二进制文件 $ ls /path/to/dpvs/bin/ dpip dpvs ipvsadm keepalived
# 注意查看make过程中的提示信息,尤其是keepalived部分,如果出现下面的部分则表示IPVS支持IPv6 Keepalived configuration ------------------------ Keepalived version : 2.0.19 Compiler : gcc Preprocessor flags : -D_GNU_SOURCE -I/usr/include/libnl3 Compiler flags : -g -g -O2 -fPIE -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -O2 Linker flags : -pie -Wl,-z,relro -Wl,-z,now Extra Lib : -lm -lcrypto -lssl -lnl-genl-3 -lnl-3 Use IPVS Framework : Yes IPVS use libnl : Yes IPVS syncd attributes : No IPVS 64 bit stats : No
$ dpip link show 1: dpdk0: socket 0 mtu 1500 rx-queue 16 tx-queue 16 UP 10000 Mbps full-duplex auto-nego addr AA:BB:CC:23:33:33 OF_RX_IP_CSUM OF_TX_IP_CSUM OF_TX_TCP_CSUM OF_TX_UDP_CSUM
$ ip a 67: dpdk0.kni: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether AA:BB:CC:23:33:33 brd ff:ff:ff:ff:ff:ff inet 1.1.1.1/24 brd 1.1.1.255 scope global dpdk0.kni valid_lft forever preferred_lft forever
# 接着我们需要添加两条路由,分为是wan口网段的路由和到RS机器网段的路由 $ dpip route add 10.0.96.0/24 dev dpdk2 $ dpip route add 192.168.229.0/24 dev dpdk0 # 最好再加一条到网关的默认路由保证ICMP数据包的回包能跑通 $ dpip route add default via 10.0.96.254 dev dpdk2
# 使用RR算法建立转发规则 # add service <VIP:vport> to forwarding, scheduling mode is RR. # use ipvsadm --help for more info. $ ipvsadm -A -t 10.0.96.204:80 -s rr
# 这里为了方便测试我们只添加一台RS # add two RS for service, forwarding mode is FNAT (-b) $ ipvsadm -a -t 10.0.96.204:80 -r 192.168.229.1 -b
# 添加LocalIP到网络中,FNAT模式这里需要 # add at least one Local-IP (LIP) for FNAT on LAN interface $ ipvsadm --add-laddr -z 192.168.229.204 -t 10.0.96.204:80 -F dpdk0
# 然后我们查看一下效果 $ dpip route show inet 192.168.229.204/32 via 0.0.0.0 src 0.0.0.0 dev dpdk0 mtu 1500 tos 0 scope host metric 0 proto auto inet 10.0.96.204/32 via 0.0.0.0 src 0.0.0.0 dev dpdk2 mtu 1500 tos 0 scope host metric 0 proto auto inet 10.0.96.0/24 via 0.0.0.0 src 0.0.0.0 dev dpdk2 mtu 1500 tos 0 scope link metric 0 proto auto inet 192.168.229.0/24 via 0.0.0.0 src 0.0.0.0 dev dpdk0 mtu 1500 tos 0 scope link metric 0 proto auto inet 0.0.0.0/0 via 10.0.96.254 src 0.0.0.0 dev dpdk2 mtu 1500 tos 0 scope global metric 0 proto auto
$ dpip addr show inet 10.0.96.204/32 scope global dpdk2 valid_lft forever preferred_lft forever inet 192.168.229.204/32 scope global dpdk0 valid_lft forever preferred_lft forever
location / { default_type text/plain; return200"Your IP and port is $remote_addr:$remote_port\n"; }
}
直接对VIP使用ping和curl命令进行测试:
1 2 3 4 5 6 7 8 9 10 11 12 13
$ ping -c4 10.0.96.204 PING 10.0.96.204 (10.0.96.204) 56(84) bytes of data. 64 bytes from 10.0.96.204: icmp_seq=1 ttl=54 time=47.2 ms 64 bytes from 10.0.96.204: icmp_seq=2 ttl=54 time=48.10 ms 64 bytes from 10.0.96.204: icmp_seq=3 ttl=54 time=48.5 ms 64 bytes from 10.0.96.204: icmp_seq=4 ttl=54 time=48.5 ms
--- 10.0.96.204 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 8ms rtt min/avg/max/mdev = 47.235/48.311/48.969/0.684 ms
$ curl 10.0.96.204 Your IP and port is 192.168.229.204:1033
TOA source code is included into DPVS project(in directory kmod/toa) since v1.7 to support IPv6 and NAT64. It is derived from the Alibaba TOA. For IPv6 applications which need client’s real IP address, we suggest to use this TOA version.