Skip to content

🔥micro_gateway is a micro-service gateway developed based on Vue and Golang. The system supports multiple proxy protocols (such as HTTP, TCP and gRPC) and multiple load balancing algorithms.

License

Notifications You must be signed in to change notification settings

hugokung/micro_gateway

Repository files navigation

Github Repo Stars License Issue Verison Build Commit

Micro Gateway

🧱一个高性能微服务网关

Micro Gateway 管理后台Demo

demo1 demo2 demo3

功能

功能脑图

技术栈

后端

  • Golang
  • Gin
  • Gorm
  • Redis
  • MySql
  • Swagger
  • Docker
  • K8s

前端

  • Vue.js
  • Vue-element-admin

特性

代理协议

  • Http/Https
  • Tcp
  • Grpc
  • WebSocket

代理功能

  • 流量统计
  • 流量限制
  • 熔断
  • 黑白名单
  • 错误重试(Http/Https)

服务发现

  • 静态配置
  • ETCD
  • Zookeeper
  • Nacos

插件

  • 用户自定义插件

灰度发布

  • 按权重分流

性能监测

  • pprof
  • Prometheus

部署方式

  • 单机部署
  • Docker
  • K8s
  • DockerCompose

环境依赖

  • Golang版本要求Golang1.12+
  • 下载类库依赖
export GO111MODULE=on && export GOPROXY=https://goproxy.cn
cd micro_gateway
go mod tidy
  • 创建数据库并导入
mysql -h localhost -u root -p -e "CREATE DATABASE micro_gateway DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
mysql -h localhost -u root -p micro_gateway < gateway.sql --default-character-set=utf8

前端部署

控制面板前端与后端服务分开部署时,前端项目需要如下设置:

  • vue.config.js文件中设置publicPath/
  • .env.production文件中设置VUE_APP_BASE_API为自己需要的url前缀,本项目设置为/prod-api
  • 编译。
npm run build:prod
  • 通过nginx代理实现与后端接口服务的同域访问。
 server {
      listen       8884;
      server_name  localhost;
      root /dashboard编译生成的结果的路径;
      index  index.html index.htm index.php;

      location / {
          try_files $uri $uri/ /index.html?$args;
      }

      location /prod-api/ {
          proxy_pass http://127.0.0.1:8880/; #后端服务接口
      }
}
  • 访问http://你的ip:8884即可。

控制面板前端与后端项目合并部署

  • vue.config.js文件中设置publicPath/dist
  • .env.production文件中设置VUE_APP_BASE_API为空。
  • 在后端项目的router包的route.go文件中增加代码
router.Static("/dist", "./dist")
  • 编译后放入到后端项目的根目录下。
  • 访问http://后端IP:后端port/dist

后端部署

直接编译源码运行

make build_dev
sh run.sh

使用Docker部署

  • 部署网关管理服务
docker build -f dockerfile-dashboard -t gateway-dashboard .
docker run --name dashboard --net host -e TZ=Asia/Shanghai -d gateway-dashboard:latest
  • 部署代理服务
docker build -f dockerfile-server -t gateway-server .
docker run --name server --net host -e TZ=Asia/Shanghai -d gateway-server:latest
  • 需要再额外自己部署Redis和Mysql服务器。

使用K8s部署

kubectl apply -f k8s_gateway_mysql.yaml
kubectl apply -f k8s_gateway_redis.yaml
kubectl apply -f k8s_dashboard.yaml
kubectl apply -f k8s_server.yaml

测试

  • example目录为模拟下游服务节点的代码。

代理规则

  • HTTP/HTTPS代理:通过HttpRule.Rule字段以前缀匹配的形式实现不同下游服务的转发
  • TCP代理:通过TcpRule.Port字段实现不同tcp服务的转发
  • GRPC代理:通过GrpcRule.Port字段实现不同GRPC服务的转发

💻API文档

生成接口文档:swag init
然后启动服务器:go run main.go,浏览地址: http://127.0.0.1:8880/swagger/index.html

About

🔥micro_gateway is a micro-service gateway developed based on Vue and Golang. The system supports multiple proxy protocols (such as HTTP, TCP and gRPC) and multiple load balancing algorithms.

Topics

Resources

License

Stars

Watchers

Forks