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端口上:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM