一:kong的簡介
1.Kong是一款基於OpenResty(Nginx + Lua模塊)編寫的高可用、易擴展的,由Mashape公司開源的API Gateway項目。Kong是基於NGINX和Apache Cassandra或PostgreSQL構建的,能提供易於使用的RESTful API來操作和配置API管理系統,所以它可以水平擴展多個Kong服務器,通過前置的負載均衡配置把請求均 勻地分發到各個Server,來應對大批量的網絡請求

upstream helloUpstream {
server localhost:3000 weighi(權重)=100;
}
server {
listen 80;
location /hello {
proxy_pass http://helloUpstream;
}
}
1.配置upstream
# curl -X POST http://localhost:8001/upstreams --data "name=helloUpstream"
2.配置target
# curl -X POST http://localhost:8001/upstreams/helloUpstream/targets --data "target=localhost:3000" --data "weight=100"
3.配置service
# curl -X POST http://localhost:8001/services --data "name=hello" --data "host=helloUpstream"
4.配置route
# curl -X POST http://localhost:8001/routes --data "paths[]=/hello" --data "service.id=(輸入上次執行之后回饋的id號)"

> --network=kong-net \
> -p 5432:5432 \
> -e "POSTGRES_USER=kong" \
> -e "POSTGRES_DB=kong" \
> -e "POSTGRES_PASSWORD=kong" \
> --restart always \
> postgres:9.6

(3)使用臨時Kong容器運行進行數據庫初始化
[root@localhost ~]# docker run --rm \
> --network=kong-net \
> -e "KONG_DATABASE=postgres" \
> -e "KONG_PG_HOST=kong-database" \
> -e "KONG_PG_USER=kong" \
> -e "KONG_PG_PASSWORD=kong" \
> -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
> kong:latest kong migrations bootstrap
(4)啟動Kong
[root@localhost ~]# docker run -d --name kong \
> --network=kong-net \
> -e "KONG_DATABASE=postgres" \
> -e "KONG_PG_HOST=kong-database" \
> -e "KONG_PG_USER=kong" \
> -e "KONG_PG_PASSWORD=kong" \
> -e "KONG_CASSANDRA_CONTACT_POINTS=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 \
> --restart always \
> kong:latest
然后在瀏覽器上訪問http://IP:8001 或者在命令行輸入curl http://IP:8001
在瀏覽器上顯示
接下來就是安裝界面
konga的安裝
(1)初始化Konga 數據庫
命令:[root@localhost ~]# docker run --rm --network=kong-net pantsel/konga:latest -c prepare -a postgres -u postgresql://kong:kong@kong-database:5432/konga_db
(2)運行Konga
[root@localhost ~]# docker run -p 1337:1337 \
> --network=kong-net \
> -e "KONG_DATABASE=postgres" \
> -e "KONG_PG_HOST=kong-database" \
> -e "KONG_PG_USER=kong" \
> -e "KONG_PG_PASSWORD=kong" \
> -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
> -e "DB_DATABASE=konga_db" \
> -e "KONGA_HOOK_TIMEOUT=120000" \
> --name konga \
> pantsel/konga
然后再瀏覽器上訪問http://192.168.20.100:1337
自此就部署完畢了