1. 首页 > IT综合教程 > 正文

259. F5 BIG-IP负载均衡培训

一、F5 BIG-IP概述

F5 BIG-IP是业界领先的硬件负载均衡和应用交付控制器,提供高性能的流量管理、安全防护和应用加速功能。

学习交流加群风哥QQ113257174

1.1 F5 BIG-IP核心特性

  • 高性能硬件:专用硬件加速,处理能力强大
  • 丰富的负载均衡算法:支持多种调度算法
  • 应用安全:内置WAF、DDoS防护
  • SSL卸载:硬件加速SSL/TLS处理

1.2 F5核心概念

F5 BIG-IP核心对象:

Virtual Server(虚拟服务器)
    - 监听客户端请求的入口
    - 绑定VIP地址和端口
    - 关联Profile和Policy

Pool(服务器池)
    - 后端服务器集合
    - 定义负载均衡算法
    - 配置健康检查

Pool Member(池成员)
    - 具体的后端服务器
    - 定义IP地址和端口
    - 设置权重和优先级

Node(节点)
    - 服务器IP地址
    - 可被多个Pool共享
    - 统计服务器状态

Monitor(监视器)
    - 健康检查配置
    - 支持TCP/HTTP/HTTPS等
    - 定义检查间隔和阈值

二、F5基础配置

2.1 管理访问

# Web管理界面访问
https://

# 默认账号
fgedu: admin
密码: admin

# SSH访问
ssh admin@

# 进入TMOS Shell
tmsh

# 进入bash shell
run /bin/bash

2.2 网络配置

# TMOS命令行配置网络

# 创建VLAN
create net vlan external interfaces add { 1.1 }
create net vlan internal interfaces add { 1.2 }

# 配置Self IP
create net self 192.168.1.100/24 vlan external
create net self 10.0.0.1/24 vlan internal

# 配置路由
create net route default gw 192.168.1.1

# 查看网络配置
list net vlan
list net self
list net route

三、Virtual Server配置

3.1 创建Virtual Server

# 创建HTTP Virtual Server
create ltm virtual web_vs {
    destination 192.168.1.100:80
    ip-protocol tcp
    mask 255.255.255.255
    pool web_pool
    profiles add { 
        http { }
        tcp { }
    }
    source-address-translation {
        type automap
    }
}

# 创建HTTPS Virtual Server
create ltm virtual web_vs_https {
    destination 192.168.1.100:443
    ip-protocol tcp
    mask 255.255.255.255
    pool web_pool
    profiles add {
        http { }
        tcp { }
        clientssl {
            cert fgedu.net.cn.crt
            key fgedu.net.cn.key
        }
    }
    source-address-translation {
        type automap
    }
}

# 查看Virtual Server
list ltm virtual web_vs

3.2 Virtual Server类型

类型 说明 适用场景
Standard 标准虚拟服务器 HTTP/HTTPS应用
Performance (HTTP) 高性能HTTP 高流量HTTP场景
Performance (Layer 4) 四层负载均衡 TCP/UDP应用
Forwarding 转发虚拟服务器 路由转发

四、Pool配置

4.1 创建Pool

# 创建Pool
create ltm pool web_pool {
    members add {
        10.0.0.101:80 { 
            address 10.0.0.101
        }
        10.0.0.102:80 { 
            address 10.0.0.102
        }
        10.0.0.103:80 { 
            address 10.0.0.103
        }
    }
    monitor http_monitor
    load-balancing-mode round-robin
}

# 查看Pool
list ltm pool web_pool

# 查看Pool成员状态
show ltm pool web_pool members

4.2 负载均衡算法

# 设置负载均衡算法
modify ltm pool web_pool load-balancing-mode least-connections-member

# 可用算法
round-robin              # 轮询
least-connections-member # 最少连接
least-connections-node   # 节点最少连接
ratio-member             # 加权轮询
ratio-node               # 节点加权
source-address           # 源地址哈希
destination-address      # 目标地址哈希
observed-member          # 观察模式
predictive-member        # 预测模式

五、Monitor配置

5.1 HTTP Monitor

# 创建HTTP Monitor
create ltm monitor http http_monitor {
    defaults-from http
    destination *:80
    interval 5
    timeout 16
    send "GET /health HTTP/1.1\r\nHost: fgedu.net.cn\r\nConnection: close\r\n\r\n"
    recv "HTTP/1.1 200"
}

# 创建HTTPS Monitor
create ltm monitor https https_monitor {
    defaults-from https
    destination *:443
    interval 5
    timeout 16
    send "GET /health HTTP/1.1\r\nHost: fgedu.net.cn\r\nConnection: close\r\n\r\n"
    recv "HTTP/1.1 200"
    ssl-profile clientssl
}

# 关联Monitor到Pool
modify ltm pool web_pool monitor http_monitor

5.2 TCP Monitor

