首先验证内核版本uname -r
与你下载的OvS
版本是否匹配(必须),目前 OvS-3.2.1
最高只支持内核5.8
!
【版本适配关系表】
Linux内核与OvS版本匹配关系、OvS版本与DPDK版本匹配关系:
https://docs.openvswitch.org/en/latest/faq/releases/
【OvS版本路径列表】
Open vSwitch版本下载路径:
http://www.openvswitch.org/download/
以 OvS-2.16.0
为例,编译过程如下:
安装依赖包:
yum install wget git gcc autoconf automake libtool make pkg-config uuid kernel-devel-$(uname -r) -y
[root@localhost ~]# wget https://www.openvswitch.org/releases/openvswitch-2.16.0.tar.gz
[root@localhost ~]# tar zxvf openvswitch-2.16.0.tar.gz
[root@localhost ~]# cd openvswitch-2.16.0/
[root@localhost openvswitch-2.16.0]# ls
acinclude.m4 AUTHORS.rst config.h.in CONTRIBUTING.rst debian ipsec m4 Makefile.in ofproto poc rhel third-party Vagrantfile vtep
aclocal.m4 boot.sh configure datapath Documentation lib MAINTAINERS.rst NEWS ovsdb python selinux tutorial Vagrantfile-FreeBSD windows
appveyor.yml build-aux configure.ac datapath-windows include LICENSE Makefile.am NOTICE package.m4 README.rst tests utilities vswitchd xenserver
[root@localhost ~]# git clone https://github.com/openvswitch/ovs.git
[root@localhost tmp]# cd ovs
// git tag 或 git branch -a 查看所有分支,切换为稳定分支
[root@localhost ovs]# git branch
* master
[root@localhost ovs]# git tag
v0.90.0
...
v2.15.8
v2.16.0
v2.16.1
...
[root@localhost ovs]# git checkout v2.16.0
[root@localhost ovs]# ls
acinclude.m4 boot.sh CONTRIBUTING.rst Documentation lib MAINTAINERS.rst NOTICE poc rhel third-party Vagrantfile vtep
appveyor.yml build-aux datapath-windows include LICENSE Makefile.am ofproto python selinux tutorial Vagrantfile-FreeBSD windows
AUTHORS.rst configure.ac debian ipsec m4 NEWS ovsdb README.rst tests utilities vswitchd
# 当使用源代码时,需要自己创建configure脚本
[root@localhost openvswitch-2.16.0]# ./boot.sh
# 配置并开启内核模块编译,如无需编译openvswitch.ko等内核模块,则直接执行./configure即可
[root@localhost openvswitch-2.16.0]# ./configure --with-linux=/lib/modules/`uname -r`/build
# 编译安装OvS用户空间组件
[root@localhost openvswitch-2.16.0]# make && make install
# 安装内核模块,执行该步骤后,会使编译生成的openvswitch.ko等内核模块拷贝到/lib/modules/$(uname -r)/extra/目录下
[root@localhost openvswitch-2.16.0]# make modules_install
注意:如何不带配置选项
--with-linux=/lib/modules/$(uname -r)/build
,则表示使用当前系统内核附带的openvswitch.ko
模块。如果带有该配置选项,则表示在更新的Open vSwitch
版本基础上,基于当前的Linux
内核,构建新的openvswitch.ko
模块版本。
make modules_install
会使编译生成的openvswitch.ko
等内核模块安装到系统默认的/lib/modules/$(uname -r)/extra/
目录下,当使用modprobe openvswitch
时,则会直接加载该目录下的openvswitch.ko
模块。
【拓展】
Linux系统中,模块默认安装在
/lib/modules/$(KERNELRELEASE)/kernel/
。外部模块默认安装在
/lib/modules/$(KERNELRELEASE)/extra/
。改变默认安装目录的前置路径,编译时设置
INSTALL_MOD_PATH
即可,如下:
make INSTALL_MOD_PATH=/myown modules_install
把默认安装路径/lib/modules/$(KERNELRELEASE)/kernel/
更改为/myown/lib/modules/$(KERNELRELEASE)/kernel/
;该属性对编译kernel
结构内或结构外模块,都可以使用。
可以使用以下命令来查看 OvS
用户空间的组件,即可执行程序安装的位置:
[root@localhost ~]# whereis openvswitch
openvswitch: /etc/openvswitch /usr/local/etc/openvswitch /usr/include/openvswitch /usr/share/openvswitch
一般而言,OvS
可执行文件位于 /usr/local/sbin
目录下,数据库文件位于 /usr/local/etc/openvswitch
目录下。
openvswitch
有几个脚本放在 /usr/local/share/openvswitch/scripts
下,为了方便使用,可以设置 PATH
路径。由于运行需要 root
权限,可以切换到 root
,再设置 PATH
。
echo 'export PATH=$PATH:/usr/local/share/openvswitch/scripts' | tee -a /root/.bashrc
进行上面设置后,则可无需带文件路径,直接使用位于/usr/local/share/openvswitch/scripts/
目录下的ovs-ctl
等可执行程序。
# 查看系统自带openvswitch.ko模块信息,未执行上述make modules_install命令前
[root@localhost openvswitch-2.16.0]# modinfo openvswitch
filename: /lib/modules/4.18.0-394.el8.x86_64/kernel/net/openvswitch/openvswitch.ko.xz
alias: net-pf-16-proto-16-family-ovs_ct_limit
alias: net-pf-16-proto-16-family-ovs_meter
alias: net-pf-16-proto-16-family-ovs_packet
alias: net-pf-16-proto-16-family-ovs_flow
alias: net-pf-16-proto-16-family-ovs_vport
alias: net-pf-16-proto-16-family-ovs_datapath
license: GPL
description: Open vSwitch switching datapath
rhelversion: 8.7
srcversion: F3F697B9C54245CFAFFDBC6
depends: nf_conntrack,nf_nat,nf_conncount,libcrc32c,nf_defrag_ipv6
intree: Y
name: openvswitch
vermagic: 4.18.0-394.el8.x86_64 SMP mod_unload modversions
sig_id: PKCS#7
signer: CentOS kernel signing key
sig_key: 63:93:7D:30:8C:56:B6:89:97:5E:B1:FE:1B:5B:91:73:BC:D2:CA:D2
...
# 查看自己编译的 openvswitch.ko 依赖的模块
[root@localhost openvswitch-2.16.0]# modinfo ./datapath/linux/openvswitch.ko
filename: /tmp/openvswitch-2.16.0/./datapath/linux/openvswitch.ko
alias: net-pf-16-proto-16-family-ovs_ct_limit
alias: net-pf-16-proto-16-family-ovs_meter
alias: net-pf-16-proto-16-family-ovs_packet
alias: net-pf-16-proto-16-family-ovs_flow
alias: net-pf-16-proto-16-family-ovs_vport
alias: net-pf-16-proto-16-family-ovs_datapath
version: 2.16.0
license: GPL
description: Open vSwitch switching datapath
rhelversion: 8.7
srcversion: 79E4AE8CCF8AE3FCD9DB165
depends: nf_conntrack,nf_nat,udp_tunnel,libcrc32c,nf_defrag_ipv6
name: openvswitch
vermagic: 4.18.0-394.el8.x86_64 SMP mod_unload modversions
# 查看depends:行,发现 openvswitch.ko 依赖于多个模块,但其中 udp_tunnel 和 libcrc32c 模块还未加载,于是先载入 udp_tunnel 和 libcrc32c
# 不同机器可能有所区别,根据实际依赖进行加载
[root@localhost openvswitch-2.16.0]# modprobe udp_tunnel
[root@localhost openvswitch-2.16.0]# modprobe libcrc32c
# 载入 openvswitch 模块
[root@localhost openvswitch-2.16.0]# modprobe openvswitch
=======================================================================================
# 也可使用如下方式加载openvswitch.ko模块,自己编译的openvswitch.ko模块位于datapath/linux/目录下
[root@localhost openvswitch-2.16.0]# insmod ./datapath/linux/openvswitch.ko
=======================================================================================
# 执行上述make modules_install命令后,查看模块载入情况,可以发现filename行的文件路径和之前有所不同
[root@localhost ~]# modinfo openvswitch
filename: /lib/modules/4.18.0-394.el8.x86_64/extra/openvswitch.ko
alias: net-pf-16-proto-16-family-ovs_ct_limit
alias: net-pf-16-proto-16-family-ovs_meter
alias: net-pf-16-proto-16-family-ovs_packet
alias: net-pf-16-proto-16-family-ovs_flow
alias: net-pf-16-proto-16-family-ovs_vport
alias: net-pf-16-proto-16-family-ovs_datapath
version: 2.16.0
license: GPL
description: Open vSwitch switching datapath
rhelversion: 8.7
srcversion: 79E4AE8CCF8AE3FCD9DB165
depends: nf_conntrack,nf_nat,udp_tunnel,libcrc32c,nf_defrag_ipv6
name: openvswitch
vermagic: 4.18.0-394.el8.x86_64 SMP mod_unload modversions
sig_id: PKCS#7
signer: localhost
sig_key: 2E:DC:FD:33:39:74:46:20:22:5A:63:C7:1F:0C:90:CD:90:25:50:01
sig_hashalgo: sha256
...
[root@localhost openvswitch-2.16.0]# lsmod | grep openvswitch
openvswitch 184320 0
nf_conncount 16384 1 openvswitch
nf_nat 45056 3 ipt_MASQUERADE,openvswitch,nft_chain_nat
nf_conntrack 172032 5 xt_conntrack,nf_nat,ipt_MASQUERADE,openvswitch,nf_conncount
nf_defrag_ipv6 20480 2 nf_conntrack,openvswitch
libcrc32c 16384 5 nf_conntrack,nf_nat,openvswitch,nf_tables,xfs
【拓展】
modinfo openvswitch:可查看
openvswitch
依赖的模块。modprobe -D openvswitch:可查看加载的是
Linux
自带的openvswitch.ko
模块还是自己编译的openvswitch.ko
模块。/sbin/lsmod | grep openvswitch:查看安装是否成功。
# 根据下面openvswitch.ko模块位于extra路径下,可知加载的是自己编译的模块
[root@localhost ~]# modprobe -D openvswitch
insmod /lib/modules/4.18.0-394.el8.x86_64/kernel/arch/x86/crypto/crc32c-intel.ko.xz
insmod /lib/modules/4.18.0-394.el8.x86_64/kernel/lib/libcrc32c.ko.xz
insmod /lib/modules/4.18.0-394.el8.x86_64/kernel/net/ipv4/udp_tunnel.ko.xz
insmod /lib/modules/4.18.0-394.el8.x86_64/kernel/net/ipv4/netfilter/nf_defrag_ipv4.ko.xz
insmod /lib/modules/4.18.0-394.el8.x86_64/kernel/net/ipv6/netfilter/nf_defrag_ipv6.ko.xz
install /sbin/modprobe --ignore-install nf_conntrack $CMDLINE_OPTS && /sbin/sysctl --quiet --pattern 'net[.]netfilter[.]nf_conntrack.*' --system
insmod /lib/modules/4.18.0-394.el8.x86_64/kernel/net/netfilter/nf_nat.ko.xz
insmod /lib/modules/4.18.0-394.el8.x86_64/extra/openvswitch.ko
# 创建 ovsdb 数据库目录
[root@localhost openvswitch-2.16.0]# mkdir -p /usr/local/etc/openvswitch
# 使用当前目录下的/vswitchd/vswitch.ovsschema创建一个名为 "conf.db" 的空数据库文件,并将其保存在上一步创建的目录中
[root@localhost openvswitch-2.16.0]# ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema
[root@localhost openvswitch-2.16.0]#
[root@localhost openvswitch-2.16.0]# ls ./vswitchd/vswitch.ovsschema
./vswitchd/vswitch.ovsschema
[root@localhost openvswitch-2.16.0]# ls -l /usr/local/etc/openvswitch/
total 16
-rw-r----- 1 root root 14800 Dec 5 10:26 conf.db
[root@localhost openvswitch-2.16.0]#
# 配置启动 ovsdb 数据库
# 使用以下命令来启动 ovsdb-server 并加载刚才创建的数据库文件:
[root@localhost openvswitch-2.16.0]# 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
# 初始化数据库
[root@localhost openvswitch-2.16.0]# ovs-vsctl --no-wait init
# 开启 Open vSwitch 守护进程
[root@localhost openvswitch-2.16.0]# ovs-vswitchd --pidfile --detach
2023-12-05T08:45:16Z|00001|ovs_numa|INFO|Discovered 32 CPU cores on NUMA node 0
2023-12-05T08:45:16Z|00002|ovs_numa|INFO|Discovered 32 CPU cores on NUMA node 1
2023-12-05T08:45:16Z|00003|ovs_numa|INFO|Discovered 2 NUMA nodes and 64 CPU cores
2023-12-05T08:45:16Z|00004|reconnect|INFO|unix:/usr/local/var/run/openvswitch/db.sock: connecting...
2023-12-05T08:45:16Z|00005|reconnect|INFO|unix:/usr/local/var/run/openvswitch/db.sock: connected
【ovsdb-server中的参数含义】
--remote
: 指定ovsdb-server
的远程访问方式。punix:/usr/local/var/run/openvswitch/db.sock
表示通过Unix
域套接字连接本地主机,db:Open_vSwitch,manager_options
则指定了Open_vSwitch
数据库和manager_options
表。--private-key
: 指定SSL
加密所用的私钥文件。--certificate
:指定SSL
加密所用的证书文件。--bootstrap-ca-cert
:指定用于CA
证书认证的根证书文件。--pidfile
:将ovsdb-server
进程ID
写入PID
文件以便后续管理。--detach
:让ovsdb-server
在后台以守护进程模式运行。启动成功后,
ovsdb-server
将加载conf.db
数据库,并等待来自其他Open vSwitch
组件的连接请求。
看到类似以下几行消息,表明 openvswitch
配置完毕
2023-12-05T08:45:16Z|00001|ovs_numa|INFO|Discovered 32 CPU cores on NUMA node 0
2023-12-05T08:45:16Z|00002|ovs_numa|INFO|Discovered 32 CPU cores on NUMA node 1
2023-12-05T08:45:16Z|00003|ovs_numa|INFO|Discovered 2 NUMA nodes and 64 CPU cores
2023-12-05T08:45:16Z|00004|reconnect|INFO|unix:/usr/local/var/run/openvswitch/db.sock: connecting...
2023-12-05T08:45:16Z|00005|reconnect|INFO|unix:/usr/local/var/run/openvswitch/db.sock: connected
注意:以上操作是在
root
账户下进行,普通账户请注意切换权限。
创建 OvS
服务脚本。
[root@localhost ~]# touch /etc/systemd/system/ovs.service
[root@localhost ~]# vi /etc/systemd/system/ovs.service
脚本内容如下:
[Unit]
Description=Open vSwitch server daemon
After=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/share/openvswitch/scripts/ovs-ctl start
ExecStop=/usr/local/share/openvswitch/scripts/ovs-ctl stop
[Install]
WantedBy=multi-user.target
加载服务并设置开机自启
systemctl daemon-reload
systemctl enable ovs
查看重启操作系统后,OvS
的状态:
# systemctl查看OvS服务的状态,可知系统启动后OvS服务已被自动启动
[root@localhost ~]# systemctl status ovs
● ovs.service - Open vSwitch server daemon
Loaded: loaded (/etc/systemd/system/ovs.service; enabled; vendor preset: disabled)
Active: active (exited) since Wed 2023-12-06 04:21:51 SAST; 1min 31s ago
Process: 1766 ExecStart=/usr/local/share/openvswitch/scripts/ovs-ctl start (code=exited, status=0/SUCCESS)
Main PID: 1766 (code=exited, status=0/SUCCESS)
Tasks: 4 (limit: 409648)
Memory: 20.3M
CGroup: /system.slice/ovs.service
├─1833 ovsdb-server: monitoring pid 1834 (healthy)
├─1834 ovsdb-server /usr/local/etc/openvswitch/conf.db -vconsole:emer -vsyslog:err -vfile:info --remote=punix:/usr/local/var/run/openvswitch/db.sock --private-key=db:Open_vSwitch,SSL,private_key --cer>
├─2166 ovs-vswitchd: monitoring pid 2167 (healthy)
└─2167 ovs-vswitchd unix:/usr/local/var/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --no-chdir --log-file=/usr/local/var/log/openvswitch/ovs-vswitchd.log --pidfile=/usr/>
Dec 06 04:21:49 localhost ovs-ctl[1766]: Starting ovsdb-server [ OK ]
Dec 06 04:21:49 localhost ovs-vsctl[1841]: ovs|00001|vsctl|INFO|Called as ovs-vsctl --no-wait -- init -- set Open_vSwitch . db-version=8.3.0
Dec 06 04:21:49 localhost ovs-ctl[1766]: system ID not configured, please use --system-id ... failed!
Dec 06 04:21:49 localhost ovs-vsctl[1868]: ovs|00001|vsctl|INFO|Called as ovs-vsctl --no-wait set Open_vSwitch . ovs-version=2.16.0 "external-ids:system-id=\"\"" "external-ids:rundir=\"/usr/local/var/run/open>
Dec 06 04:21:49 localhost ovs-ctl[1766]: Configuring Open vSwitch system IDs [ OK ]
Dec 06 04:21:51 localhost ovs-ctl[1869]: Inserting openvswitch module [ OK ]
Dec 06 04:21:51 localhost ovs-ctl[1766]: Starting ovs-vswitchd [ OK ]
Dec 06 04:21:51 localhost ovs-vsctl[2179]: ovs|00001|vsctl|INFO|Called as ovs-vsctl --no-wait add Open_vSwitch . external-ids hostname=localhost
Dec 06 04:21:51 localhost ovs-ctl[1766]: Enabling remote OVSDB managers [ OK ]
Dec 06 04:21:51 localhost systemd[1]: Started Open vSwitch server daemon.
# OvS已成功启动
[root@localhost ~]# ovs-vsctl show
d90dc0bb-1632-463a-b2ee-b266360b8b57
ovs_version: "2.16.0"
# systemctl命令停止OvS服务
[root@localhost ~]# systemctl stop ovs
# systemctl查看OvS服务的状态,可知OvS服务已停止运行
[root@localhost ~]# systemctl status ovs
● ovs.service - Open vSwitch server daemon
Loaded: loaded (/etc/systemd/system/ovs.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Wed 2023-12-06 04:23:54 SAST; 2s ago
Process: 2947 ExecStop=/usr/local/share/openvswitch/scripts/ovs-ctl stop (code=exited, status=0/SUCCESS)
Process: 1766 ExecStart=/usr/local/share/openvswitch/scripts/ovs-ctl start (code=exited, status=0/SUCCESS)
Main PID: 1766 (code=exited, status=0/SUCCESS)
Dec 06 04:21:51 localhost ovs-ctl[1869]: Inserting openvswitch module [ OK ]
Dec 06 04:21:51 localhost ovs-ctl[1766]: Starting ovs-vswitchd [ OK ]
Dec 06 04:21:51 localhost ovs-vsctl[2179]: ovs|00001|vsctl|INFO|Called as ovs-vsctl --no-wait add Open_vSwitch . external-ids hostname=localhost
Dec 06 04:21:51 localhost ovs-ctl[1766]: Enabling remote OVSDB managers [ OK ]
Dec 06 04:21:51 localhost systemd[1]: Started Open vSwitch server daemon.
Dec 06 04:23:53 localhost systemd[1]: Stopping Open vSwitch server daemon...
Dec 06 04:23:53 localhost ovs-ctl[2947]: Exiting ovs-vswitchd (2167) [ OK ]
Dec 06 04:23:53 localhost ovs-ctl[2947]: Exiting ovsdb-server (1834) [ OK ]
Dec 06 04:23:54 localhost systemd[1]: ovs.service: Succeeded.
Dec 06 04:23:54 localhost systemd[1]: Stopped Open vSwitch server daemon.
# systemctl命令启动OvS服务
[root@localhost ~]# systemctl start ovs
# OvS已成功启动
[root@localhost ~]# ovs-vsctl show
d90dc0bb-1632-463a-b2ee-b266360b8b57
ovs_version: "2.16.0"
# systemctl查看OvS服务的状态,服务已成功启动
[root@localhost ~]# systemctl status ovs
● ovs.service - Open vSwitch server daemon
Loaded: loaded (/etc/systemd/system/ovs.service; enabled; vendor preset: disabled)
Active: active (exited) since Wed 2023-12-06 04:24:02 SAST; 10s ago
Process: 2947 ExecStop=/usr/local/share/openvswitch/scripts/ovs-ctl stop (code=exited, status=0/SUCCESS)
Process: 2977 ExecStart=/usr/local/share/openvswitch/scripts/ovs-ctl start (code=exited, status=0/SUCCESS)
Main PID: 2977 (code=exited, status=0/SUCCESS)
Tasks: 4 (limit: 409648)
Memory: 4.0M
CGroup: /system.slice/ovs.service
├─2991 ovsdb-server: monitoring pid 2992 (healthy)
├─2992 ovsdb-server /usr/local/etc/openvswitch/conf.db -vconsole:emer -vsyslog:err -vfile:info --remote=punix:/usr/local/var/run/openvswitch/db.sock --private-key=db:Open_vSwitch,SSL,private_key --cer>
├─3008 ovs-vswitchd: monitoring pid 3009 (healthy)
└─3009 ovs-vswitchd unix:/usr/local/var/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --no-chdir --log-file=/usr/local/var/log/openvswitch/ovs-vswitchd.log --pidfile=/usr/>
Dec 06 04:24:02 localhost systemd[1]: Starting Open vSwitch server daemon...
Dec 06 04:24:02 localhost ovs-ctl[2977]: Starting ovsdb-server [ OK ]
Dec 06 04:24:02 localhost ovs-vsctl[2993]: ovs|00001|vsctl|INFO|Called as ovs-vsctl --no-wait -- init -- set Open_vSwitch . db-version=8.3.0
Dec 06 04:24:02 localhost ovs-ctl[2977]: system ID not configured, please use --system-id ... failed!
Dec 06 04:24:02 localhost ovs-vsctl[2997]: ovs|00001|vsctl|INFO|Called as ovs-vsctl --no-wait set Open_vSwitch . ovs-version=2.16.0 "external-ids:system-id=\"\"" "external-ids:rundir=\"/usr/local/var/run/open>
Dec 06 04:24:02 localhost ovs-ctl[2977]: Configuring Open vSwitch system IDs [ OK ]
Dec 06 04:24:02 localhost ovs-ctl[2977]: Starting ovs-vswitchd [ OK ]
Dec 06 04:24:02 localhost ovs-ctl[2977]: Enabling remote OVSDB managers [ OK ]
Dec 06 04:24:02 localhost systemd[1]: Started Open vSwitch server daemon.
Dec 06 04:24:02 localhost ovs-vsctl[3017]: ovs|00001|vsctl|INFO|Called as ovs-vsctl --no-wait add Open_vSwitch . external-ids hostname=localhost
[root@localhost ~]# lsmod | grep openvswitch
openvswitch 184320 2
nf_conncount 16384 1 openvswitch
nf_nat 45056 3 ipt_MASQUERADE,openvswitch,nft_chain_nat
nf_conntrack 172032 6 xt_conntrack,nf_nat,nfnetlink_cttimeout,ipt_MASQUERADE,openvswitch,nf_conncount
nf_defrag_ipv6 20480 2 nf_conntrack,openvswitch
libcrc32c 16384 5 nf_conntrack,nf_nat,openvswitch,nf_tables,xfs
# 停止ovs服务
[root@localhost ~]# /usr/local/share/openvswitch/scripts/ovs-ctl stop
Exiting ovs-vswitchd (951780) [ OK ]
Exiting ovsdb-server (951758) [ OK ]
#卸载openvswitch模块,报错显示openvswitch正在使用中
[root@localhost ~]# rmmod openvswitch
rmmod: ERROR: Module openvswitch is in use
[root@localhost ~]#
[root@localhost ~]# ovs-vsctl show
ovs-vsctl: unix:/usr/local/var/run/openvswitch/db.sock: database connection failed (No such file or directory)
# 查看内核,会有一个ovs-system的datapath
[root@localhost ~]# ovs-dpctl show
system@ovs-system:
lookups: hit:0 missed:0 lost:0
flows: 0
masks: hit:0 total:0 hit/pkt:0.00
caches:
masks-cache: size:256
port 0: ovs-system (internal)
port 1: br0 (internal)
# 删除上一步出现的datapath(不进行这一步,rmmod会报错)
[root@localhost ~]# ovs-dpctl del-dp ovs-system
[root@localhost ~]# ovs-dpctl show
# 卸载openvswitch内核模块
[root@localhost ~]# rmmod openvswitch
# 使用lsmod | grep openvswitch 没有openvswitch
[root@localhost ~]# lsmod | grep openvswitch
注意:上面最开始
rmmod openvswitch
失败,本质就是模块的模块的引用计数不为0
, 要解决此类问题,只需要使模块的引用计数为0
即可。因OvS
的datapath
即ovs-system
会使用openvswitch
模块,故如果不删除该datapath
,则无法卸载openvswitch
模块,删除后,则卸载openvswitch
模块成功。
原创不易,点个赞或在看支持一下吧~