API网关Kong
各种方式安装汇总:https://konghq.com/install/
命令列表:https://docs.konghq.com/0.14.x/admin-api/
官方插件列表:https://docs.konghq.com/hub/
相关学习笔记链接:https://www.lijiaocn.com/%E9%A1%B9%E7%9B%AE/2018/09/29/nginx-openresty-kong.html
相关博客:https://www.itcodemonkey.com/article/5980.html
Kong集群搭建博客:https://www.cnblogs.com/zhoujie/p/kong6.html
github:https://github.com/Kong
可视化程序dashboard github:https://github.com/PGBI/kong-dashboard
缓存插件github:https://github.com/globocom/kong-plugin-proxy-cache
kong配置文件默认地址:/etc/kong/kong.conf
kong插件默认地址:/usr/local/share/lua/5.1/kong/plugins
添加新插件时安装后需要在kong.conf中配置引入,proxy-cache插件安装前需要 luarocks install lua-resty-redis-connector
构建包含响应缓存插件的docker包:
Dockerfile:
From kong:latest RUN apk update RUN apk add git RUN luarocks install lua-resty-redis-connector RUN luarocks install kong-plugin-proxy-cache RUN cp /etc/kong/kong.conf.default /etc/kong/kong.conf RUN echo "plugins = bundled, proxy-cache" >> /etc/kong/kong.conf EXPOSE 8000 8001 8443 8444
docker build -t custom-kong .
导出image:
docker save > kong.tar custom-kong:latest
导入image:
docker load < kong.tar
Kong集群(完全无状态):
主节点启动(与数据库在一个docker network):
docker run -d --name kong \ --network=kong-net \ -e "KONG_DATABASE=postgres" \ -e "KONG_PG_HOST=kong-database" \ -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \ -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \ -e "KONG_PROXY_ERROR_LOG=/dev/stderr" \ -e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \ -e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \ -p 8000:8000 \ -p 8443:8443 \ -p 8001:8001 \ -p 8444:8444 \ custom-kong:latest
其他节点:
docker run -d --name kong \ -e "KONG_DATABASE=postgres" \ -e "KONG_PG_HOST=10.95.55.185" \ -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \ -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \ -e "KONG_PROXY_ERROR_LOG=/dev/stderr" \ -e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \ -e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \ -p 8002:8000 \ -p 8443:8443 \ -p 8001:8001 \ -p 8444:8444 \ custom-kong:latest
Kong集群前负载均衡nginx配置:
配置文件地址:/etc/nginx/nginx.conf
# include /... upstream kongs { server xx:xx:xx:xx:xx weight=10; server xx:xx:xx:xx:xx weight=10; }
# 修改http的请求头为源请求头
proxy_set_header Host $http_host;
proxy_set_header X-Forward-For $remote_addr;
# 修改hearder支持加"_"
underscores_in_headers on;
server { listen 80; server_name kongs; location / { proxy_pass http://kongs; } }