OpenStack之Neutron分配VIP提供给两台虚拟机做高可用

一. 简单介绍

在openstack私有云平台的应用场景中,涉及多台虚拟机实例进行高可用的绑定,这里我们需要在云平台中提供一个IP给高可用场景切换,这里介绍keepalived + allow_address_pairs实现虚拟机的高可用

二.创建port和指定vip

[root@openstack01 ~]# neutron net-list
+--------------------------------------+-------------+----------------------------------+------------------------------------------------------+
| id                                   | name        | tenant_id                        | subnets                                              |
+--------------------------------------+-------------+----------------------------------+------------------------------------------------------+
| 0fbab9a2-9838-43f9-b1a3-0302ee53eb70 | virtual-net | c1f5a356a4f549bb90234c05d60e0a35 | d09ba832-6734-42e7-b127-00114bbbbe83 10.0.0.0/24     |
| f2cbbf07-bb60-4ef8-acdd-bee4a793b51b | public1     | c1f5a356a4f549bb90234c05d60e0a35 | b5614524-96c2-4f5f-9507-a95a1627ac4d 192.168.30.0/24 |
+--------------------------------------+-------------+----------------------------------+------------------------------------------------------+

这里找出virtual-net对应的id号( 0fbab9a2-9838-43f9-b1a3-0302ee53eb70)
创建port和绑定内部IP:

[root@openstack01 ~]# neutron port-create --fixed-ip ip_address=10.0.0.150 0fbab9a2-9838-43f9-b1a3-0302ee53eb70
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
Created a new port:
+-----------------------+-----------------------------------------------------------------------------------+
| Field                 | Value                                                                             |
+-----------------------+-----------------------------------------------------------------------------------+
| admin_state_up        | True                                                                              |
| allowed_address_pairs |                                                                                   |
| binding:host_id       |                                                                                   |
| binding:profile       | {}                                                                                |
| binding:vif_details   | {}                                                                                |
| binding:vif_type      | unbound                                                                           |
| binding:vnic_type     | normal                                                                            |
| created_at            | 2018-09-28T01:15:18Z                                                              |
| description           |                                                                                   |
| device_id             |                                                                                   |
| device_owner          |                                                                                   |
| extra_dhcp_opts       |                                                                                   |
| fixed_ips             | {"subnet_id": "d09ba832-6734-42e7-b127-00114bbbbe83", "ip_address": "10.0.0.150"} |
| id                    | 715d39e9-8341-4124-a8e4-3a4e2700ee36                                              |
| mac_address           | fa:16:3e:f0:2b:85                                                                 |
| name                  |                                                                                   |
| network_id            | 0fbab9a2-9838-43f9-b1a3-0302ee53eb70                                              |
| port_security_enabled | True                                                                              |
| project_id            | c1f5a356a4f549bb90234c05d60e0a35                                                  |
| revision_number       | 6                                                                                 |
| security_groups       | 8da47344-9c63-4229-b89a-b653afad65b6                                              |
| status                | DOWN                                                                              |
| tags                  |                                                                                   |
| tenant_id             | c1f5a356a4f549bb90234c05d60e0a35                                                  |
| updated_at            | 2018-09-28T01:15:19Z                                                              |
+-----------------------+-----------------------------------------------------------------------------------+

注意:ip_address是keepalived的vip,后面的字符串是virtual-net对应的id
创建完毕后,我们可以看到端口的信息显示unbound未绑定的。下面我们将这个端口信息更新到对应的虚拟机中。

三. 更新端口信息到对应的实例


如上图所示,有两台虚拟机,对应的IP地址分别为10.0.0.13和10.0.0.6,这里我们将上面创建的端口信息更新到这两台实例中去:
查看对应IP端口port的ID信息:

