Openstack Neutron网络实验-05

0 阅读

本文继续介绍在Openstack实现网络的高可用性。

上一篇文章中创建了两个路由器,router01和router02,虽然为这两个路由器分别关联了两个外部物理网络extnet和extnet2,但实际上这两个网络是同一个网络在完全隔离的两个环境中的表现。既然router01和router02两个路由器可以分布在不同的网络节点上,又可以同时连接到相同的网络,那很自然应该可以利用两个路由器来实现网络的高可用性,即VRRP虚拟路由器。

事实上,我们可以通过手动创建路由器间通信的网络来实现VRRP,但是过程比较复杂。Openstack从M版本之后为Router增加了HA属性,当这个属性打开时,路由器会自动创建所需网络,实现HA功能。

0. 准备环境

为了更加清晰的看到HA Router的网络拓扑,将之前创建的一些额外网络和Router删掉,包括:router02,test-net2,external-net2。

还需要将os-net1上的neutron配置文件中的物理网络标识extnet2改回和os-ctl1一致的extnet,因为对于VRRP的两个路由器而言,实际的外部网络只有一个。

[root@os-net1 ~]# vi /etc/neutron/plugins/ml2/openvswitch_agent.ini 

bridge_mappings=extnet2:br-ex

改为:

bridge_mappings=extnet:br-ex

重启os-net1使配置生效。

1. 创建HA Router

清理完毕后,系统中只有一个路由器router01,该路由器运行在os-ctl1上,可以通过ip netns指令看到他所在的命名空间qrouter-7d360e8e-e392-4def-816b-f92f7e5f9bc5。而os-net1没有路由器命名空间。

[root@os-ctl1 ~]# ip netns
qrouter-7d360e8e-e392-4def-816b-f92f7e5f9bc5
qdhcp-d18f42ff-a688-4c57-acde-6299326022dc
[root@os-net1 ~]# ip netns 
[root@os-net1 ~]#

通过指令为router01打开ha属性:

[root@os-ctl1 ~(keystone_admin)]# openstack router show router01
[root@os-ctl1 ~(keystone_admin)]# openstack router set router01 --disable
[root@os-ctl1 ~(keystone_admin)]# openstack router set router01 --ha
[root@os-ctl1 ~(keystone_admin)]# openstack router set router01 --enable
[root@os-ctl1 ~(keystone_admin)]# openstack router show router01

查看命名空间的变化:

[root@os-ctl1 ~]# ip netns exec qrouter-7d360e8e-e392-4def-816b-f92f7e5f9bc5 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
16: ha-725365ed-9d: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN qlen 1000
    link/ether fa:16:3e:5a:81:55 brd ff:ff:ff:ff:ff:ff
    inet 169.254.192.1/18 brd 169.254.255.255 scope global ha-725365ed-9d
       valid_lft forever preferred_lft forever
    inet 169.254.0.1/24 scope global ha-725365ed-9d
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fe5a:8155/64 scope link 
       valid_lft forever preferred_lft forever
17: qr-9516320e-52: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN qlen 1000
    link/ether fa:16:3e:f6:ec:e8 brd ff:ff:ff:ff:ff:ff
    inet 172.16.2.1/24 scope global qr-9516320e-52
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fef6:ece8/64 scope link nodad 
       valid_lft forever preferred_lft forever
18: qg-fb855659-95: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN qlen 1000
    link/ether fa:16:3e:ab:05:69 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.6/24 scope global qg-fb855659-95
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:feab:569/64 scope link nodad 
       valid_lft forever preferred_lft forever
[root@os-net1 ~]# ip netns
qrouter-7d360e8e-e392-4def-816b-f92f7e5f9bc5
[root@os-net1 ~]# ip netns exec qrouter-7d360e8e-e392-4def-816b-f92f7e5f9bc5 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
13: ha-6218ff4d-1b: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN qlen 1000
    link/ether fa:16:3e:26:45:c2 brd ff:ff:ff:ff:ff:ff
    inet 169.254.192.4/18 brd 169.254.255.255 scope global ha-6218ff4d-1b
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fe26:45c2/64 scope link 
       valid_lft forever preferred_lft forever
14: qr-9516320e-52: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN qlen 1000
    link/ether fa:16:3e:f6:ec:e8 brd ff:ff:ff:ff:ff:ff
15: qg-fb855659-95: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN qlen 1000
    link/ether fa:16:3e:ab:05:69 brd ff:ff:ff:ff:ff:ff

