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

相关文章
相关标签/搜索