Kong Api网关简介(一) 安装运行

Kong 是 Mashape 开源的高性能高可用 API 网关和 API 管理服务层。它基于 OpenResty 进行 API 管理,并提供了插件实现 API 的 AOP。最近因工作的需要研究了 Kong 的相关应用实现。

由于本机的8001端口被占 所以8001被替换为8003

一.准备

  kong 的官方文档提供了基于不同平台的安装方式,为了方便,这里使用 docker-compose 进行。

[root@xxbnz ~]# cd /home/src/

[root@xxbnz src]# ll

total 4

drwxr-xr-x 8 root root 4096 Sep 17 10:09 dnmp

[root@xxbnz src]# mkdir kong-gateway && cd kong-gateway

[root@xxbnz kong-gateway]# ll

total 0

[root@xxbnz kong-gateway]# touch docker-compose.yml

[root@xxbnz kong-gateway]# mkdir config plugins postgresql

[root@xxbnz php72]# cd ../../../kong-gateway/

[root@xxbnz kong-gateway]# ll


total 16

drwxr-xr-x 2 root root 4096 Sep 21 18:26 config

-rw-r--r-- 1 root root  966 Sep 21 18:28 docker-compose.yml

drwxr-xr-x 2 root root 4096 Sep 21 18:26 plugins

drwxr-xr-x 2 root root 4096 Sep 21 18:26 postgresql

上述创建名为 kong-gateway 的目录并且进入,然后在 kong-gateway 目录中创建 docker-compose.yml 文件,并且创建了 config、 plugins、 postgresql 三个文件夹。其中, config 文件夹用于存放 kong 网关配置, plugins 文件夹用于存放自定义插件, postgresql 文件夹用于存放 postgresql 数据文件,这三个文件夹将被挂载到 docker 容器中。 docker-compose.yml 文件定义如下:

            version: '3'

services:

  postgres:

image: postgres:9.6

ports:

  - "5432:5432"

environment:

  - POSTGRES_USER=kong

  - POSTGRES_DB=kong

  - POSTGRES_PASSWORD=kong

  - PGDATA=/var/lib/postgresql/data

container_name: kong-database

volumes:

  - ./postgresql/data:/var/lib/postgresql/data

  kong:

image: kong:latest

container_name: kong

environment:

  - KONG_DATABASE=postgres

  - KONG_PG_HOST=kong-database

  - KONG_PG_USER=kong

  - KONG_PG_PASSWORD=kong

  - KONG_CASSANDRA_CONTACT_POINTS=kong-database

  - KONG_PROXY_ACCESS_LOG=/dev/stdout

  - KONG_ADMIN_ACCESS_LOG=/dev/stdout

  - KONG_PROXY_ERROR_LOG=/dev/stderr

  - KONG_ADMIN_ERROR_LOG=/dev/stderr

ports:

  - "8000:8000"

  - "8003:8003"  //8001:8001 被占用 改用8003

  - "8443:8443"

  - "7946:7946"

  - "7946:7946/udp"

volumes:

  - ./config:/etc/kong

  - ./plugins:/etc/kong/plugins

depends_on:

  - postgres

config 文件夹下放置 kong 的配置文件 kong.conf,简单定义如下:

        prefix = /etc/kong/

log_level = debug

proxy_listen = 0.0.0.0:8000, 0.0.0.0:8443 ssl

admin_listen = 0.0.0.0:8003, 0.0.0.0:8444 ssl

database = postgres

pg_host = 127.0.0.1

pg_port = 5432

pg_user = kong

pg_password = kong

pg_database = kong

pg_ssl = off

pg_ssl_verify = off

    上述准备好后的 kong-gateway文件夹目录如下:

    [root@xxbnz kong-gateway]# tree


├── config

│   └── kong.conf

├── docker-compose.yml

├── plugins

└── postgresql

3 directories, 2 files

二.启动

      首先准备数据库,执行下面命令:

[root@xxbnz kong-gateway]# docker-compose run kong kong migrations up


Creating network "konggateway_default" with the default driver

Pulling postgres (postgres:9.6)...

9.6: Pulling from library/postgres

802b00ed6f79: Already exists

4e0de21e2180: Pull complete

58b06ac4cd84: Pull complete

