华为云 容器获取通过LB Service访问的客户端真实IP

  1. 配置负载访问方式,添加LB SERVICE
    在这里插入图片描述
    此时通过配置的B Service访问服务无法获取到客户端源IP,remoteAddr为华为云负载均衡器的IP地址
    注:本文测试使用的镜像为containous/whoami
    在这里插入图片描述
  2. 安装TOA插件
    华为云文档
  • 在容器节点上执行命令安装TOA模块
# 准备编译环境
yum install gcc
yum install make
# 下载TOA插件源码
wget https://github.com/Huawei/TCP_option_address/archive/master.zip
# 解压编译
unzip master.zip
cd TCP_option_address-master/src/
make
# 加载TOA模块
insmod toa.ko
  • 验证TOA模块
dmesg | grep toa

在这里插入图片描述

  • 创建脚本重启自动加载TOA模块

创建文件/etc/sysconfig/modules/toa.modules
/usr/src/TCP_option_address-master/src/toa.ko替换为编译toa的路径

#!/bin/sh
/sbin/modinfo -F filename /usr/src/TCP_option_address-master/src/toa.ko > /dev/null 2>&1
if [ $? -eq 0 ]; then
/sbin/insmod /usr/src/TCP_option_address-master/src/toa.ko
fi
  • 为toa.modules启动脚本添加可执行权限
chmod +x /etc/sysconfig/modules/toa.modules
  1. 修改负载均衡配置
  • 找到LB SERVICE关联的负载均衡器
    在这里插入图片描述
  • 修改监听器属性,开启获取客户端IP
    在这里插入图片描述
  • 等待大约10秒配置生效,remoteAddr已经获取正确的客户端IP
    在这里插入图片描述

posted on   路过君  阅读(204)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示