bfe 参考架构
bfe 参考回调点
安装
下载对应平台的软件包,解压即可
流程
注意因为配置是json 格式,所以关于json 注释的信息都应该删除,否则配置会有问题
- 基本配置 conf/bfe.conf
hostRuleConf = server_data_conf/host_rule.data #域名规则配置文件
routeRuleConf = server_data_conf/route_rule.data #分流规则配置文件
clusterConf = server_data_conf/cluster_conf.data #集群配置文件
clusterTableConf = cluster_conf/cluster_table.data #集群实例列表配置文件
gslbConf = cluster_conf/gslb.data #子集群负载均衡配置文件
- 域名配置(产品线,租户)conf/server_data_conf/host_rule.data
{
"Version": "init version",
"DefaultProduct": null,
"Hosts": {
"jenkinsapp":[
"mydemoapp.rongfengliang.com"
]
},
"HostTags": {
"jenkinsdemo_product":[
"jenkinsapp"
]
}
}
- 集群信息配置 conf/server_data_conf/cluster_conf.data
{
"Version": "init version",
"Config": {
"cluster_demo_static": { // 集群cluster_demo_static的配置
"CheckConf": { // 健康检查配置
"Schem": "http",
"Uri": "/",
"Host": "mydemoapp.rongfengliang.com",
"StatusCode": 200
}
},
"cluster_demo_dynamic": { // 集群cluster_demo_dynamic的配置
"CheckConf": { // 健康检查配置
"Schem": "http",
"Uri": "/",
"Host": "mydemoapp.rongfengliang.com",
"StatusCode": 200
}
}
}
}
- 集群实例配置 conf/cluster_conf/cluster_table.data
{
"Version": "init version",
"Config": {
"cluster_demo_static": { // 集群 => 子集群 => 实例列表
"demo_static.all": [{ // 子集群demo_static.all
"Addr": "10.15.0.15", // 实例地址:10.0.0.1
"Name": "static.A", // 实例名:static.A
"Port":50658, // 实例端口:8001
"Weight": 1 // 实例权重:1
}]
},
"cluster_demo_dynamic": {
"demo_dynamic.all": [{
"Addr": "10.15.0.80",
"Name": "dynamic.A",
"Port":80,
"Weight": 1
}]
}
}
}
- 子集群负载均衡 conf/cluster_conf/gslb.data
{
"Hostname": "",
"Ts": "0",
"Clusters": {
"cluster_demo_static": { // 集群 => 子集群权重
"GSLB_BLACKHOLE": 0, // 黑洞的分流权重为0,表示不丢弃流量
"demo_static.all": 100 // 权重为100,表示全部分流到demo_static.all
},
"cluster_demo_dynamic": {
"GSLB_BLACKHOLE": 0,
"demo_dynamic.all": 100
}
}
}
- 分流规则 conf/server_data_conf/route_rule.data
{
"Version": "init version",
"ProductRule": {
"jenkinsdemo_product": [ // 产品线 => 分流规则
{
// 以/static开头的path分流到cluster_demo_static集群
"Cond": "req_path_prefix_in("/cube", false)",
"ClusterName": "cluster_demo_static"
},
{
// 其他流量分流到cluster_demo_dynamic集群
"Cond": "default_t()",
"ClusterName": "cluster_demo_dynamic"
}
]
}
}
启动
./bfe -c ../conf -l ../log
测试
- 访问
// 静态信息
curl -H "host: mydemoapp.rongfengliang.com" "http://127.0.0.1:8080/cube/index.html"
// 动态信息
curl -H "host: mydemoapp.rongfengliang.com" "http://127.0.0.1:8080"
参考资料
https://www.bfe-networks.net/zh_cn/example/route/
https://www.bfe-networks.net/zh_cn/development/module/bfe_callback/
https://www.bfe-networks.net/zh_cn/introduction/route/
https://www.bfe-networks.net/zh_cn/introduction/forward_model/
https://www.bfe-networks.net/zh_cn/introduction/balance/