14e76b354b47: Pull complete

0f0c9f244b65: Pull complete

37117d8abb6d: Pull complete

8b541f5d818a: Pull complete

7cb4855fcd96: Pull complete

02dac872bc79: Pull complete

260defa8ced6: Pull complete

8d6200d741e7: Pull complete

252375ab8537: Pull complete

56e2f1d2303b: Pull complete

6eb2ae61937d: Pull complete

Digest: sha256:608ce712224026e9c5692a48130635166f710ff6a581542c3dd4d0da767e2a47

Status: Downloaded newer image for postgres:9.6

Creating kong-database ...

Creating kong-database ... done

Pulling kong (kong:latest)...

latest: Pulling from library/kong

3489d1c4660e: Pull complete

97eb239b37ff: Pull complete

136565b6d830: Pull complete

Digest: sha256:eb294641b50cf7aaf97aa65598f6e9483624d621588517f9561e7bec921221e9

Status: Downloaded newer image for kong:latest

migrating core for database kong

core migrated up to: 2015-01-12-175310_skeleton

core migrated up to: 2015-01-12-175310_init_schema

core migrated up to: 2015-11-23-817313_nodes

core migrated up to: 2016-02-29-142793_ttls

core migrated up to: 2016-09-05-212515_retries

core migrated up to: 2016-09-16-141423_upstreams

core migrated up to: 2016-12-14-172100_move_ssl_certs_to_core

core migrated up to: 2016-11-11-151900_new_apis_router_1

core migrated up to: 2016-11-11-151900_new_apis_router_2

core migrated up to: 2016-11-11-151900_new_apis_router_3

core migrated up to: 2016-01-25-103600_unique_custom_id

core migrated up to: 2017-01-24-132600_upstream_timeouts

core migrated up to: 2017-01-24-132600_upstream_timeouts_2

core migrated up to: 2017-03-27-132300_anonymous

core migrated up to: 2017-04-18-153000_unique_plugins_id

core migrated up to: 2017-04-18-153000_unique_plugins_id_2

core migrated up to: 2017-05-19-180200_cluster_events

core migrated up to: 2017-05-19-173100_remove_nodes_table

core migrated up to: 2017-06-16-283123_ttl_indexes

core migrated up to: 2017-07-28-225000_balancer_orderlist_remove

core migrated up to: 2017-10-02-173400_apis_created_at_ms_precision

core migrated up to: 2017-11-07-192000_upstream_healthchecks

core migrated up to: 2017-10-27-134100_consistent_hashing_1

core migrated up to: 2017-11-07-192100_upstream_healthchecks_2

core migrated up to: 2017-10-27-134100_consistent_hashing_2

core migrated up to: 2017-09-14-121200_routes_and_services

core migrated up to: 2017-10-25-180700_plugins_routes_and_services

core migrated up to: 2018-03-27-123400_prepare_certs_and_snis

core migrated up to: 2018-03-27-125400_fill_in_snis_ids

core migrated up to: 2018-03-27-130400_make_ids_primary_keys_in_snis

core migrated up to: 2018-05-17-173100_hash_on_cookie

migrating response-transformer for database kong

response-transformer migrated up to: 2016-05-04-160000_resp_trans_schema_changes

migrating ip-restriction for database kong

ip-restriction migrated up to: 2016-05-24-remove-cache

migrating statsd for database kong

statsd migrated up to: 2017-06-09-160000_statsd_schema_changes

migrating jwt for database kong

jwt migrated up to: 2015-06-09-jwt-auth

jwt migrated up to: 2016-03-07-jwt-alg

jwt migrated up to: 2017-05-22-jwt_secret_not_unique

jwt migrated up to: 2017-07-31-120200_jwt-auth_preflight_default

jwt migrated up to: 2017-10-25-211200_jwt_cookie_names_default

jwt migrated up to: 2018-03-15-150000_jwt_maximum_expiration

migrating cors for database kong

cors migrated up to: 2017-03-14_multiple_orgins

migrating basic-auth for database kong

basic-auth migrated up to: 2015-08-03-132400_init_basicauth

basic-auth migrated up to: 2017-01-25-180400_unique_username

migrating key-auth for database kong

