ovs操作指令

开启ovs数据库

1
2
3
4
5
6
7
8
sudo 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

利用网络明明空间实现内部通信

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#创建ovs (相当于搬来一台openflow交换机)
ovs-vsctl add-br br-int
#创建端口
ovs-vsctl add-port br-int vnet1 -- set Interface vnet1 type=internal
ovs-vsctl add-port br-int vnet2 -- set Interface vnet2 type=internal
ovs-vsctl add-port br-int vnet3 -- set Interface vnet3 type=internal
#1.创建网络命名空间(相当于搬来四台主机)
ip netns add ns1
ip netns add ns2
ip netns add ns3

ip link set vnet1 netns ns1
ip link set vnet2 netns ns2
ip link set vnet3 netns ns3

ip netns exec ns1 ip link set lo up
ip netns exec ns1 ip link set vnet1 up
ip netns exec ns1 ip addr add 10.23.4.4/24 dev vnet1
ip netns exec ns2 ip link set lo up
ip netns exec ns2 ip link set vnet2 up
ip netns exec ns2 ip addr add 10.23.4.5/24 dev vnet2
ip netns exec ns3 ip link set lo up
ip netns exec ns3 ip link set vnet3 up
ip netns exec ns3 ip addr add 10.23.4.6/24 dev vnet3

ovs-vsctl add-port br-int vnet0 -- set Interface vnet0 type=internal
ip netns add ns0
ip link set vnet0 netns ns0
ip netns exec ns0 ip link set lo up
ip netns exec ns0 ip link set vnet0 up
ip netns exec ns0 ip addr add 10.23.4.7/24 dev vnet0

ovs-vsctl set Port vnet0 tag=100
ovs-vsctl set Port vnet1 tag=200
ovs-vsctl set Port vnet2 tag=200
ip netns exec ns1 ping 10.23.4.4

物理网卡绑定

1
2
3
ovs-vsctl add-port br-int ens33
ifconfig ens33 0 up && ifconfig br-int 192.168.159.128/24 up
route add default gw 192.168.159.2 br-int

设置vxlan

1
ovs-vsctl add-port br-int vx1 -- set interface vx1 type=vxlan option:local_ip=172.16.25.129

查看端口

1
ovs-ofctl show br-int -O OpenFlow13

查看流表

1
ovs-ofctl -O OpenFlow13 dump-flows br-int

查看组

1
ovs-ofctl dump-groups br-int -O openflow13

查看交换机

1
ovs-vsctl show

删除交换机

1
ovs-vsctl  del-br br-int

删除端口

1
ovs-vsctl del-port br-int vnet0

设置vxlan端口

1
ovs-vsctl add-port br-int vxlan1 -- set interface vxlan1 type=vxlan  options:remote_ip=192.168.169.169 option:local_ip=192.168.159.128 options:key=100ovs-vsctl add-port br-local vxlan1 -- set interface vxlan1 type=vxlan  options:remote_ip=192.168.159.128  options:key=100

创建group

1
#创建group,并把vxlan1加入group中,vxlan1的端口是6ovs-ofctl -O OpenFlow13 add-group br-int  group_id=5566,type=select,bucket=output:6#创建入口为vnet0转发到group的流表,vnet0的端口号是1ovs-ofctl -O OpenFlow13 add-flow br-int in_port=1,actions=group:5566

开启upcall负载均衡

1
ovs-vsctl set open_vswitch . other_config:pmd-auto-lb="true"

添加控制器

1
ovs-vsctl set-controller s1 tcp:<controller IP>:<port>

删除控制器

1
ovs-vsctl del-controllers