• 华为云 容器获取通过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
      在这里插入图片描述
  • 相关阅读:
    跨源资源共享(CORS)
    7.9 restful api
    7.8 http redirected
    7.7 设置http首部
    7.6 request form post
    7.5 URL 解析
    7.4 http request post get
    7.3 ip host反解析
    7.2 tcpclient 基本web
    7.1 获取所有网卡ip地址
  • 原文地址:https://www.cnblogs.com/luguojun/p/14294639.html
Copyright © 2020-2023  润新知