key-auth migrated up to: 2015-07-31-172400_init_keyauth

key-auth migrated up to: 2017-07-31-120200_key-auth_preflight_default

migrating ldap-auth for database kong

ldap-auth migrated up to: 2017-10-23-150900_header_type_default

migrating hmac-auth for database kong

hmac-auth migrated up to: 2015-09-16-132400_init_hmacauth

hmac-auth migrated up to: 2017-06-21-132400_init_hmacauth

migrating datadog for database kong

datadog migrated up to: 2017-06-09-160000_datadog_schema_changes

migrating tcp-log for database kong

tcp-log migrated up to: 2017-12-13-120000_tcp-log_tls

migrating acl for database kong

acl migrated up to: 2015-08-25-841841_init_acl

migrating response-ratelimiting for database kong

response-ratelimiting migrated up to: 2015-08-03-132400_init_response_ratelimiting

response-ratelimiting migrated up to: 2016-08-04-321512_response-rate-limiting_policies

response-ratelimiting migrated up to: 2017-12-19-120000_add_route_and_service_id_to_response_ratelimiting

migrating request-transformer for database kong

request-transformer migrated up to: 2016-05-04-160000_req_trans_schema_changes

migrating rate-limiting for database kong

rate-limiting migrated up to: 2015-08-03-132400_init_ratelimiting

rate-limiting migrated up to: 2016-07-25-471385_ratelimiting_policies

rate-limiting migrated up to: 2017-11-30-120000_add_route_and_service_id

migrating oauth2 for database kong

oauth2 migrated up to: 2015-08-03-132400_init_oauth2

oauth2 migrated up to: 2016-07-15-oauth2_code_credential_id

oauth2 migrated up to: 2016-12-22-283949_serialize_redirect_uri

oauth2 migrated up to: 2016-09-19-oauth2_api_id

oauth2 migrated up to: 2016-12-15-set_global_credentials

oauth2 migrated up to: 2017-04-24-oauth2_client_secret_not_unique

oauth2 migrated up to: 2017-10-19-set_auth_header_name_default

oauth2 migrated up to: 2017-10-11-oauth2_new_refresh_token_ttl_config_value

oauth2 migrated up to: 2018-01-09-oauth2_pg_add_service_id

67 migrations ran

    执行过程中将拉取 docker-compose.yml 中定义的 postgres:9.6 镜像和 kong:latest镜像,并执行数据库迁移操作。

    迁移完成后,执行下面命令,启动 kong 网关:

[root@xxbnz kong-gateway]# docker-compose up --no-recreate -d


Starting kong-database ... done

Creating kong ...

Creating kong ... done

[root@xxbnz kong-gateway]# docker-compose ps


Name                  Command              State                                              Ports                                         

----------------------------------------------------------------------------------------------------------------------------------------------------

kong            /docker-entrypoint.sh kong ...  Up      0.0.0.0:7946->7946/tcp, 0.0.0.0:7946->7946/udp, 0.0.0.0:8000->8000/tcp, 8001/tcp,         

0.0.0.0:8003->8003/tcp, 0.0.0.0:8443->8443/tcp, 8444/tcp                                 

kong-database  docker-entrypoint.sh postgres    Up      0.0.0.0:5432->5432/tcp   

    通过docker ps查看是否已经安装成功

[root@xxbnz kong-gateway]# docker ps


CONTAINER ID        IMAGE                                COMMAND                  CREATED            STATUS              PORTS                                                                                                                                        NAMES

58bee35c5789        kong:latest                          "/docker-entrypoint.…"  45 seconds ago      Up 44 seconds      0.0.0.0:7946->7946/tcp, 0.0.0.0:8000->8000/tcp, 0.0.0.0:8003->8003/tcp, 8001/tcp, 0.0.0.0:8443->8443/tcp, 0.0.0.0:7946->7946/udp, 8444/tcp  kong

6f3d818e4d1b        postgres:9.6                          "docker-entrypoint.s…"  3 minutes ago      Up 3 minutes 

    注: 各端口映射关系及作用

端口 作用

8000 监听http请求

8443 监听https请求

8003 admin api配置http端口

8444 admin api配置https端口

        5432    postgresql端口

7946    监听udp请求 貌似没啥用 还未研究

