分流转发

    • 假设我们有一个http server对外提供服务,并且有2个服务实例;1个负责处理静态文件请求,另外1个负责处理动态请求
    • 域名:example.org
    • 以/static开头的请求都转发至静态文件服务实例;地址:10.0.0.1:8001
    • 其他的请求都转发至动态服务实例;地址:10.0.0.1:8002

    配置说明

    • Step 1.在 conf/bfe.conf配置转发功能使用的配置文件路径
    • Step 2. 配置域名规则 (conf/server_data_conf/host_rule.data)
    1. "Version": "init version",
    2. "DefaultProduct": null,
    3. "Hosts": {
    4. "exampleTag":[
    5. "example.org" // 域名example.org=>域名标签exampleTag
    6. ]
    7. },
    8. "HostTags": {
    9. "example_product":[
    10. "exampleTag" // 域名标签exampleTag=>产品线名称example_product
    11. ]
    12. }
    • Step 3. 配置集群的基础信息 (conf/server_data_conf/cluster_conf.data) 配置集群cluster_demo_static和cluster_demo_dynamic健康检查的参数,其他均使用默认值
    • Step 4. 配置集群下实例信息 (conf/cluster_conf/cluster_table.data)
    1. {
    2. "Version": "init version",
    3. "Config": {
    4. "demo_static.all": [{ // 子集群demo_static.all
    5. "Addr": "10.0.0.1", // 实例地址:10.0.0.1
    6. "Name": "static.A", // 实例名:static.A
    7. "Port": 8001, // 实例端口:8001
    8. "Weight": 1 // 实例权重:1
    9. }]
    10. },
    11. "cluster_demo_dynamic": {
    12. "demo_dynamic.all": [{
    13. "Addr": "10.0.0.1",
    14. "Name": "dynamic.A",
    15. "Port": 8002,
    16. "Weight": 1
    17. }]
    18. }
    • Step 5. 配置子集群内负载均衡 (conf/cluster_conf/gslb.data)
    • Step 6. 配置分流规则 (conf/server_data_conf/route_rule.data)
    • 将/static开头的流量转发到cluster_demo_static集群
    • 其余流量转发到cluster_demo_dynamic集群
    1. {
    2. "Version": "init version",
    3. "ProductRule": {
    4. "example_product": [ // 产品线 => 分流规则
    5. {
    6. // 以/static开头的path分流到cluster_demo_static集群
    7. "Cond": "req_path_prefix_in(\"/static\", false)",
    8. "ClusterName": "cluster_demo_static"
    9. },
    10. {
    11. // 其他流量分流到cluster_demo_dynamic集群
    12. "Cond": "default_t()",
    13. "ClusterName": "cluster_demo_dynamic"
    14. }
    15. ]
    16. }
    • Step 7. 验证配置规则