在Ubuntu20.04 安装P4-OvS

在Ubuntu20.04 安装P4-OvS

P4-OvS

Git项目地址:https://github.com/osinstom/P4-OvS
安装文档:https://github.com/osinstom/P4-OvS/blob/p4/Documentation/intro/install/general.rst

安装步骤

在桌面创建文件夹P4
# cd P4

#第一步  ==安装依赖项依赖==
# apt-get update
# sudo apt-get install -y automake cmake libjudy-dev libgmp-dev libpcap-dev libboost-all-dev libevent-dev libtool flex bison pkg-config g++ libssl-dev libnanomsg-dev libjudy-dev libreadline-dev valgrind libtool-bin libboost-dev libboost-system-dev libboost-thread-dev
# sudo apt-get install -y python3-pip python3-dev
# sudo pip3 install nnpy

#第二步 == Thrift ==
# cd "$BASE_DIR"
# git clone https://github.com/apache/thrift.git
# cd thrift
# git checkout v0.13.0
# ./bootstrap.sh
# ./configure --prefix=/usr
# make
# sudo make install
# cd ..

#第三步 == PI ==
# sudo apt install -y libnanomsg-dev \
   libprotobuf-dev protobuf-compiler protobuf-compiler-grpc \
   libgrpc++-dev libgrpc-dev libgc-dev

# cd "$BASE_DIR"
# git clone https://github.com/osinstom/PI.git   # *NOT* upstream: https://github.com/p4lang/PI
# cd PI
# git checkout p4-ovs
# git submodule update --init
# ./autogen.sh
# ./configure --prefix=/usr --with-proto --with-fe-cpp --with-cli --with-internal-rpc --with-gnu-ld
# make
# sudo make install
# cd ..

#第四步 == P4-OvS ==
# cd "$BASE_DIR"
# git clone https://github.com/simula/P4-OvS.git
# cd P4-OvS
# git remote add upstream https://github.com/osinstom/P4-OvS.git
# git checkout dreibh/build-fix-16Dec2020
# ./boot.sh
# ./configure
# make
# make install
# cd ..

#第五步 == ovs ==(openvswitch)
# cd "$BASE_DIR"
# git clone https://github.com/openvswitch/ovs.git
# cd ovs

开始配置
# ./boot.sh(在ovs工程根目录下)

构建Linux内核模块
# ./configure -with-linux=/lib/modules/$(uname -r)/build

开始安装
# make
# make install (默认情况下在/usr/local)
# make modules_install (您构建了内核模块,则可以安装它们)

您的机器上可能已经安装了来自上游 Linux(在不同目录中)的 Open vSwitch 内核模块。为了确保加载从该存储库构建的 Open vSwitch 内核模块,您应该创建一个depmod.d文件,该文件优先于新安装的内核模块而不是来自上游 Linux 的内核模块。
# config_file="/etc/depmod.d/openvswitch.conf"
# for module in datapath/linux/*.ko; do
  	modname="\$(basename \${module})"
  	echo "override \${modname%.ko} * extra" >> "\$config_file"
 	echo "override \${modname%.ko} * weak-updates" >> "\$config_file"
  done
# depmod -a

加载内核模块
# /sbin/modprobe openvswitch

验证模块是否已加载
# /sbin/lsmod | grep openvswitch
# sudo insmod datapath/linux/openvswitch.ko

启动程序
# export PATH=$PATH:/usr/local/share/openvswitch/scripts
# ovs-ctl start

启动数据库

配置数据库
$ mkdir -p /usr/local/etc/openvswitch
$ ovsdb-tool create /usr/local/etc/openvswitch/conf.db  vswitchd/vswitch.ovsschema

$ mkdir -p /usr/local/var/run/openvswitch 
$ ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock 
	--remote=db:Open_vSwitch,Open_vSwitch,manager_options 
    --private-key=db:Open_vSwitch,SSL,private_key 
    --certificate=db:Open_vSwitch,SSL,certificate 
    --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert 
    --pidfile --detach - -日志文件