上面的结果显示,打开router01的ha属性后:

  • 在os-net1上创建了一个新的router命名空间,表示此时集群中已经有两个路由器。
  • 在os-net1的新路由器命名空间中,创建了两个和os-ctl1一样的设备qr-9516320e-52和qg-fb855659-95,用于连接内外两个网络test-net和external-net。
  • 两个路由器上均多了一个HA网络的接口设备:os-ctl1上的ha-725365ed-9d和os-net1上的ha-6218ff4d-1b,这两个设备分配了169.254.194.4/18网段的地址。
  • 169.254.0.1/24这个浮动地址也分配在os-ctl1上,表示目前os-ctl1上的路由器是Active路由器,os-net1上是Standby。
  • 内外网的接口IP地址172.16.2.1和10.0.2.6也分配在os-ctl1上。

测试实例中的网络通信正常,可以正常访问外网。

[root@os-ctl1 ~]# virsh console 1
Connected to domain instance-00000004
Escape character is ^]

login as 'cirros' user. default password: 'cubswin:)'. use 'sudo' for root.
test-vm1 login: cirros
Password: 
$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=56 time=18.591 ms
64 bytes from 8.8.8.8: seq=1 ttl=56 time=18.098 ms

--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 18.098/18.344/18.591 ms

此时虚拟网络拓扑图如下:

neutron-10.jpg

2. 触发网络切换

在os-ctl1将VXLAN Overlay的虚拟端口停掉,即os-ctl1上的172.16.2.0/24网段无法访问,将触发路由器发生切换。

[root@os-ctl1 ~]# ifconfig vxlan_sys_4789 down   

切换后,再查看两个路由器命名空间中的网络设备:

[root@os-net1 ~]# ip netns exec qrouter-7d360e8e-e392-4def-816b-f92f7e5f9bc5 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
13: ha-6218ff4d-1b: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN qlen 1000
    link/ether fa:16:3e:26:45:c2 brd ff:ff:ff:ff:ff:ff
    inet 169.254.192.4/18 brd 169.254.255.255 scope global ha-6218ff4d-1b
       valid_lft forever preferred_lft forever
    inet 169.254.0.1/24 scope global ha-6218ff4d-1b
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fe26:45c2/64 scope link 
       valid_lft forever preferred_lft forever
14: qr-9516320e-52: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN qlen 1000
    link/ether fa:16:3e:f6:ec:e8 brd ff:ff:ff:ff:ff:ff
    inet 172.16.2.1/24 scope global qr-9516320e-52
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fef6:ece8/64 scope link nodad 
       valid_lft forever preferred_lft forever
15: qg-fb855659-95: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN qlen 1000
    link/ether fa:16:3e:ab:05:69 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.6/24 scope global qg-fb855659-95
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:feab:569/64 scope link nodad 
       valid_lft forever preferred_lft forever

[root@os-net1 ~]# ip netns exec qrouter-7d360e8e-e392-4def-816b-f92f7e5f9bc5 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
9: ha-6218ff4d-1b: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN qlen 1000
    link/ether fa:16:3e:26:45:c2 brd ff:ff:ff:ff:ff:ff
    inet 169.254.192.4/18 brd 169.254.255.255 scope global ha-6218ff4d-1b
       valid_lft forever preferred_lft forever
    inet 169.254.0.1/24 scope global ha-6218ff4d-1b
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fe26:45c2/64 scope link 
       valid_lft forever preferred_lft forever
10: qr-9516320e-52: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN qlen 1000
    link/ether fa:16:3e:f6:ec:e8 brd ff:ff:ff:ff:ff:ff
    inet 172.16.2.1/24 scope global qr-9516320e-52
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fef6:ece8/64 scope link nodad 
       valid_lft forever preferred_lft forever
11: qg-fb855659-95: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN qlen 1000
    link/ether fa:16:3e:ab:05:69 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.6/24 scope global qg-fb855659-95
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:feab:569/64 scope link nodad 
       valid_lft forever preferred_lft forever

可以见到os-ctl1上的路由器没有发生任何变化,但是os-net1上则分配了HA网络的浮动IP 169.254.0.1/24,也分配了内外网的接口IP 172.16.2.1和10.0.2.6。这是因为两个路由器间的网络断开后,互相检测不到对方,因此都尝试接管业务,但实际上,由于os-ctl1是被实际关闭端口的路由器,所以真正接管了业务的是os-net1。

3. HA Router的属性和网络

查看router01的属性和虚拟网络信息如下图:

ha-router.jpg ha-networks.jpg

可以看到,router01实际上对应了两个L3 Agent,即路由器,分别运行在os-ctl1和os-net1上,而系统自动创建了一个HA Network用于两个L3 Agent之间的通信。

更新于

本文遵守 CC-BY-NC-4.0 许可协议。

Creative Commons License

欢迎转载,转载需注明出处,且禁止用于商业目的。

上篇在CentOS7上配置iSCSI
下篇Openstack Neutron网络实验-04