ovs缺陷
1. ovs只能做二层转发,没有三层能力
2. ovs没有高可用配置
3. ovs配置无法随着虚机迁移和容器迁移而自动迁移
安装ovs和ovn
ovn-northd通过unix socket连上北向数据库和南向数据库,3者在同一台机器上。
ovn-controler启动后自动创建br-int网桥。
# 通过yum安装ovs和ovn(省略)
# 南向数据库开启6442端口,该端口给ovn controller连接
ovn-sbctl set-connection ptcp:6642:192.168.0.192
# ovn-controller连接南向数据库的6442端口
ovs-vsctl set Open_vSwitch . external-ids:ovn-remote="tcp:192.168.0.192:6642" external-ids:ovn-encap-ip="192.168.0.192" external-ids:ovn-encap-type=geneve external-ids:system-id=node2
ovs-vsctl set Open_vSwitch . external-ids:ovn-remote="tcp:192.168.0.192:6642" external-ids:ovn-encap-ip="192.168.0.115" external-ids:ovn-encap-type=geneve external-ids:system-id=node1
同网段跨节点通信
# node1创建ns1并分配IP
ip netns add ns1
ip link add veth1 type veth peer name veth2
ip link set veth2 netns ns1
ip link set veth1 up
ip netns exec ns1 ip link set lo up
ip netns exec ns1 ip link set veth2 address 00:00:00:00:00:01
ip netns exec ns1 ip link set veth2 up
ovs-vsctl add-port br-int veth1
ip netns exec ns1 ip addr add 192.168.1.10/24 dev veth2
# node2创建ns1并分配IP(不同的mac和ip)
ip netns add ns1
ip link add veth1 type veth peer name veth2
ip link set veth2 netns ns1
ip link set veth1 up
ip netns exec ns1 ip link set lo up
ip netns exec ns1 ip link set veth2 address 00:00:00:00:00:02
ip netns exec ns1 ip link set veth2 up
ovs-vsctl add-port br-int veth1
ip netns exec ns1 ip addr add 192.168.1.11/24 dev veth2
node1上192.168.1.10无法ping通node2上192.168.1.11
# 添加逻辑交换机
ovn-nbctl ls-add ls1
# node1绑定交换机端口
ovn-nbctl lsp-add ls1 ls1-node1-ns1
ovn-nbctl lsp-set-addresses ls1-node1-ns1 00:00:00:00:00:01
ovn-nbctl lsp-set-port-security ls1-node1-ns1 00:00:00:00:00:01
# node2绑定交换机端口
ovn-nbctl lsp-add ls1 ls1-node2-ns1
ovn-nbctl lsp-set-addresses ls1-node2-ns1 00:00:00:00:00:02
ovn-nbctl lsp-set-port-security ls1-node2-ns1 00:00:00:00:00:02
# node1上veth1端口绑定交换机端口
ovs-vsctl set interface veth1 external-ids:iface-id=ls1-node1-ns1
# node2上veth1端口绑定交换机端口
ovs-vsctl set interface veth1 external-ids:iface-id=ls1-node2-ns1
验证同网段跨节点连通性
跨网段跨节点通信
# 新增逻辑交换机
ovn-nbctl ls-add ls2
ovn-nbctl lsp-add ls2 ls2-node2-ns2
ovn-nbctl lsp-set-addresses ls2-node2-ns2 00:00:00:00:00:03
ovn-nbctl lsp-set-port-security ls2-node2-ns2 00:00:00:00:00:03
# node2上创建ns2并分配IP
ip netns add ns2
ip link add veth3 type veth peer name veth4
ip link set veth4 netns ns2
ip link set veth3 up
ip netns exec ns2 ip link set veth4 address 00:00:00:00:00:03
ip netns exec ns2 ip link set veth4 up
ovs-vsctl add-port br-int veth3
ip netns exec ns2 ip addr add 192.168.2.10/24 dev veth4
# node2上绑定交换机端口
ovs-vsctl set interface veth3 external-ids:iface-id=ls2-node2-ns2
# 创建逻辑路由器连接2个逻辑交换机
ovn-nbctl lr-add lr1
ovn-nbctl lrp-add lr1 lr1-ls1 00:00:00:00:11:00 192.168.1.1/24
ovn-nbctl lrp-add lr1 lr1-ls2 00:00:00:00:21:00 192.168.2.1/24
ovn-nbctl lsp-add ls1 ls1-lr1
ovn-nbctl lsp-set-type ls1-lr1 router
ovn-nbctl lsp-set-addresses ls1-lr1 00:00:00:00:11:00
ovn-nbctl lsp-set-options ls1-lr1 router-port=lr1-ls1
ovn-nbctl lsp-add ls2 ls2-lr1
ovn-nbctl lsp-set-type ls2-lr1 router
ovn-nbctl lsp-set-addresses ls2-lr1 00:00:00:00:21:00
ovn-nbctl lsp-set-options ls2-lr1 router-port=lr1-ls2
# 添加默认路由
# node1和node2
ip netns exec ns1 ip route add default via 192.168.1.1 dev veth2
# node2
ip netns exec ns2 ip route add default via 192.168.2.1 dev veth4
验证跨网段跨节点连通性
参考资料
https://blog.csdn.net/NUCEMLS/article/details/126149936
标签:打通,00,set,网段,ip,add,ns1,ovn From: https://www.cnblogs.com/WJQ2017/p/17626675.html