[root@openstack01 ~]# neutron port-list
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
+--------------------------------------+--------+----------------------------------+-------------------+--------------------------------------------------------------------------------------+
| id                                   | name   | tenant_id                        | mac_address       | fixed_ips                                                                            |
+--------------------------------------+--------+----------------------------------+-------------------+--------------------------------------------------------------------------------------+
| 35d83ee9-e574-45a3-9193-bdd746102807 |        | c1f5a356a4f549bb90234c05d60e0a35 | fa:16:3e:e2:42:ad | {"subnet_id": "d09ba832-6734-42e7-b127-00114bbbbe83", "ip_address": "10.0.0.2"}      |
| 468bf092-324e-4c0d-a7f7-603f19b388fc |        |                                  | fa:16:3e:b3:19:92 | {"subnet_id": "b5614524-96c2-4f5f-9507-a95a1627ac4d", "ip_address": "192.168.30.57"} |
| 52da60be-e2d1-47b6-8d84-8634bd3a18f8 |        | c1f5a356a4f549bb90234c05d60e0a35 | fa:16:3e:0c:50:55 | {"subnet_id": "d09ba832-6734-42e7-b127-00114bbbbe83", "ip_address": "10.0.0.6"}      |
| 715d39e9-8341-4124-a8e4-3a4e2700ee36 |        | c1f5a356a4f549bb90234c05d60e0a35 | fa:16:3e:f0:2b:85 | {"subnet_id": "d09ba832-6734-42e7-b127-00114bbbbe83", "ip_address": "10.0.0.150"}    |
| a6632ddd-588c-46f2-ad98-edb4a3b5dda3 |        | c1f5a356a4f549bb90234c05d60e0a35 | fa:16:3e:fe:e2:67 | {"subnet_id": "d09ba832-6734-42e7-b127-00114bbbbe83", "ip_address": "10.0.0.1"}      |
| a9629c47-cf80-40d3-864f-f3ce9c7fe7ca |        | c1f5a356a4f549bb90234c05d60e0a35 | fa:16:3e:ff:90:81 | {"subnet_id": "d09ba832-6734-42e7-b127-00114bbbbe83", "ip_address": "10.0.0.13"}     |
| da2afbf5-33c4-48ca-8ab3-136d48628631 |        |                                  | fa:16:3e:08:af:07 | {"subnet_id": "b5614524-96c2-4f5f-9507-a95a1627ac4d", "ip_address": "192.168.30.53"} |
| dc993931-499b-440e-9980-4f8e7ceb6cb4 |        |                                  | fa:16:3e:87:32:bf | {"subnet_id": "d09ba832-6734-42e7-b127-00114bbbbe83", "ip_address": "10.0.0.5"}      |
| e97c25fe-f08b-4230-9ccf-e34f0a2e5d4b |        |                                  | fa:16:3e:d0:d5:85 | {"subnet_id": "b5614524-96c2-4f5f-9507-a95a1627ac4d", "ip_address": "192.168.30.52"} |
| e9841b66-17d4-4a7d-8f74-e27b33d24d6d |        |                                  | fa:16:3e:da:c0:96 | {"subnet_id": "b5614524-96c2-4f5f-9507-a95a1627ac4d", "ip_address": "192.168.30.51"} |
| f33564a2-37b2-4df8-a14f-ce2c31402f25 | port-1 | c1f5a356a4f549bb90234c05d60e0a35 | fa:16:3e:dc:1c:d3 | {"subnet_id": "d09ba832-6734-42e7-b127-00114bbbbe83", "ip_address": "10.0.0.50"}     |
+--------------------------------------+--------+----------------------------------+-------------------+--------------------------------------------------------------------------------------+

更新虚拟机10.0.0.13端口信息:

[root@openstack01 ~]# neutron port-update a9629c47-cf80-40d3-864f-f3ce9c7fe7ca --allowed_address_pairs list=true type=dict ip_address=10.0.0.150 
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
Updated port: a9629c47-cf80-40d3-864f-f3ce9c7fe7ca

更新虚拟机10.0.0.6的端口信息:

[root@openstack01 ~]# neutron port-update 52da60be-e2d1-47b6-8d84-8634bd3a18f8 --allowed_address_pairs list=true type=dict ip_address=10.0.0.150 
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
Updated port: 52da60be-e2d1-47b6-8d84-8634bd3a18f8

上面的操作完成后,我们可以通过下面的命令查看更新的端口信息:

[root@openstack01 ~]# neutron port-show a9629c47-cf80-40d3-864f-f3ce9c7fe7ca
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
+-----------------------+----------------------------------------------------------------------------------+
| Field                 | Value                                                                            |
+-----------------------+----------------------------------------------------------------------------------+
| admin_state_up        | True                                                                             |
| allowed_address_pairs | {"ip_address": "10.0.0.150", "mac_address": "fa:16:3e:ff:90:81"}                 |
| binding:host_id       | openstack01                                                                      |
| binding:profile       | {}                                                                               |
| binding:vif_details   | {"port_filter": true, "datapath_type": "system", "ovs_hybrid_plug": true}        |
| binding:vif_type      | ovs                                                                              |
| binding:vnic_type     | normal                                                                           |
| created_at            | 2018-09-28T01:18:09Z                                                             |
| description           |                                                                                  |
| device_id             | 59cdecdd-2e42-48cc-b76f-29d8fee78183                                             |
| device_owner          | compute:nova                                                                     |
| extra_dhcp_opts       |                                                                                  |
| fixed_ips             | {"subnet_id": "d09ba832-6734-42e7-b127-00114bbbbe83", "ip_address": "10.0.0.13"} |
| id                    | a9629c47-cf80-40d3-864f-f3ce9c7fe7ca                                             |
| mac_address           | fa:16:3e:ff:90:81                                                                |
| name                  |                                                                                  |
| network_id            | 0fbab9a2-9838-43f9-b1a3-0302ee53eb70                                             |
| port_security_enabled | True                                                                             |
| project_id            | c1f5a356a4f549bb90234c05d60e0a35                                                 |
| revision_number       | 12                                                                               |
| security_groups       | 8da47344-9c63-4229-b89a-b653afad65b6                                             |
| status                | ACTIVE                                                                           |
| tags                  |                                                                                  |
| tenant_id             | c1f5a356a4f549bb90234c05d60e0a35                                                 |
| updated_at            | 2018-09-28T01:27:54Z                                                             |
+-----------------------+----------------------------------------------------------------------------------+

我们可以看到虚拟机端口信息已经更新了10.0.0.150的IP信息和MAC地址。

四. 绑定浮动IP

  • 在实际的应用场景中,我们需要将虚拟机绑定一个浮动IP来提供给外部的业务访问,这里需要将浮动IP绑定到keepalived 的VIP对应的端口上

  • 将分配的浮动IP绑定到keepalived的vip端口上:

posted @ 2018-09-28 09:40  yuhaohao  阅读(535)  评论(0编辑  收藏  举报