查看网路端口使用情况:

[root@xxbnz kong-gateway]# netstat -ntlp


Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address          Foreign Address        State      PID/Program name   

tcp        0      0 0.0.0.0:22              0.0.0.0:*              LISTEN      1335/sshd         

tcp        0      0 127.0.0.1:32000        0.0.0.0:*              LISTEN      1113/java         

tcp6      0      0 :::6379                :::*                    LISTEN      1979/docker-proxy 

tcp6      0      0 :::80                  :::*                    LISTEN      4840/docker-proxy 

tcp6      0      0 :::8080                :::*                    LISTEN      1953/docker-proxy 

tcp6      0      0 :::8081                :::*                    LISTEN      2384/docker-proxy 

tcp6      0      0 :::5432                :::*                    LISTEN      12436/docker-proxy 

tcp6      0      0 :::8443                :::*                    LISTEN      13161/docker-proxy 

tcp6      0      0 :::443                  :::*                    LISTEN      4814/docker-proxy 

tcp6      0      0 :::8000                :::*                    LISTEN      13218/docker-proxy 

tcp6      0      0 :::8001                :::*                    LISTEN      31964/docker-proxy 

tcp6      0      0 :::8002                :::*                    LISTEN      1189/docker-proxy 

tcp6      0      0 :::8003                :::*                    LISTEN      13189/docker-proxy 

tcp6      0      0 :::7946                :::*                    LISTEN      13230/docker-proxy 

tcp6      0      0 :::3306                :::*                    LISTEN      2378/docker-proxy

这时候控制台执行 curl http://127.0.0.1:8003/status可以看到管理端口输出的状态json。

[root@xxbnz kong-gateway]# curl http://127.0.0.1:8003/status


{"database":{"reachable":true},"server":{"connections_writing":1,"total_requests":1,"connections_handled":1,"connections_accepted":1,"connections_reading":0,"connections_active":1,"connections_waiting":0}}

三.运行

1.Service Object

Kong 中的 Service 对象代表了上游服务的一个抽象,主要由协议、主机名、端口、路径等组成。Service 和路由关联(一个Service可能会被关联至多个路由)。更多参见Kong Admin Api Service Object。

我们首先执行命令创建一个 Service, 这个 Service 名称为 baidu-service,对应的 url 地址为 https://juejin.im/post/5ba97ff95188255c9e02d3e3:

[root@xxbnz ~]# curl -i -X POST \

  >        --url http://127.0.0.1:8001/services/ \

  >        --data 'name=juejin-service' \

  >        --data 'url=https://juejin.im/post/5ba97ff95188255c9e02d3e3'


  响应:

HTTP/1.1 201 Created

Date: Tue, 25 Sep 2018 08:20:13 GMT

Content-Type: application/json; charset=utf-8

Connection: keep-alive

Access-Control-Allow-Origin: *

Server: kong/0.14.1

Content-Length: 307

{"host":"juejin.im","created_at":1537863613,"connect_timeout":60000,"id":"b7e8bfda-c659-41de-9392-2b03886cb887","protocol":"http","name":"juejin-service","read_timeout":60000,"port":80,"path":"\/post\/5ba97ff95188255c9e02d3e3","updated_at":1537863613,"retries":5,"write_timeout":60000}

    可以通过以下命令查看所有已创建的 Service:

[root@xxbnz ~]# curl -i -X GET --url http://127.0.0.1:8003/services/


  响应:

HTTP/1.1 200 OK

Date: Tue, 25 Sep 2018 08:21:09 GMT

Content-Type: application/json; charset=utf-8

Connection: keep-alive

Access-Control-Allow-Origin: *

Server: kong/0.14.1

Content-Length: 330

{"next":null,"data":[{"host":"juejin.im","created_at":1537863613,"connect_timeout":60000,"id":"b7e8bfda-c659-41de-9392-2b03886cb887","protocol":"http","name":"juejin-service","read_timeout":60000,"port":80,"path":"\/post\/5ba97ff95188255c9e02d3e3","updated_at":1537863613,"retries":5,"write_timeout":60000}]}

也可以根据 serviceId 查看某个具体的 Service:

