同步操作将从 fagongzi/gateway 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
If you have not dealt much with HTTP gateway before and want to deploy one in your company or just play with one, then congradulations, you have come to the right place!
This tutorial is very user-friendly. It aims to assist first-timers to have a hands-on experience without going through the pain of searching, asking and wondering.
This was tested on a MacOS environment.
If you encounter any problem going through the tutorial, feel free to create an issue or send me an email to this address brucewangno1@qq.com with the subject "Issues with Gateway Tutorial."
ETCD is a distributed key-value storage required to store Gateway configurations.
You need an ETCD server or a cluster of them running.
Follow the directions on this page.
Under $GOPATH/src/github.com/fagongzi, run
git clone https://github.com/fagongzi/gateway.git
Make sure your Go version is 1.10 or above. Otherwise error will occurs. In the root directory of this project, there is a Makefile which is responsible to generate the executables and the static Web UI. Under the root directory of this project, run
make
to generate executables apiserver and proxy , found under directory dist; run
make ui
to generate the UI directory under dist, which is the Web UI needed by apiserver.
So now there is a ETCD or a cluster of ETCD Docker containers running.
Under directory dist, run the following two command lines in two separate terminal tabs in a termial (iTerm highly recommended)
sudo ./proxy --addr=127.0.0.1:80 --addr-rpc=127.0.0.1:9091 --addr-store=etcd://127.0.0.1:2379 --namespace=test
./apiserver --addr=127.0.0.1:9091 --addr-store=etcd://127.0.0.1:2379 --discovery --namespace=test -ui=ui/dist
to start proxy and apiserver.
Under the directory cmd/backend, there is the file backend.go. This is a backend mock service. It have many simple APIs like the one returning the hostname, ip and port of the server.
Start up 3 terminal tabs and run the following commands in these 3 tabs, respectively.
go run backend.go --addr=localhost:9000
go run backend.go --addr=localhost:9001
go run backend.go --addr=localhost:9002
Alright, alright, alright. You now have three servers which provide the same service and will later form a cluster by configurations on the Web UI.
There are two ways to configure Gateway which is responsible for stuff like redirecting traffic. The first one is through Web UI and the second is through GRPC.
Web UI is at http://localhost:9093/ui/index.html#/home. Please do not try to access http://localhost:9093. Instead of the Web UI showing up, you get
{"message":"Not Found"}
A rookie mistake. In the future, this issue might be resolved.
The configuration is all set up.
Click on the link to open the download page.
Remember to add the Host field in Headers. Otherwise it will not work.
And voila! You have something like
Johns-MacBook-Pro.local
localhost:9002
Notice that almost every time you click on Send, server address changes. This is because of the Round Robin load balance strategy.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。