openstack虚拟机配置vip

openstack配置vip
1.导入环境变量
source admin-openrc.sh

2.执行命令neutron net-list查看网络,找到自己需要设置的网络,获取subnet_id和network_id

3.创建port来占用ip,保证neutron不会将此IP在分配出去,导致IP冲突问题。

neutron port-create --fixed-ip subnet_id=<subnet_id>,ip_address= <network_id>
注:
替换subnet_id为neutron net-list中查看到的subnet_id
替换vip为需要配置的vip地址
替换network_ID为neutron net-list中查看到的network_id

neutron port-create --fixed-ip subnet_id=46c12a96-d1b6-4951-b57c-8884457f3e86,ip_address=10.10.4.131 b7fff54f-ae3a-45ae-8d84-228b7bc41059

4、执行命令neutron port-list查看端口,找到VIP的Port ID以及需要使用VIP的虚拟机的IP对应的Port id
比如两台虚拟机做HA绑定vip,那么需要查看两台虚拟机的port ID和这个vip的port ID

neutron port-list|grep 4.131

5、取消安全组对应端口的管理

neutron port-update --no-security-groups <Port_id>
neutron port-update --port_security_enabled=false <Port_id>
注:
替换Port_id为之前neutron port-list中找到的Port_id

neutron port-update --no-security-groups 25758e55-9480-4a4c-9fe3-a9814ac00072
neutron port-update --port_security_enabled=false 25758e55-9480-4a4c-9fe3-a9814ac00072

6、此时执行命令neutron port-show

可看到port_security_enabled的value为False,security_groups的value为空,即OK,这样两个端口就没有了安全组了

[[root@manager ~]# neutron port-show dbb1d245-2ece-40c6-853e-df2734873924
±----------------------±-------------------------------------------------------------------------------------+
| Field | Value |
±----------------------±-------------------------------------------------------------------------------------+
| admin_state_up | True |
| allowed_address_pairs | |
| binding:host_id | node5 |
| binding:profile | {} |
| binding:vif_details | {“port_filter”: true} |
| binding:vif_type | bridge |
| binding:vnic_type | normal |
| created_at | 2018-12-25T02:05:51 |
| description | |
| device_id | 30a7fd91-34bc-43a7-83cd-2e51cb987619 |
| device_owner | compute:nova |
| extra_dhcp_opts | |
| fixed_ips | {“subnet_id”: “46c12a96-d1b6-4951-b57c-8884457f3e86”, “ip_address”: “10.10.4.161”} |
| id | dbb1d245-2ece-40c6-853e-df2734873924 |
| mac_address | fa:16:3e:e3:24:08 |
| name | |
| network_id | b7fff54f-ae3a-45ae-8d84-228b7bc41059 |
| port_security_enabled | True |
| security_groups | 7b318b1e-fa4c-4ac3-8b2c-6767bce7b6e7 |
| status | ACTIVE |
| tenant_id | 6ae3bb9cf1504355bfae9b911c50a19e |
| updated_at | 2019-02-11T01:33:58 |
±----------------------±-------------------------------------------------------------------------------------+

VIP和需要使用VIP的虚拟机都执行4、5、6步,比如配置HA,VIP+两台虚拟机,总共3个Port,都需要执行4、5、6步,然后就可以在这两台虚拟机上搭建keepalived集群使用10.10.4.131这个vip了

# 注意:每个运行虚拟机的IP和VIP都需要设置此操作。

[root@manager ~]# neutron port-list|grep 10.10.4.102
| 7974c3f7-8ba0-4c66-953c-ae954ae4e896 | | fa:16:3e:aa:b8:a4 | {“subnet_id”: “46c12a96-d1b6-4951-b57c-8884457f3e86”, “ip_address”: “10.10.4.102”} |

neutron port-update --no-security-groups 7974c3f7-8ba0-4c66-953c-ae954ae4e896
neutron port-update --port_security_enabled=false 7974c3f7-8ba0-4c66-953c-ae954ae4e896

[root@manager ~]# neutron port-list|grep 4.113
| 8ee0d442-8104-485c-b512-f3126ae4b10c | | fa:16:3e:e6:74:fc | {“subnet_id”: “46c12a96-d1b6-4951-b57c-8884457f3e86”, “ip_address”: “10.10.4.113”} |

neutron port-update --no-security-groups 8ee0d442-8104-485c-b512-f3126ae4b10c
neutron port-update --port_security_enabled=false 8ee0d442-8104-485c-b512-f3126ae4b10c

### 配置虚拟机 VIP 的方法 在 OpenStack 平台上配置虚拟机VIP (Virtual IP),由于 Neutron 中的安全机制,直接分配给网络的 VIP 可能无法正常工作。这是因为从 VM 端口发送/接收的数据包必须具有该 VM 端口的固定 IP/MAC 地址[^1]。 #### 解决方案一:允许地址对(Recommended) 为了使 VIP 正常运作,可以为需要使用 VIP虚拟机端口配置 `allowed_address_pairs` 参数。这使得数据包可以从不同的 MAC 或者 IP 发送出去而不受限制: ```bash openstack port set --allowed-address ip-address=192.168.1.100 mac-address=fa:16:3e:a:b:c <port-id> ``` 此命令会向特定端口添加一对允许使用的 IP 和 MAC 地址组合。如果只需要设置 IP,则可省略 MAC 地址部分: ```bash openstack port set --allowed-address ip-address=192.168.1.100 <port-id> ``` 这种方法不会影响现有的安全组规则,并且保持了安全性。 #### 解决方案二:禁用安全功能 另一种方式是通过关闭端口上的安全特性来实现 VIP 功能,但这通常不被推荐因为这样做可能会带来安全隐患: ```bash openstack port set --no-security-group <port-id> ``` 这种方式虽然简单但是降低了系统的整体安全性,因此除非绝对必要并充分理解风险后再考虑采用这种做法。 #### Linux 系统下手动配置 VIP 对于已经运行中的实例,也可以直接在其内部操作系统层面增加 VIP。例如,在 CentOS 7 上可以通过以下命令临时添加一个 VIP 至 eth0 接口: ```bash sudo ip addr add 192.168.1.200/24 dev eth0 label eth0:0 ``` 要永久保存更改则需编辑相应的网络接口文件 `/etc/sysconfig/network-scripts/ifcfg-eth0:0`[^4]。 #### 使用 Keepalived 实现高可用性 对于希望构建 HA 架构的应用场景来说,Keepalived 是一种常用的工具用于管理 VIP 的漂移和服务冗余。安装和配置 Keepalived 后可以根据设定条件自动切换主备节点间的 VIP 归属,从而提高服务连续性和可靠性[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值