我建议以Consul为例,了解在分布式系统中Alexander Sigachev服务发现报告的解码。
创建Service Discovery的目的是使您可以以最低的成本将新应用程序连接到我们的现有环境。使用服务发现,我们可以最大程度地将以docker形式存在的容器或虚拟服务与运行它的环境分开。
我向大家致意!我是Alexander Sigachev,我为Inventos工作。今天,我将向您介绍诸如服务发现之类的概念。我们将以领事为例考虑服务发现。
![](https://habrastorage.org/webt/lw/ed/qn/lwedqnz0yo65okktwubqaqt9ih4.png)
服务发现可以解决哪些问题?
创建Service Discovery的目的是使您可以以最低的成本将新应用程序连接到我们的现有环境。使用服务发现,我们可以最大程度地将以docker形式存在的容器或虚拟服务与运行它的环境分开。
它是什么样子的?在经典的网络示例中,这是接受用户请求的前端。然后将其路由到后端。在此示例中,此负载均衡器在两个后端之间保持平衡。
![](https://habrastorage.org/webt/xy/cq/z_/xycqz_5qtn_nxxpegm7mu-rsaf4.png)
, . , , Service Discovery. Service Discovery load-balancer. Load-balancer backend . backend, , , .
![](https://habrastorage.org/webt/bg/ba/wc/bgbawcrp4ouevoqnopkpfignk28.png)
Service Discovery?
Service Discovery nginx, backend-.
![](https://habrastorage.org/webt/3q/nx/dl/3qnxdlcsdjbetna83vlxvejpjqg.png)
Service Discovery , .
?
- , , Service Discovery, .
- Service Discovery .
- , Service Discovery, , , , .
, . , , , Service Discovery. , Service Discovery .
- , , , .
![](https://habrastorage.org/webt/3x/h_/gn/3xh_gnbho0nmrk8qywsiv058_no.png)
. Load-balancer nginx . , Consul. consul-template. . , ( Golang). , , , Service Discovery «reload». , nginx .
![](https://habrastorage.org/webt/yw/j1/ul/ywj1ulwcgatsd5s3dr6sgkefat0.png)
Consul?
– Service Discovery.
– Health Checking.
KV Store.
Multi Datacenter.
? KV Store . Health Checking . Multi Datacenter , . , Amazon , -, , , , .
![](https://habrastorage.org/webt/jb/x8/jf/jbx8jfoevu6a5bt5k32xgl8anc0.png)
, Consul .
- Consul – , Go. Go – 1 , . .
- , .
- «datacenter» - .
- Consensus – raft. , Consul. , .
- Gossip – , . . - . , , . , .
- LAN Gossip – -.
- WAN Gossip – , -. , .
- RPC – .
RPC. , Consul . . . , , .
, . , . , , , .
![](https://habrastorage.org/webt/k7/xc/tj/k7xctj20rqiy9ri9jl_8ciwqsq0.png)
, . , . . , UDP/TCP. - . .
![](https://habrastorage.org/webt/ts/kd/ea/tskdeasgovv-sjkyy1e1pspt0fi.png)
API Consul?
, API Consul.
DNS API. Consul 8600 . , DNS. IP-.
HTTP API – 8500 JSON , IP , host, . token.
![](https://habrastorage.org/webt/pj/pp/jp/pjppjpyk3v_yq42gp5gybzr2slq.png)
, Consul?
, . Agent . . , .
– production. . , bootstrap , . . , . , , , . . , , bootstrap, . , .
. , , . , .
![](https://habrastorage.org/webt/o2/ve/ee/o2veee2ogo-bocu5zpiicme89kc.png)
Health Checks?
Consul Json . – google.com. , 30 . , .
– . curl localhost 10 .
Service Discovery. , .
![](https://habrastorage.org/webt/8a/ao/_w/8aao_wosqqatxmm-crepvoyts-w.png)
Consul UI-, . , .
«». , , Consul. . -, .
![](https://habrastorage.org/webt/8h/l3/dc/8hl3dcn2qbg3nwzaihfhyvowb1o.png)
«Nodes». , -. , , . . , . - , .
Consul , .
: -, Consul ?
: - . – -, . . Consul.
: . . Consul -?
: . -. – - . , , , .
: , -, Service Discovery - , Consul?
: . , . , name, . Consul.
: UI . UI, , production-. ? ? - ?
: UI Service Discovery. .
: ?
: Consul localhost. , - proxy. .
: ? Health Checks. , .
: , .
: , .
: – .
: Service Discovery Consul ?
: . – , . , -, 1- . , , Kubernetes, . Kubernetes Service Discovery Etcd. , Consul. Service Discovery Consul.
: ? Consul , ?
: . , .
: Consul ?
: , . , , service.consul. . production , , , DNS.
: . . , Consul, , ?
答:可以。如果我们使用DNS,那么当我们使用DNS名称时,它将像没有Consul一样工作。通常,现代应用程序不会在每个请求中都提取域名,因为我们已经安装了connect,一切正常,并且在不久的将来几乎不使用它。如果连接断开,那么-是的,我们再次询问我们的底座在哪里,然后转到它。