[root@xxbnz ~]# curl -i -X GET --url http://127.0.0.1:8003/services/b7e8bfda-c659-41de-9392-2b03886cb887


  响应:

HTTP/1.1 200 OK

Date: Tue, 25 Sep 2018 08:50:07 GMT

Content-Type: application/json; charset=utf-8

Connection: keep-alive

Access-Control-Allow-Origin: *

Server: kong/0.14.1

Content-Length: 307

{"host":"juejin.im","created_at":1537863613,"connect_timeout":60000,"id":"b7e8bfda-c659-41de-9392-2b03886cb887","protocol":"http","name":"juejin-service","read_timeout":60000,"port":80,"path":"\/post\/5ba97ff95188255c9e02d3e3","updated_at":1537863613,"retries":5,"write_timeout":60000}


    2.Route Object

路由定义了匹配客户端请求的规则,每一个路由关联一个 Service,每一个 Service 有可能被多个路由关联,每一个匹配到指定的路由请求将被代理到它关联的 Service 上。 更多参见Kong Admin Api Route Object。[https://docs.konghq.com/0.14.x/admin-api/#route-object]

    首先创建一个Route:

[root@xxbnz ~]# curl -i -X POST \

>        --url http://localhost:8003/services/juejin-service/routes \

>        --data 'hosts[]=juejin.im'


  响应:

HTTP/1.1 201 Created

Date: Tue, 25 Sep 2018 08:58:39 GMT

Content-Type: application/json; charset=utf-8

Connection: keep-alive

Access-Control-Allow-Origin: *

Server: kong/0.14.1

Content-Length: 306

{"created_at":1537865919,"strip_path":true,"hosts":["juejin.im"],"preserve_host":false,"regex_priority":0,"updated_at":1537865919,"paths":null,"service":{"id":"b7e8bfda-c659-41de-9392-2b03886cb887"},"methods":null,"protocols":["http","https"],"id":"00456c6b-81d0-4846-ba8c-82a02cded5c0"}

可以通过以下命令查看所有已创建的 Routes:

[root@xxbnz ~]# curl -i -X GET --url http://127.0.0.1:8003/routes


   响应:

HTTP/1.1 200 OK

Date: Tue, 25 Sep 2018 09:01:08 GMT

Content-Type: application/json; charset=utf-8

Connection: keep-alive

Access-Control-Allow-Origin: *

Server: kong/0.14.1

Content-Length: 329

{"next":null,"data":[{"created_at":1537865919,"strip_path":true,"hosts":["juejin.im"],"preserve_host":false,"regex_priority":0,"updated_at":1537865919,"paths":null,"service":{"id":"b7e8bfda-c659-41de-9392-2b03886cb887"},"methods":null,"protocols":["http","https"],"id":"00456c6b-81d0-4846-ba8c-82a02cded5c0"}]}

也可以根据 routeId 查看某个具体的 Route:

    [root@xxbnz ~]# curl -i -X GET --url http://127.0.0.1:8003/routes/00456c6b-81d0-4846-ba8c-82a02cded5c0


  响应:

HTTP/1.1 200 OK

Date: Tue, 25 Sep 2018 09:02:40 GMT

Content-Type: application/json; charset=utf-8

Connection: keep-alive

Access-Control-Allow-Origin: *

Server: kong/0.14.1

Content-Length: 278

{"created_at":1537865919,"strip_path":true,"hosts":["juejin.im"],"preserve_host":false,"regex_priority":0,"updated_at":1537865919,"service":{"id":"b7e8bfda-c659-41de-9392-2b03886cb887"},"protocols":["http","https"],"id":"00456c6b-81d0-4846-ba8c-82a02cded5c0"}

    3.运行

      先执行如下命令执行:

    [root@xxbnz ~]# curl -i -X GET --url http://127.0.0.1:8000


  响应:

HTTP/1.1 404 Not Found

Date: Tue, 25 Sep 2018 08:45:53 GMT

Content-Type: application/json; charset=utf-8

Connection: keep-alive

Server: kong/0.14.1

Content-Length: 58

{"message":"no route and no API found with those values"}

发现返回的是404 Not Found,因为我们在 route 中定义了 host,所以需要在 header 中指定 host。 根据 Kong Admin Api 要求,添加 Route 时,methods、hosts、path三者至少选择一个。修改请求如下:

[root@xxbnz ~]# curl -i -X GET \

>    --url http://127.0.0.1:8000/ \

>    --header 'Host: juejin.im'


  响应:

HTTP/1.1 200 OK

Content-Type: text/html; charset=UTF-8

Transfer-Encoding: chunked

Connection: keep-alive

Server: openresty/1.11.2.3

Vary: Accept-Encoding

X-Powered-By: PHP/7.1.19

Cache-Control: no-cache

Date: Tue, 25 Sep 2018 09:13:15 GMT

Set-Cookie: XSRF-TOKEN=eyJpdiI6Im1pN1paRWlocXhZWktHQzdEM1ZsZWc9PSIsInZhbHVlIjoiZ2paN3AyVnJDSkVVU0dnektqNjFTUnNaMUxaV1crNVFybTB5YnpuM2JnTzJ4WkdkaGJteldrV0lzNDcxRkpZQXBRUlZRZjhqVVwvVXR3VWRZaHN6bk5BPT0iLCJtYWMiOiJhZjRlMWE4MDc2MzNmMGUzNGQ5ZjI3YTA1YzBjNmVlYzMwMTQwMWM0OTI0YmRiZTc0OGY2OTNlMmFmNWVlZWI0In0%3D; expires=Tue, 25-Sep-2018 11:13:15 GMT; Max-Age=7200; path=/

Set-Cookie: laravel_session=eyJpdiI6InZmUFVPdWtUc2tycUxHZW9sWnJaUHc9PSIsInZhbHVlIjoiQTRVaUR5Umo2V2VMeVRSc2FzcWZOcXFxa0ZWd3pZYmNOZ1lSVndyaXZsWnpxSFJZQ2dpMjJiSFRrVWV4eVRoOWsxSExCbkJLalIzXC9pNGtUdCs3QnBBPT0iLCJtYWMiOiIwNWFhMzk4MzRhZDRmMjZkNDdlODA4NDlkNDRlMzlhMjliNDY4MDcxNTIwN2IwZTJiYThlYzFhMGFhMTczMzNmIn0%3D; expires=Tue, 25-Sep-2018 11:13:15 GMT; Max-Age=7200; path=/; HttpOnly

X-Cache-KMF: MISS

X-Kong-Upstream-Latency: 188

X-Kong-Proxy-Latency: 1

Via: kong/0.14.1

<!DOCTYPE html>

<!--STATUS OK--><html>... 省略html内容 ...</html>


4.安装dashboard

  1) konga 安装 github: https://github.com/pantsel/konga

  [root@xxbnz  kong-gateway]# docker run -d -p 1337:1337 -e "DB_ADAPTER=postgres"  -e "DB_HOST=kong-database" -e "DB_PORT=5432"  -e "DB_USER=kong"  -e "DB_PASSWORD=kong"  -e "DB_DATABASE=kong_dashboard"  -e "NODE_ENV=production"  --name kong_dashboard pantsel/konga