初始化数据库
$ sudo ovs-vsctl --no-wait init
启动守护进程
$ sudo ovs-vswitchd --pidfile --detach --log-file

到这里已经配置好了。接下来做测试

open vswitch常用操作

添加网桥:ovs-vsctl add-br br0
列出open vswitch中的所有网桥:ovs-vsctl list-br
判断网桥是否存在:ovs-vsctl br-exists br0
将物理网卡挂接到网桥:ovs-vsctl add-port br0 eth0
列出网桥中的所有端口:ovs-vsctl list-ports br0
列出所有挂接到网卡的网桥:ovs-vsctl port-to-br eth0
查看open vswitch的网络状态:ovs-vsctl show
删除网桥上已经挂接的网口:vs-vsctl del-port br0 eth0
删除网桥:ovs-vsctl del-br br0

安装是遇到的问题1

p4rt/.libs/libp4rt.a(p4rt_libp4rt_la-p4rt.o): In function `p4rt_initialize_datapath':
/home/vetletm/P4-OvS/p4rt/p4rt.c:611: undefined reference to `PIGrpcServerPipelineConfigSet'
collect2: error: ld returned 1 exit status
Makefile:3841: recipe for target 'vswitchd/ovs-vswitchd' failed
make[2]: *** [vswitchd/ovs-vswitchd] Error 1
make[2]: Leaving directory '/home/vetletm/P4-OvS'
Makefile:5238: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/vetletm/P4-OvS'
Makefile:2887: recipe for target 'all' failed
make: *** [all] Error 2

这个问题是找不到这个方法:PIGrpcServerPipelineConfigSet。这个方法是C编译的,没有引用。出现这个问题就是没有进行安装第四步,也就是安装ovs,缺少东西
解决方法就是上面安装方法第五步克隆ovs,在配置一遍

安装时遇到问题2

缺少db.sock  找不到文件或文件夹
最近服务器上ovs突然崩溃掉,ovs-vsctl查看时:

|00001|reconnect|WARN|unix:/var/run/openvswitch/db.sock: connection attempt failed (No such file or directory)
ovs-vsctl: unix:/var/run/openvswitch/db.sock: database connection failed (No such file or directory)

解决方法:
先杀掉ovsdb进程,然后重启服务
killall ovsdb-server
service openvswitch-switch force-reload-kmod

安装时遇到的问题3

ovs安装启动出现错误

ovs-vsctl: unix:/usr/local/var/run/openvswitch/db.sock: database connection failed (No such file or directory)
ovs-vsctl exited with code 1
*** Error connecting to ovs-db with ovs-vsctl
Make sure that Open vSwitch is installed, that ovsdb-server is running, and that
"ovs-vsctl show" works correctly.
You may wish to try "service openvswitch-switch start"


========解决方法========
# sudo ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --pidfile --detach
# sudo ovs-vsctl --no-wait init (初始化数据库)
# sudo ovs-vswitchd --pidfile --detach --log-file (启动 Open vSwitch daemon,连接到同样的 Unix domain socket 上)

如果仍然有问题:
ovsdb-server: I/O error: open: /usr/local/etc/openvswitch/conf.db failed (No such file or directory)

在进行一次上面配置数据库的内容
# sudo mkdir -p /usr/local/etc/openvswitch
# sudo ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema

Ovs的卸载

启动ovs之后,如果改动ovs源代码并且想更新ovs服务,进行如下操作:

# ovs-ctl stop 停止ovs服务
# ovs-dpctl show查看内核,会有一个ovs-system的datapath
# ovs-dpctl del-dp ovs-system 删除上一步出现的datapath(不进行这一步,rmmod可能会报错)
# rmmod  openvswitch 卸载openvswitch内核模块,使用lsmod | grep openvswitch 没有openvswitch
# 进入ovs源代码目录,按照前述编译步骤``重新编译安装

帮助来源网址:

https://blog.csdn.net/u011412226/article/details/80847911
https://www.cnblogs.com/buptmuye/p/3698855.html
https://blog.csdn.net/Sherry_Rui/article/details/49928051
https://www.cnblogs.com/yearsj/p/9648749.html

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值