openstack運維實戰系列(十一)之neutron替換instance的IP

1. 背景說明linux

  生產環境下openstack使用了vlan的的網絡模式,針對業務需求不一樣,設置不一樣的網段,分別放置在不通的vlan中,經過vlan的方式,實現網絡的隔離,網絡相關的策略,能夠經過現有的交換機,防火牆來設置。有時候,業務申請的虛擬機使用一段時間以後,須要將網絡A切換至另一個網絡B,而且須要保留原有的虛擬機和數據,對於這種場景,就能夠經過neutron端口替換的方式實現。
網絡

  neutron在openstack中負責虛擬機網絡相關的服務,做爲一種插件式的服務,neutron可以支持各類插件,包括OpenVswitch,Cisco插件,Boacade等網絡廠商的插件,同時爲了網絡的可擴展性和tenant之間的流量隔離,neutron可以支持多種網絡隔離技術,常見的隔離技術包括:vlan,gre,vxlan,gre,linux bridge等。根據使用場景的不一樣,能夠選擇不一樣的網絡模式,我所在的工做環境中,使用的網絡模式爲vlan。關於網絡的說明,請繼續關注個人博客,此處再也不贅述。app

2. 實現過程ide

  1. 查看須要替換地址的instance插件

[root@controller ~]# nova list |grep 192.168.100.200
| 3f694eaf-aa87-456a-99ce-90dd9f4e45ee | happyblog_blog_51cto_com | ACTIVE | -          | Running     | vmTest=192.168.100.200   | ChuangYiYuan_10_16_2_11 |

#須要將192.168.100.200這臺機器的ip,替換成10.16.4.x網段的ip地址

2. 將instance的port卸載3d

#將port從instance中detach 
[root@controller ~]# nova interface-detach 3f694eaf-aa87-456a-99ce-90dd9f4e45ee  4c158efa-6cba-4d62-99d7-590877586c09    

[root@controller ~]# nova list |grep 3f694eaf-aa87-456a-99ce-90dd9f4e45ee
| 3f694eaf-aa87-456a-99ce-90dd9f4e45ee | happyblog_blog_51cto_com | ACTIVE | -          | Running     |                         | ChuangYiYuan_10_16_2_11|

#發現instance 3f694eaf-aa87-456a-99ce-90dd9f4e45ee此時沒有IP地址了!!

3. 基於指定的sunbet建立一個端口orm

[root@controller ~]# neutron subnet-list
+--------------------------------------+----------------+------------------+------------------------------------------------------+
| id                                   | name           | cidr             | allocation_pools                                     |
+--------------------------------------+----------------+------------------+------------------------------------------------------+
| 79cb82a1-eac1-4311-8e6d-badcabd22e44 | ForTest        | 192.168.100.0/24 | {"start": "192.168.100.2", "end": "192.168.100.254"} |
| 9654a807-d4fa-49f1-abb6-2e45d776c69f | Subnet_INSIDE  | 10.16.4.0/23     | {"start": "10.16.4.10", "end": "10.16.5.254"}        |#基於該subnet建立port

查看network狀況
[root@controller ~]# neutron net-list
+--------------------------------------+---------------+-------------------------------------------------------+
| id                                   | name          | subnets                                               |
+--------------------------------------+---------------+-------------------------------------------------------+
| 43b5c341-c22d-445a-94d1-e2c84722ad4e | vmProdution   | 9654a807-d4fa-49f1-abb6-2e45d776c69f 10.16.4.0/23     |   #網絡ID好,後續使用
| 99c68a93-336a-4605-aa78-343d41ca1206 | vmTest        | 79cb82a1-eac1-4311-8e6d-badcabd22e44 192.168.100.0/24 |
+--------------------------------------+---------------+-------------------------------------------------------+

#基於指定的subnet,建立一個端口port
[root@controller ~]# neutron port-create --name port-1  --fixed-ip subnet_id=9654a807-d4fa-49f1-abb6-2e45d776c69f,ip_address=10.16.4.58  \
--security-group 663468d9-73b1-4b04-8d4c-dac1bf21a94d  43b5c341-c22d-445a-94d1-e2c84722ad4e        
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                                                                            |
| device_id             |                                                                                   |
| device_owner          |                                                                                   |
| fixed_ips             | {"subnet_id": "9654a807-d4fa-49f1-abb6-2e45d776c69f", "ip_address": "10.16.4.58"} |   #指定的ip地址了
| id                    | ae64c08e-ac2e-4a28-ae89-0d4d2fb67981                                              |   #ID號碼,記住
| mac_address           | fa:16:3e:1d:c0:9a                                                                 |
| name                  | port-1                                                                            |
| network_id            | 43b5c341-c22d-445a-94d1-e2c84722ad4e                                              |
| security_groups       | 663468d9-73b1-4b04-8d4c-dac1bf21a94d                                              |
| status                | DOWN                                                                              |
| tenant_id             | 842ab3268a2c47e6a4b0d8774de805ae                                                  |
+-----------------------+-----------------------------------------------------------------------------------+

#查看端口的信息
[root@controller ~]# neutron port-list |grep  ae64c08e-ac2e-4a28-ae89-0d4d2fb67981 
| ae64c08e-ac2e-4a28-ae89-0d4d2fb67981 | port-1 | fa:16:3e:1d:c0:9a | {"subnet_id": "9654a807-d4fa-49f1-abb6-2e45d776c69f", "ip_address": "10.16.4.58"}  |
[root@controller ~]# 
[root@controller ~]# neutron port-show  ae64c08e-ac2e-4a28-ae89-0d4d2fb67981 
+-----------------------+-----------------------------------------------------------------------------------+
| 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                                                                            |
| device_id             |                                                                                   |
| device_owner          |                                                                                   |
| extra_dhcp_opts       |                                                                                   |
| fixed_ips             | {"subnet_id": "9654a807-d4fa-49f1-abb6-2e45d776c69f", "ip_address": "10.16.4.58"} |
| id                    | ae64c08e-ac2e-4a28-ae89-0d4d2fb67981                                              |
| mac_address           | fa:16:3e:1d:c0:9a                                                                 |
| name                  | port-1                                                                            |
| network_id            | 43b5c341-c22d-445a-94d1-e2c84722ad4e                                              |
| security_groups       | 663468d9-73b1-4b04-8d4c-dac1bf21a94d                                              |
| status                | DOWN                                                                              |
| tenant_id             | 842ab3268a2c47e6a4b0d8774de805ae                                                  |
+-----------------------+-----------------------------------------------------------------------------------+

4. 將所建立的port和instance關聯blog

[root@controller ~]# nova list |grep happy
| 3f694eaf-aa87-456a-99ce-90dd9f4e45ee | happyblog_blog_51cto_com | ACTIVE | -          | Running     |                         | ChuangYiYuan_10_16_2_11 |
#執行關聯操做,用法參考nova help interface-attach
[root@controller ~]# nova interface-attach --port-id ae64c08e-ac2e-4a28-ae89-0d4d2fb67981 3f694eaf-aa87-456a-99ce-90dd9f4e45ee
[root@controller ~]# nova list |grep 3f694eaf-aa87-456a-99ce-90dd9f4e45ee
| 3f694eaf-aa87-456a-99ce-90dd9f4e45ee | happyblog_blog_51cto_com | ACTIVE | -          | Running     | vmProdution=10.16.4.58   | ChuangYiYuan_10_16_2_11 |
#關聯完畢!!!


3. 小結ip

   關於端口的替換,能夠參考上面的例子,neutron做爲可插拔式的服務,其port能夠隨便切換,這也是neutron的強大之處。ci

相關文章
相關標籤/搜索