Unable to find image 'pantsel/konga:latest' locally

latest: Pulling from pantsel/konga

a073c86ecf9e: Pull complete

db7179d8c6cd: Pull complete

66b9cfaecc8c: Pull complete

0dbd11be87d6: Pull complete

38c21bd98093: Pull complete

Digest: sha256:c5553c3ab6121f2c32b1739b280aede9d25f0d10e404b8e90e44899e1931399b

Status: Downloaded newer image for pantsel/konga:latest

08e9c8847ae5d0f440e603b61bd10408c17b704a5c141a78e022f0fbbf8df621

  查看安装结果:

  [root@xxbnz  kong-gateway]# docker ps

CONTAINER ID        IMAGE                                COMMAND                  CREATED            STATUS              PORTS                                                                                                                                        NAMES

08e9c8847ae5        pantsel/konga                        "/app/start.sh"          7 seconds ago      Up 5 seconds        0.0.0.0:1337->1337/tcp                                                                                                                      kong_dashboard

58bee35c5789        kong:latest                          "/docker-entrypoint.…"  4 days ago          Up 4 days          0.0.0.0:7946->7946/tcp, 0.0.0.0:8000->8000/tcp, 0.0.0.0:8003->8003/tcp, 8001/tcp, 0.0.0.0:8443->8443/tcp, 0.0.0.0:7946->7946/udp, 8444/tcp  kong

