代码拉取完成,页面将自动刷新
title |
---|
zookeeper |
Zookeeper
service discovery needs to rely on the apisix-seed project.
apisix-seed
Worksapisix-seed
completes data exchange by watching the changes of etcd
and zookeeper
at the same time.
The process is as follows:
APISIX
registers an upstream and specifies the service discovery type as zookeeper
to etcd
.apisix-seed
watches the resource changes of APISIX
in etcd
and filters the discovery type and obtains the service name.apisix-seed
binds the service to the etcd
resource and starts watching the service in zookeeper.zookeeper
.apisix-seed
gets the service changes in zookeeper
.apisix-seed
queries the bound etcd
resource information through the service name, and writes the updated service node to etcd
.APISIX
worker watches etcd
changes and refreshes the service node information to the memory.apisix-seed
and ZookeeperThe configuration steps are as follows:
docker run -itd --rm --name=dev-zookeeper -p 2181:2181 zookeeper:3.7.0
apisix-seed
project.git clone https://github.com/api7/apisix-seed.git
cd apisix-seed
go build
apisix-seed
configuration file, config path conf/conf.yaml
.etcd: # APISIX ETCD Configure
host:
- "http://127.0.0.1:2379"
prefix: /apisix
timeout: 30
discovery:
zookeeper: # Zookeeper Service Discovery
hosts:
- "127.0.0.1:2181" # Zookeeper service address
prefix: /zookeeper
weight: 100 # default weight for node
timeout: 10 # default 10s
apisix-seed
to monitor service changes./apisix-seed
APISIX
Route and UpstreamSet a route, the request path is /zk/*
, the upstream uses zookeeper as service discovery, and the service name
is APISIX-ZK
.
curl http://127.0.0.1:9080/apisix/admin/routes/1 \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"uri": "/zk/*",
"upstream": {
"service_name": "APISIX-ZK",
"type": "roundrobin",
"discovery_type": "zookeeper"
}
}'
# Login Container
docker exec -it ${CONTAINERID} /bin/bash
# Login Zookeeper Client
oot@ae2f093337c1:/apache-zookeeper-3.7.0-bin# ./bin/zkCli.sh
# Register Service
[zk: localhost:2181(CONNECTED) 0] create /zookeeper/APISIX-ZK '{"host":"127.0.0.1:1980","weight":100}'
Created /zookeeper/APISIX-ZK
curl -i http://127.0.0.1:9080/zk/hello
HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: text/html; charset=utf-8
Date: Tue, 29 Mar 2022 08:51:28 GMT
Server: APISIX/2.12.0
Transfer-Encoding: chunked
hello
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。