Fabio 安装和简单使用

Fabio 安装和简单使用Fabio Go 语言 https github com eBay fabioFabio 是一个快速 现代 zero conf 负载均衡 HTTP S 路由器 用于部署 Consul 管理的微服务 Fabio 由 eBayClassifi 开发 用于处理 marktplaats nl 和 kijiji it 的流量 Marktplaats 所有的流量都经过 Fa

Fabio(Go 语言):https://github.com/eBay/fabio

Fabio 是一个快速、现代、zero-conf 负载均衡 HTTP(S) 路由器,用于部署 Consul 管理的微服务。

Fabio 由 eBay Classifieds Group 开发,用于处理 marktplaats.nl 和 kijiji.it 的流量。Marktplaats 所有的流量都经过 Fabio ,每秒有 个请求,分发于数个 Fabio 实例,并且没有出现任何延迟。

简单流程图(摘自 http://dockone.io/article/1567):

======    服务注册     =========        ========= A服务    <------>    consul集群  ---->  健康的 A/不健康的 A 集群 ======    健康检查     =========        =========                                      ^                                      |  加入/移出路由表                                      |                                   ========                                    fabio 集群                                   ========                                      |                                      | A服务   如果找到则成功路由否则返回错误                                      V                                     http 请求
$ brew install fabio Updating Homebrew... ==> Auto-updated Homebrew!Updated 1 tap (homebrew/core). ==> New Formulae crystal-icr     gcc@4.7         gnome-autoar    libchaos        llvm@3.8        pdftoipe        tomcat@8.0dbt             gcc@5           isl@0.12        libswiftnav     mps-youtube     recipes         ucg gcc@4.6         gcc@6           lasso           llvm@3.7        ndenv           servus ==> Updated Formulae afflib                 dnscrypt-proxy         handbrake              mpv                    sassc ant                    doxygen                hebcal                 mysql                  sbcl antigen                duply                  highlight              mysql-connector-c++    sqldiff antlr                  flex                   hugo                   mysql-sandbox          sqlite apache-spark           fluent-bit             imagemagick            nagios                 sqlite-analyzer arangodb               fobis                  ipv6calc               nagios-plugins         stunnel astyle                 fontforge              jasper                 ncdc                   syncthing ats2-postiats          fpp                    jenkins                ncftp                  tarantool aws-sdk-cpp            freetype               lean-cli               neo4j                  taylor awscli                 ganglia                leptonica              nvm                    tile38 bup                    gcc                    libass                 ooniprobe              vim cdiff                  gcc@4.9                libgit2                opentsdb               volatility cfr-decompiler         geos                   libgit2-glib           osm2pgsql              vowpal-wabbit checkstyle             git-annex              libpng                 osquery                weechat cloog                  git-lfs                libxml2                pngpaste               wine compcert               gitg                   lmdb                   poco                   winetricks couchdb                gitless                m-cli                  pure-ftpd              wireguard-tools cppcheck               gmic                   macosvpn               qt5                    x265 czmq                   gnome-builder          menhir                 questdb                yaz dbhash                 gnutls                 mg                     rclone                 youtube-dl dmd                    groonga                mitmproxy              re2 ==> Deleted Formulae cloog@0.18                            qt                                    tutumError: Could not link: /usr/local/share/man/man1/brew.1Please delete these paths and run `brew update`. ==> Installing dependencies for fabio: consul ==> Installing fabio dependency: consul ==> Downloading https://homebrew.bintray.com/bottles/consul-0.7.2.sierra.bottle.tar.gz 100.0% ==> Pouring consul-0.7.2.sierra.bottle.tar.gzError: The `brew link` step did not complete successfully The formula built, but is not symlinked into /usr/localCould not symlink bin/consul Target /usr/local/bin/consul already exists. You may want to remove it:   rm '/usr/local/bin/consul'To force the link and overwrite all conflicting files:   brew link --overwrite consulTo list all files that would be deleted:   brew link --overwrite --dry-run consulPossible conflicting files are: /usr/local/bin/consul ==> CaveatsIf consul was built with --with-web-ui, you can activate the UI by runningconsul with `-ui-dir /usr/local/Cellar/consul/0.7.2/share/consul/web-ui`.   zsh completion has been installed to:   /usr/local/share/zsh/site-functionsTo have launchd start consul now and restart at login:   brew services start consulOr, if you don't want/need a background service you can just run:  consul agent -dev -advertise 127.0.0.1 ==> Summary  /usr/local/Cellar/consul/0.7.2: 5 files, 27.6M ==> Installing fabio ==> Downloading https://homebrew.bintray.com/bottles/fabio-1.3.5.sierra.bottle.tar.gz 100.0% ==> Pouring fabio-1.3.5.sierra.bottle.tar.gz  /usr/local/Cellar/fabio/1.3.5: 6 files, 10.1M

1. 创建fabio目录:

$ mkdir /opt/fabio

2. 设置环境变量:

$ export PATH=$PATH:/opt/fabio

3. 创建fabio.properties文件(/opt/fabio工作目录下):

$ touch fabio.properties

4. 下载 Fabio 文件(地址:https://github.com/eBay/fabio/releases):

$ wget https://github.com/eBay/fabio/releases/download/v1.3.5/fabio-1.3.5-go1.7.3-linux_amd64

5. 赋予权限:

$ chmod a+x fabio-1.3.5-go1.7.3-linux_amd64

6. 设置fabio命令:

$ ln -s fabio-1.3.5-go1.7.3-linux_amd64 fabio
API server listening at: 127.0.0.1:33178
2018/10/30 15:05:24 [INFO] Setting log level to INFO
2018/10/30 15:05:55 [INFO] Runtime config
{
    "Proxy": {
        "Strategy": "rnd",
        "Matcher": "prefix",
        "NoRouteStatus": 404,
        "MaxConn": 10000,
        "ShutdownWait": 0,
        "DialTimeout": 30000000000,
        "ResponseHeaderTimeout": 0,
        "KeepAliveTimeout": 0,
        "FlushInterval": 1000000000,
        "GlobalFlushInterval": 0,
        "LocalIP": "10.128.23.4",
        "ClientIPHeader": "",
        "TLSHeader": "",
        "TLSHeaderValue": "",
        "GZIPContentTypes": null,
        "RequestID": "",
        "STSHeader": {
            "MaxAge": 0,
            "Subdomains": false,
            "Preload": false
        }
    },
    "Registry": {
        "Backend": "consul",
        "Static": {
            "NoRouteHTML": "",
            "Routes": ""
        },
        "File": {
            "NoRouteHTMLPath": "",
            "RoutesPath": ""
        },
        "Consul": {
            "Addr": "registd.fcae.io",
            "Scheme": "http",
            "Token": "",
            "KVPath": "/fabio/config",
            "NoRouteHTMLPath": "/fabio/noroute.html",
            "TagPrefix": "urlprefix-",
            "Register": true,
            "ServiceAddr": ":9998",
            "ServiceName": "fabio",
            "ServiceTags": null,
            "ServiceStatus": [
                "passing"
            ],
            "CheckInterval": 1000000000,
            "CheckTimeout": 3000000000,
            "CheckScheme": "http",
            "CheckTLSSkipVerify": false,
            "CheckDeregisterCriticalServiceAfter": "90m",
            "ChecksRequired": "one"
        },
        "Timeout": 10000000000,
        "Retry": 500000000
    },
    "Listen": [
        {
            "Addr": ":9999",
            "Proto": "http",
            "ReadTimeout": 0,
            "WriteTimeout": 0,
            "CertSource": {
                "Name": "",
                "Type": "",
                "CertPath": "",
                "KeyPath": "",
                "ClientCAPath": "",
                "CAUpgradeCN": "",
                "Refresh": 0,
                "Header": null
            },
            "StrictMatch": false,
            "TLSMinVersion": 0,
            "TLSMaxVersion": 0,
            "TLSCiphers": null
        }
    ],
    "Log": {
        "AccessFormat": "common",
        "AccessTarget": "",
        "RoutesFormat": "delta",
        "Level": "INFO"
    },
    "Metrics": {
        "Target": "",
        "Prefix": "{
  
  
  
  
  
  
  
  {clean .Hostname}}.{ 
  {clean .Exec}}", "Names": "{ 
  {clean .Service}}.{ 
  {clean .Host}}.{ 
  {clean .Path}}.{ 
  {clean .TargetURL.Host}}",
        "Interval": 30000000000,
        "Timeout": 10000000000,
        "Retry": 500000000,
        "GraphiteAddr": "",
        "StatsDAddr": "",
        "Circonus": {
            "APIKey": "",
            "APIApp": "fabio",
            "APIURL": "",
            "CheckID": "",
            "BrokerID": ""
        }
    },
    "UI": {
        "Listen": {
            "Addr": ":9998",
            "Proto": "http",
            "ReadTimeout": 0,
            "WriteTimeout": 0,
            "CertSource": {
                "Name": "",
                "Type": "",
                "CertPath": "",
                "KeyPath": "",
                "ClientCAPath": "",
                "CAUpgradeCN": "",
                "Refresh": 0,
                "Header": null
            },
            "StrictMatch": false,
            "TLSMinVersion": 0,
            "TLSMaxVersion": 0,
            "TLSCiphers": null
        },
        "Color": "light-green",
        "Title": "",
        "Access": "rw"
    },
    "Runtime": {
        "GOGC": 800,
        "GOMAXPROCS": 4
    },
    "Tracing": {
        "TracingEnabled": false,
        "CollectorType": "http",
        "ConnectString": "http://localhost:9411/api/v1/spans",
        "ServiceName": "Fabiolb",
        "Topic": "Fabiolb-Kafka-Topic",
        "SamplerRate": -1,
        "SpanHost": "localhost:9998"
    },
    "ProfileMode": "",
    "ProfilePath": "C:\\Users\\lenovo\\AppData\\Local\\Temp",
    "Insecure": false,
    "GlobMatchingDisabled": false
}
2018/10/30 15:17:19 [INFO] Version 1.5.10 starting
2018/10/30 15:17:22 [INFO] Go runtime is go1.11
2018/10/30 15:17:29 [INFO] Metrics disabled
2018/10/30 15:17:29 [INFO] Setting GOGC=800
2018/10/30 15:17:29 [INFO] Setting GOMAXPROCS=4
2018/10/30 15:17:32 [INFO] consul: Connecting to "registd.fcae.io" in datacenter "mars"
2018/10/30 15:17:32 [INFO] Admin server access mode "rw"
2018/10/30 15:17:32 [INFO] Admin server listening on ":9998"
2018/10/30 15:17:32 [INFO] Waiting for first routing table
2018/10/30 15:17:32 [INFO] consul: Using dynamic routes
2018/10/30 15:17:32 [INFO] consul: Using tag prefix "urlprefix-"
2018/10/30 15:17:32 [INFO] consul: Watching KV path "/fabio/config"
2018/10/30 15:17:32 [INFO] consul: Watching KV path "/fabio/noroute.html"
2018/10/30 15:17:32 [INFO] consul: Registered fabio as "fabio"
2018/10/30 15:17:32 [INFO] consul: Registered fabio with id "fabio-lenovo-9998"
2018/10/30 15:17:32 [INFO] consul: Registered fabio with address "10.128.23.4"
2018/10/30 15:17:32 [INFO] consul: Registered fabio with tags ""
2018/10/30 15:17:32 [INFO] consul: Registered fabio with health check to "http://[10.128.23.4]:9998/health"
2018/10/30 15:17:32 [INFO] Config updates
  • http://10.9.10.173:9998/health:服务可以请求到这个地址,用于服务的健康检查(Fabio 统一健康检查)。
  • http://10.9.10.173:9999/{servicename}:服务的负载均衡地址,所有的服务调用都会请求到这个 Origin,Fabio 会进行服务分发。
  • http://10.9.10.173:9998:Fabio 后台 UI 界面,可以看到服务地址和权重,也可以增加路由规则。

服务注册的时候,需要以 Fabio 的方式进行注册(SDK 进行实现)。

服务的路由需要添加{servicename}(Fabio 识别具体的服务),比如:

[Route("server-test/values")] public class ValuesController : Controller{     public string Get()    {         return "hello world";     } }
var service = await _serviceRegistry.GetServiceInstanceAsync("server-test"); var serverUrl = $"{service.Address}:{service.Port}"; if (!serverUrl.StartsWith("http://", StringComparison.OrdinalIgnoreCase))     serverUrl = "http://" + serverUrl; var url = $"{serverUrl}/server-test/values"; var httpClient = new HttpClient(); var response = await httpClient.GetAsync(url);

640?wx_fmt=png

 

相关文章: 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/199285.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月26日 下午1:27
下一篇 2026年3月26日 下午1:27


相关推荐

  • POJ 1011 Sticks

    POJ 1011 Sticks

    2021年12月7日
    42
  • 科学计数法E表示什么_科学计数法e-5什么意思

    科学计数法E表示什么_科学计数法e-5什么意思计算机表达10的幂是一般是用E或e,即1.03乘10的8次方,可简写为“1.03E+08”的形式-1.03乘10的8次方,可简写为“-1.03E+08”的形式1.03乘10的-8次方,可简写为“1.03E-08”的形式-1.03乘10的-8次方,可简写为“-1.03E-08”的形式…

    2025年8月13日
    6
  • Postgresql基础操作3-常用SQL命令

    Postgresql基础操作3-常用SQL命令

    2021年8月28日
    66
  • 如何修改visual-studio的sln文件和project工程名

    如何修改visual-studio的sln文件和project工程名关于VS的.sln文件和.suo文件*.sln:(VisualStudio.Solution)通过为环境提供对项目、项目项和解决方案项在磁盘上位置的引用,可将它们组织到解决方案中。比如是生成Debug模式,还是Release模式,是通用CPU还是专用的等.*.suo:(solutionuseropertion)解决方案用户选项记录所有将与解决方案建立关联的选项,*.suo是一种文件的格式。它是很重要的文件,*.suo解决方案用户选项,记录所有将与解决方案建立关联的选项,..

    2022年5月7日
    115
  • class文件与dex文件解析

    class文件与dex文件解析这篇笔记是我去年的时候创建的,结果放到草稿箱里给忘记了,大写的尴尬啊,所以急忙给补上了,此处鄙视一下自己!今天的正题——解析class文件和dex文件。

    2022年6月27日
    80
  • Volatile原理解析

    Volatile原理解析一 实现原理 nbsp nbsp nbsp nbsp 对于 volatile 的解释 我相信更直白的说就是对于一个被 volatile 关键字修饰的变量 在并发情况下 Java 内存模型 JMM 保证每个线程对该变量的可见性 保证他们读取的数据是一致的 因此 volatile 实现了数据的可见性 有序性 但不保证原子性 下文会详细解释 但是怎样保证可见性的呢 在 jvm 底层对于 volatile 修饰的共享变量进行写操作的时候主要实现了两个步骤 将当前处理器缓存行的数据写回到系统内存 将其他处理器中缓存了该数据的

    2026年3月9日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号