1. 程式人生 > >OpenStack之Neutron分配VIP提供給兩臺虛擬機器做高可用

OpenStack之Neutron分配VIP提供給兩臺虛擬機器做高可用

一. 簡單介紹

在openstack私有云平臺的應用場景中,涉及多臺虛擬機器例項進行高可用的繫結,這裡我們需要在雲平臺中提供一個IP給高可用場景切換,這裡介紹keepalived + allow_address_pairs實現虛擬機器的高可用 二.建立port和指定vip

[[email protected] ~]# 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:

[[email protected] ~]# 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資訊:

[[email protected] ~]# 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埠資訊:

[[email protected] ~]# 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的埠資訊:

[[email protected] ~]# 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

上面的操作完成後,我們可以通過下面的命令檢視更新的埠資訊:

[[email protected] ~]# 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埠上: