安装依赖库
apt install libnuma-dev
apt-get install libpopt-dev
编译dpvs
#编译dpdk
./scripts/dpdk-build.sh
#编译dpvs
export PKG_CONFIG_PATH=/root/dpvs/dpdk/dpdklib/lib/x86_64-linux-gnu/pkgconfig
make
#编译后,dpvs在src下,dpip在tools/dpip/build下
root@ubuntu:~/dpvs# ls src/dpvs
src/dpvs
root@ubuntu:~/dpvs# ls tools/dpip/build/dpip
tools/dpip/build/dpip
root@ubuntu:~/dpvs# ls tools/ipvsadm/ipvsadm
tools/ipvsadm/ipvsadm
root@ubuntu:~/dpvs# ls tools/keepalived/keepalived/keepalived
tools/keepalived/keepalived/keepalived
搭建dpdk环境并执行dpvs
# 搭建环境
echo 2048 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages
mkdir -p /mnt/huge
mount -t hugetlbfs nodev /mnt/huge
modprobe uio_pci_generic
insmod dpdk/dpdklib/rte_kni.ko carrier=on
./dpdk/dpdk-stable-20.11.1/usertools/dpdk-devbind.py -b uio_pci_generic 0000:00:09.0
#修改配置文件,队列个数为1,并且关闭flow
cp conf/dpvs.conf.single-nic.sample /etc/dpvs.conf
! netif config
netif_defs {
<init> pktpool_size 524287
<init> pktpool_cache 256
<init> device dpdk0 {
rx {
queue_number 1 -->flom 8 to 1
descriptor_number 1024
rss all
}
tx {
queue_number 1 -->flom 8 to 1
descriptor_number 1024
}
! mtu 1500
! promisc_mode
kni_name dpdk0.kni
}
}
! worker config (lcores)
worker_defs {
<init> worker cpu0 {
type master
cpu_id 0
}
<init> worker cpu1 {
type slave
cpu_id 1
port dpdk0 {
rx_queue_ids 0
tx_queue_ids 0
! isol_rx_cpu_ids 9
! isol_rxq_ring_sz 1048576
}
}
-->只保留一个worker
}
! ipvs config
ipvs_defs {
conn {
<init> conn_pool_size 209715 -- from 2097152 to 209715
<init> conn_pool_cache 256
conn_init_timeout 3
! expire_quiescent_template
! fast_xmit_close
! <init> redirect off
}
...
}
! sa_pool config
sa_pool {
pool_hash_size 16
flow_enable off --> from on to off
}
#运行dpvs
./src/dpvs
检查运行结果
#使用dpvs自带的dpip工具查看
root@ubuntu:~/dpvs# ./tools/dpip/build/dpip link show
1: dpdk0: socket 0 mtu 1500 rx-queue 1 tx-queue 1
UP 1000 Mbps full-duplex auto-nego
addr 08:00:27:F0:18:59 OF_RX_IP_CSUM OF_TX_IP_CSUM OF_TX_TCP_CSUM OF_TX_UDP_CSUM
#使用ip命令查看,会有一个kni接口
root@ubuntu:~/dpvs# ip link show
...
32: dpdk0.kni: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
问题
编译遇到的问题,如下所示:
1)没有头文件
/root/dpvs/src/common.c:24:10: fatal error: numa.h: No such file or directory
ipvsadm.c:114:10: fatal error: popt.h: No such file or directory
安装即可。
apt install libnuma-dev
apt-get install libpopt-dev
2>all warnings being treated as errors
/root/dpvs/src/ipv4.c: In function ‘ipv4_rcv_fin’:
/root/dpvs/src/ipv4.c:334:47: error: taking address of packed member of ‘struct rte_ipv4_hdr’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
修改:
src/Makefile 中加上 -Wno-address-of-packed-member
CFLAGS += -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -Wno-address-of-packed-member -mcmodel=medium
3>
参考
https://www.jianshu.com/p/07e80f6bf5af