一、简介
Gateway 是一个基于HTTP协议的restful的API网关。主要作用:流量控制、熔断、负载均衡、服务发现、插件机制、基于URL 的路由、API聚合、API参数校验、API访问控制、API Mock、后端server的健康检查、使用fasthttp、后台管理UI。
二、Github地址:https://github.com/fagongzi/gateway
三、安装步骤
1.系统配置
- [root@localhost ~]# yum -y update
2.安装etcd
- [root@localhost ~]# yum search etcd
- [root@localhost ~]# yum install etcd
3. 源码安装go语言1.8
http://blog.youkuaiyun.com/xiaofei15135161280/article/details/70256484
4. 安装docker
Docker 软件包已经包括在默认的 CentOS-Extras 软件源里。因此想要安装 docker,只需要运行下面的 yum 命令:
- [root@localhost ~]# yum install docker
启动 Docker 服务
安装完成后,使用下面的命令来启动 docker 服务,并将其设置为开机启动:
- [root@localhost ~]# service docker start
- [root@localhost ~]# chkconfig docker on
源码包下载地址:https://github.com/fagongzi/gateway
下载完解压到src目录下的 github.com/fagongzi/目录下,并且将包名gateway-master改成 gateway 如下图:
为什么要这么修改路径?因为下载的源码里,在执行的文件里会有引用地址,
在红框里的代码是引用地址,可以看到第一条的路径中需要引入CodisLabs包中的文件,所以还需要下载Codislabs
下载地址:https://github.com/CodisLabs/codis
下载完后将codis/pkg目录移到github.com/CodisLabs/codis目录下
最后的目录应该是:
6. 编译运行源码文件
运行admin
- [root@localhost admin]# go build admin.go
- [root@localhost admin]# ./admin --addr=:8080 --etcd-addr=http://127.0.0.1:2379
启动后,Admin监听8080端口,你可以再浏览器上访问http://127.0.0.1:8080
,默认的用户名和密码是admin/admin
运行proxy
- [root@localhost admin]# go build admin.go
- [root@localhost admin]# ./admin --addr=:8080 --etcd-addr=http://127.0.0.1:2379