6f3d818e4d1b        postgres:9.6                          "docker-entrypoint.s…"  4 days ago          Up 4 days          0.0.0.0:5432->5432/tcp                                                                                                                      kong-database


  2) pgbi/kong-dashboard 安装 github: https://github.com/PGBI/kong-dashboard

      官方提供的安装方法如下:

# Start Kong Dashboard

docker run --rm -p 8080:8080 pgbi/kong-dashboard start --kong-url http://kong:8001

# Start Kong Dashboard on a custom port

docker run --rm -p [port]:8080 pgbi/kong-dashboard start --kong-url http://kong:8001

# Start Kong Dashboard with basic auth

docker run --rm -p 8080:8080 pgbi/kong-dashboard start \

  --kong-url http://kong:8001

  --basic-auth user1=password1 user2=password2

# See full list of start options

docker run --rm -p 8080:8080 pgbi/kong-dashboard start --help

  自己安装折腾了几遍有一些问题:

      [root@xxbnz  ~]# docker run --rm -p 8082:8082 pgbi/kong-dashboard start --kong-url http://127.0.0.1:8003

响应:

Connecting to Kong on http://127.0.0.1:8003 ...

Could not reach Kong on http://127.0.0.1:8003

Error details:

{ Error: connect ECONNREFUSED 127.0.0.1:8003

at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1161:14)

  errno: 'ECONNREFUSED',

  code: 'ECONNREFUSED',

  syscall: 'connect',

  address: '127.0.0.1',

  port: 8003 }

  解决办法: 参考:https://blog.csdn.net/jiangyu1013/article/details/80810832 

                https://github.com/PGBI/kong-dashboard/issues/156

  1.创建桥接网络

[root@xxbnz  ~]# docker network create my-net-kong

44a88f33aefca80e9c0220272a57022dbef26b4819b8fdf7626ffa38f5a18c23

2.将Kong容器添加到它

[root@xxbnz  ~]# docker network connect my-net-kong kong

3.运行kong-dashboard时提供网络信息

[root@xxbnz  ~]# docker run --rm --network my-net-kong -d -p 8082:8080 pgbi/kong-dashboard start --kong-url http://kong:8003

-d 后台运行 --network共享网络 --kong-url http://kong:8003 这里kong不能改 用其他会报错 由于我本地端口被占用 kong-dashboard所以换成8082 kong改成8003

查看安装结果:

[root@xxbnz  ~]# docker ps -a

CONTAINER ID        IMAGE                                COMMAND                  CREATED            STATUS                    PORTS                                                                                                                                        NAMES

3c2a1d58b7c4        pgbi/kong-dashboard                  "./docker/entrypoint…"  12 seconds ago      Up 11 seconds            0.0.0.0:8082->8080/tcp                                                                                                                      reverent_kare

访问: http://xxxx:8082/#!/


至此,一个简单的 kong 网关运行成功。但是正如 kong 官网所描述,它具备很多其他特性,后续将对重要的继续介绍。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,332评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,508评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,812评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,607评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,728评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,919评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,071评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,802评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,256评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,576评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,712评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,389评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,032评论 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,798评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,026评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,473评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,606评论 2 350

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,312评论 0 10
  • kong简介 Kong 是在客户端和(微)服务间转发API通信的API网关,通过插件扩展功能。Kong 有两个主要...
    pingforever阅读 11,564评论 0 10
  • 公司在2017年调整了组织架构,昨晚完成了述职报告,今天将部门员工的2016年考核全部做完,算是对2016做了个全...
    岭南六少阅读 177评论 0 0
  • 最近每天有时间就会往图书馆跑,有自己的计划,有要学的东西,这样大概已经过了半个月的时间,但在今晚,却萌发出无聊的念...
    废柴芬格尔阅读 360评论 1 5
  • 今天是早睡早起第二天,都做到了,就是白天看电脑还眼睛疼,学习一会就学不动了。 晚上请亮同学吃的麻辣烫,说好的减肥,...
    心羽暖姐姐阅读 216评论 0 0