# 创建TCP Monitor
create ltm monitor tcp tcp_monitor {
    defaults-from tcp
    destination *:3306
    interval 5
    timeout 16
}

# 创建自定义TCP Monitor
create ltm monitor tcp mysql_monitor {
    defaults-from tcp
    destination *:3306
    interval 5
    timeout 16
    send "\x00\x00\x00\x00\x00"
    recv "mysql"
}

六、iRules脚本

6.1 iRules基础

# 创建iRule
create ltm irule redirect_https {
    when HTTP_REQUEST {
        HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
    }
}

# 基于路径的流量分发
create ltm irule path_routing {
    when HTTP_REQUEST {
        switch -glob [HTTP::uri] {
            "/api/*" {
                pool api_pool
            }
            "/static/*" {
                pool static_pool
            }
            default {
                pool web_pool
            }
        }
    }
}

# 关联iRule到Virtual Server
modify ltm virtual web_vs rules add { redirect_https }

6.2 高级iRules

# 基于Header的路由
create ltm irule header_routing {
    when HTTP_REQUEST {
        set version [HTTP::header "X-API-Version"]
        switch $version {
            "v1" {
                pool api_v1_pool
            }
            "v2" {
                pool api_v2_pool
            }
            default {
                pool api_pool
            }
        }
    }
}

# 限流iRule
create ltm irule rate_limit {
    when HTTP_REQUEST {
        set client_ip [IP::client_addr]
        set key "rate_limit_$client_ip"
        
        if { [table keys -subtable $key] > 100 } {
            HTTP::respond 429 content "Too Many Requests"
            return
        }
        
        table add -subtable $key [clock clicks] 1 60
    }
}

七、SSL配置

7.1 证书管理

# 导入证书
install sys crypto cert fgedu.net.cn.crt from-local-file /var/tmp/fgedu.net.cn.crt

# 导入私钥
install sys crypto key fgedu.net.cn.key from-local-file /var/tmp/fgedu.net.cn.key

# 创建SSL Profile
create ltm profile clientssl clientssl_example {
    cert fgedu.net.cn.crt
    key fgedu.net.cn.key
    ciphers DEFAULT
    options { dont-insert-empty-fragments no-tlsv1 no-tlsv1.1 }
}

# 关联到Virtual Server
modify ltm virtual web_vs_https profiles add { clientssl_example }

7.2 SSL卸载配置

# 创建SSL卸载配置
create ltm virtual ssl_offload {
    destination 192.168.1.100:443
    ip-protocol tcp
    pool web_pool
    profiles add {
        tcp { }
        http { }
        clientssl_example { }
    }
    source-address-translation {
        type automap
    }
}

# 后端使用HTTP
# F5处理SSL,后端服务器使用HTTP

八、高可用配置

8.1 HA配置

# 配置HA同步
# 主设备
modify cm device  {
    configsync-ip <同步IP>
    management-ip <管理IP>
}

# 创建设备组
create cm device-group ha_group {
    devices add {   }
    type sync-failover
    auto-sync enabled
    network-failover enabled
}

# 配置Failover
create sys failover {
    group ha_group
}

# 同步配置
run cm config-sync to-group ha_group

8.2 Floating IP配置

# 创建Traffic Group
create cm traffic-group traffic-group-1 {
    unit-id 1
}

# 配置Floating IP
create net self 192.168.1.100/24 vlan external traffic-group traffic-group-1

# Virtual Server使用Floating IP
modify ltm virtual web_vs traffic-group traffic-group-1

九、运维命令

9.1 常用管理命令

# 查看系统状态
show sys performance
show sys hardware

# 查看连接状态
show sys connection

# 查看Pool状态
show ltm pool
show ltm pool web_pool members

# 查看Virtual Server状态
show ltm virtual

# 启用/禁用Pool成员
modify ltm pool web_pool members modify { 10.0.0.101:80 { session disable } }
modify ltm pool web_pool members modify { 10.0.0.101:80 { session enable } }

# 强制下线
modify ltm pool web_pool members modify { 10.0.0.101:80 { state down } }

# 保存配置
save sys config

# 查看日志
show log ltm
tail -f /var/log/ltm

十、最佳实践

配置项 建议值 说明
Monitor间隔 5秒 及时检测故障
超时时间 3倍间隔 避免误判
SSL协议 TLSv1.2+ 安全传输
HA模式 Active-Standby 高可用
注意事项:

  • 配置修改后需保存
  • 定期备份配置
  • 监控设备资源使用
  • 证书需定期更新

十一、总结

F5 BIG-IP是企业级负载均衡解决方案。通过本培训文档,您应该掌握了:

  • F5核心概念和架构
  • Virtual Server和Pool配置
  • Monitor健康检查配置
  • iRules脚本编写
  • SSL卸载配置
  • 高可用和运维管理
IT运维培训文档系列 | 第259篇 | F5 BIG-IP负载均衡培训

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息