ovs本身具有保存部分配置功能的方法,即通过ovs db保存配置,但是openflow流表在重启后无法保存。
在openvswitch的安装指南(INSTALL.md)中,有如下段话:
https://github.com/openvswitch/ovs/blob/master/INSTALL.md
An upgrade of userspace daemons means that they have to be restarted. Restarting the daemons means that the OpenFlow flows in the ovs-vswitchd daemon will be lost. One way to restore the flows is to let the controller re-populate it. Another way is to save the previous flows using a utility like ovs-ofctl and then re-add them after the restart. Restoring the old flows is accurate only if the new Open vSwitch interfaces retain the old 'ofport' values.
话里提到有两种方法避免丢失配置
1 使用控制器再下发一次流表
2 使用工具,例如ovs-ofctl重新添加一次。
我们目前未使用控制器,暂时采用方法2.
方法如下,
系统:Centos7
Step1: 创建ovsconfig.service
文件目录:/lib/systemd/system
Step2: 创建ovs-config
文件目录:/usr/bin/
文件权限:可执行(chmod +x /usr/bin/ovs-config)
Step3: 设置使用服务
systemctl enable ovsconfig.service
此时查看状态
systemctl status ovsconfig.service
状态应该为正常启动
此时重启系统,系统应该正常下发流表。
附件:
1 ovsconfig.service内容
这是systemd配置服务内容,内容如下,
[Unit]
Description=Openvswitch Openflow Saver
After=openvswitch.service
Requires=openvswitch.service
[Service]
ExecStart=/usr/bin/ovs-config
ExecReload=ovs-config
Type=oneshot
KillMode=none
[Install]
WantedBy=multi-user.target
2 ovs-config内容
这是ovs配置流表内容,内容如下,
#!/bin/sh
ovs-ofctl add-flow br-in "in_port=101,actions=bundle(eth_src,0,hrw,ofport,slaves:102,103)"