qhdx07
作者qhdx072022-05-16 10:48
系统架构师, as

neutron替换instance的IP

字数 4260阅读 587评论 0赞 0

1. 背景说明

生产环境下openstack使用了vlan的的网络模式,针对业务需求不同,设置不同的网段,分别放置在不通的vlan中,通过vlan的方式,实现网络的隔离,网络相关的策略,可以通过现有的交换机,防火墙来设置。有时候,业务申请的虚拟机使用一段时间之后,需要将网络A切换至另外一个网络B,并且需要保留原有的虚拟机和数据,对于这种场景,就可以通过neutron端口替换的方式实现。

neutron在openstack中负责虚拟机网络相关的服务,作为一种插件式的服务,neutron能够支持各种插件,包括OpenVswitch,Cisco插件,Boacade等网络厂商的插件,同时为了网络的可扩展性和tenant之间的流量隔离,neutron能够支持多种网络隔离技术,常见的隔离技术包括:vlan,gre,vxlan,gre,linux bridge等。根据使用场景的不同,可以选择不同的网络模式,我所在的工作环境中,使用的网络模式为vlan。关于网络的说明,请继续关注我的博客,此处不再赘述。

2. 实现过程

2.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.2 将instance的port卸载

将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创建一个端口

[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 |


  1. 将所创建的port和instance关联

[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. 小结

关于端口的替换,可以参考上面的例子,neutron作为可插拔式的服务,其port可以随便切换,这也是neutron的强大之处。

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

0

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广