With the rise of micro-services industry there has been a lot of excellent micro-services gateway framework, teach you to build a set of people with a micro-services gateway framework Golang write today.
Here long-winded one, there are people today probably do not understand what is micro service, why use micro-services. At present the Internet is relatively vague, there is no precise definition, but we have similar meaning, personal popular here described, is a small to large development projects during the project, due to have been maintained, with the stability and the like, the whole project is divided into a a plurality of minute service.
The role of micro-services gateway is the first user in a gateway server, you follow the needs of business-related services, the gateway to the shunt, compared to cloud hosting vendors to provide load balancing, a powerful diversion that you can go according to their business, but also to be to achieve authentication, verification, polymerization custom caching service, and the cloud host simply a load balancer according to traffic load balancing request you do not have properties of custom programming.
Then teach how to install, and precautions.
address:
https://github.com/fagongzi/gateway
Features:
- flow control
- Fuse
- Load Balancing
- Service Discovery
- Plug-in mechanism
- Routing (shunt, replication traffic)
- API aggregation
- API parameters check
- API access control (black list)
- API default return value
- Custom API return value
- Cache API results
- JWT Authorization
- API Metric Import Prometheus
- API failure retry
- The back-end server health check
- Open Management API (GRPC, Restful)
- Support websocket
- Support online migration of data
1. Download
2. Compile
cd $GOPATH/src/github.com/fagongzi/gateway/cmd/proxy go build -o proxy ./... cd $GOPATH/src/github.com/fagongzi/gateway/cmd/api go build -o apiserver ./...
3.ECTD installation
Etcd is a highly available Key / Value storage systems, mainly for sharing configuration and service discovery.
etcd github Address:
https://github.com/etcd-io/etcd
Of course, you can also install from the command line
1, the installation
yum install etcd
2, modify the configuration file, mainly to address, if not very good, you can look etcd official documents
vim /etc/etcd/etcd.conf # [member] ETCD_NAME="k8s_master_ip_name" #范例: etcd1 ETCD_DATA_DIR="/work/etcd" ETCD_LISTEN_PEER_URLS="http://k8s_master_ip:2380" ETCD_LISTEN_CLIENT_URLS="http://127.0.0.1:2379,http://k8s_master_ip:2379"
3, start
systemctl daemon-reload
systemctl enable etcd.service
systemctl start etcd.service
4, the test
IP and port to configure the ip address, if not used, it is recommended not to arbitrarily change the port
curl http://127.0.0.1:2379/version
If the return { "etcdserver": "3.3.2", "etcdcluster": "3.3.0"} is installed successfully
Basic software are installed, we are ready lowest three machines.
Operating Environment
We have three etcd, a ApiServer, three Proxy setting an example
Environmental Information
Package | surroundings | Explanation |
---|---|---|
etcd cluster environment | 192.168.1.12 | Server Configuration |
Proxy | 192.168.1.13 | Proxy Server |
ApiServer | 192.168.1.14 | Routing configuration interface server |
1. Start ApiServer Service
Start ApiServer service, see the following screenshot on the right.
2. Start agency services
See the following screenshot on the right
3. Add Configuration
After the services start, we add routing configuration.
Start Proxy
./proxy --addr=192.168.1.200:80 --addr-rpc=192.168.1.200:9091 --addr-store=etcd://192.168.1.100:2379,192.168.1.101:2379,192.168.1.102:2379 --namespace=test ./proxy --addr=192.168.1.201:80 --addr-rpc=192.168.1.201:9091 --addr-store=etcd://192.168.1.100:2379,192.168.1.101:2379,192.168.1.102:2379 --namespace=test ./proxy --addr=192.168.1.202:80 --addr-rpc=192.168.1.202:9091 --addr-store=etcd://192.168.1.100:2379,192.168.1.101:2379,192.168.1.102:2379 --namespace=test
用户的API接入地址可以为:192.168.1.201:80、192.168.1.201:80、192.168.1.202:80其中任意一个
如果能访问下你后面代理的接口内容,表示成功。
如果觉得配置服务器API,命令行麻烦,可以下载WEB UI的管理控制台。
下载地址: