负载均衡 报文转发模式服务节点配置 ULB

摘要:若绑定多个,则多个均需要配置。外网时,即为负载均衡器的外网服务地址即。本质上讲,无论后端服务实例是何种操作系统,只要将负载均衡器的配置到后端服务实例上即可。

报文转发模式服务节点配置

本篇目录

Linux配置方法Windows配置方法

“报文转发模式”下,由于用户访问会经ULB直接透传,必须保证访问地址落在后端真实服务节点上,所以要将负载均衡的内/外网IP地址配置在后端服务节点中。配置方法如下。

Linux配置方法

注意:

1、以下示例命令中的文件名称可根据实际需要修改。

2、命令和脚本中的”$VIP”,请替换成实际使用的ULB的VIP。

3、若ULB绑定多个EIP,则多个EIP均需要配置。

操作系统云主机未使用cloudinit云主机使用cloudinit

CentOS7及以下1、创建虚拟网卡配置文件:touch/etc/sysconfig/network-scripts/ifcfg-lo:12、在/etc/sysconfig/network-scripts/ifcfg-lo:1增加以下配置:DEVICE=lo:1IPADDR=$VIPNETMASK=255.255.255.2553、启动虚拟网卡:ifuplo:1UserData中添加以下内容:UserData说明#!/bin/bashtouch/etc/sysconfig/network-scripts/ifcfg-lo:1echo-e"DEVICE=lo:1
IPADDR=$VIP
NETMASK=255.255.255.255">/etc/sysconfig/network-scripts/ifcfg-lo:1
ifuplo:1CentOS8及以上1、安装network-scripts:yuminstallnetwork-scripts-y2、创建虚拟网卡配置文件:touch/etc/sysconfig/network-scripts/ifcfg-lo:13、在/etc/sysconfig/network-scripts/ifcfg-lo:1增加以下配置:DEVICE=lo:1IPADDR=$VIPNETMASK=255.255.255.2554、启动虚拟网卡ifuplo:1UserData中添加以下内容:UserData说明#!/bin/bashyuminstallnetwork-scripts-ytouch/etc/sysconfig/network-scripts/ifcfg-lo:1echo-e"DEVICE=lo:1
IPADDR=$VIP
NETMASK=255.255.255.255">/etc/sysconfig/network-scripts/ifcfg-lo:1
ifuplo:1Ubuntu16.041、创建虚拟网卡配置文件:sudotouch/etc/network/interfaces.d/lo-cloud-init.cfg2、在/etc/network/interfaces.d/lo-cloud-init.cfg中增加以下配置:autolo:1ifacelo:1inetstaticaddress$VIPnetmask255.255.255.2553、启动虚拟网卡sudo/etc/init.d/networkingrestartUserData中添加以下内容:UserData说明#!/bin/bashsudotouch/etc/network/interfaces.d/lo-cloud-init.cfgsudoecho-e"autolo:1
ifacelo:1inetstatic
address$VIP
netmask255.255.255.255">/etc/network/interfaces.d/lo-cloud-init.cfg
sudo/etc/init.d/networkingrestartUbuntu18.04Ubuntu20.041、创建虚拟网卡配置文件:sudotouch/etc/netplan/lo-cloud-init.yaml2、在文件/etc/netplan/lo-cloud-init.yaml中增加以下配置(注意每行缩进):network:ethernets:lo:addresses:-$VIP/323、使配置生效sudonetplanapplyUserData中添加以下内容:UserData说明(注意每行缩进)#!/bin/bashsudotouch/etc/netplan/lo-cloud-init.yamlsudoecho-e"network:
ethernets:
lo:
addresses:
-$VIP/32">/etc/netplan/lo-cloud-init.yaml
sudonetplanapplyDebian10.01、创建虚拟网卡配置文件:touch/etc/network/interfaces.d/lo-cloud-init2、在/etc/network/interfaces.d/lo-cloud-init中增加以下配置:autolo:1ifacelo:1inetstaticaddress$VIPnetmask255.255.255.2553、启动虚拟网卡/etc/init.d/networkingrestartUserData中添加以下内容:UserData说明#!/bin/bashtouch/etc/network/interfaces.d/lo-cloud-initecho-e"autolo:1
ifacelo:1inetstatic
address$VIP
netmask255.255.255.255">/etc/network/interfaces.d/lo-cloud-init
/etc/init.d/networkingrestartRockyLinux8.51、安装network-scripts:yuminstallnetwork-scripts-y2、创建虚拟网卡配置文件:touch/etc/sysconfig/network-scripts/ifcfg-lo:13、在/etc/sysconfig/network-scripts/ifcfg-lo:1增加以下配置:DEVICE=lo:1IPADDR=$VIPNETMASK=255.255.255.2554、启动虚拟网卡ifuplo:1UserData中添加以下内容:UserData说明#!/bin/bashyuminstallnetwork-scripts-ytouch/etc/sysconfig/network-scripts/ifcfg-lo:1echo-e"DEVICE=lo:1
IPADDR=$VIP
NETMASK=255.255.255.255">/etc/sysconfig/network-scripts/ifcfg-lo:1
ifuplo:1
获取网卡VIP

内网ULB时,这里的$VIP即为负载均衡器的内网服务IP地址。
外网ULB时,即为负载均衡器的外网服务IP地址(即EIP)。
如果您使用自动化脚本配置,我们建议您使用API获取您配置所需的VIP。

如何调用此API请参考:获取负载均衡信息-DescribeULB

负载均衡 报文转发模式服务节点配置  ULB
负载均衡 报文转发模式服务节点配置  ULB

Windows配置方法

第1步:添加lo接口

依次在“设备管理器”中选择”网络适配器”,并在菜单栏中点击“操作”→“添加过时硬件”→“安装我从手动列表安装的硬件”。并在厂商中选择”Microsoft”,网络适配器选择“Microsoft Loopback Adapter”,并点击下一步完成设备创建。

注意在windows8、windows server2012及更新版本中,“Microsoft Loopback Adapter”更名为“Microsoft KM-TEST 环回适配器”。

负载均衡 报文转发模式服务节点配置  ULB
负载均衡 报文转发模式服务节点配置  ULB

第2步:配置lo接口

内网ULB时,lo接口的IP即为负载均衡器的内网服务IP地址。
外网ULB时,lo接口的IP为负载均衡器的外网服务IP地址(即EIP)。
然后在“网络和共享中心”中,选择更改适配器设置,并配置lo接口,配置内容如图片所示:

负载均衡 报文转发模式服务节点配置  ULB

负载均衡 报文转发模式服务节点配置  ULB

负载均衡 报文转发模式服务节点配置  ULB

第3步:激活lo接口

在“cmd”中执行以下命令,其中$LOCAL代表本地接口名称,$LO代表回环接口名称。

@echo off
netsh interface ipv4 set interface "$LOCAL" weakhostreceive=enabled
netsh interface ipv4 set interface "$LOCAL" weakhostsend=enabled
netsh interface ipv4 set interface "$LO" weakhostreceive=enabled
netsh interface ipv4 set interface "$LO" weakhostsend=enabled 
Pause

执行效果见下图。

建议配置windows系统时通过VNC登陆进行操作,如以上操作未生效,可在执行完”netsh”后重启网卡或服务进行查看。本质上讲,无论后端服务实例是何种操作系统,只要将负载均衡器的VIP配置到后端服务实例上即可。

负载均衡 报文转发模式服务节点配置  ULB

原创文章,作者:网友投稿,如若转载,请注明出处:https://www.cloudads.cn/archives/4523.html

发表评论

登录后才能评论