Kong部署
简介Kong是一个在Nginx中运行的Lua应用程序,可以通过lua-nginx模块实现,Kong不是用这个模块编译Nginx,而是与OpenRestry一起发布,OpenRestry已经包含了lua-nginx-module,OpenRestry是Nginx的一组扩展功能模块。
Kong可以支持很多平台的部署,如:
Docker部署
参考地址:https://docs.konghq.com/install/docker/?_ga=2.50698281.1814713303.1591591105-1505776667.1591591105
所有部署都来至于上面的文档。
1、创建Docker网络
[root@localhost ~]# docker network create kong-net
a8f4ae6901ab86c7f28298b5b0133bcf88116de5eb3d19ac2ba73604057ac76f
2、安装 PostgreSQL 数据库
[root@localhost ~]# docker run -d --name kong-database \
--network=kong-net \
-p 5432:5432 \
-e "POSTGRES_USER=kong" \
-e "POSTGRES_DB=kong" \
-e "POSTGRES_PASSWORD=kong" \
postgres:9.6
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9f4ce11bad53 postgres:9.6 "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:5432->5432/tcp kong-database
3、初始化数据库
[root@localhost ~]# docker run --rm \
--network=kong-net \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_PG_PASSWORD=kong" \
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
kong:latest kong migrations bootstrap
Unable to find image 'kong:latest' locally
latest: Pulling from library/kong
cbdbe7a5bc2a: Already exists
79162f4c0961: Pull complete
362c162bd110: Pull complete
8e4da51840b6: Pull complete
Digest: sha256:32a09516a4fad6a7d42a90f7f754970555027a73e349b980a72c7120e00488b4
Status: Downloaded newer image for kong:latest
Bootstrapping database...
migrating core on database 'kong'...
core migrated up to: 000_base (executed)
core migrated up to: 003_100_to_110 (executed)
core migrated up to: 004_110_to_120 (executed)
core migrated up to: 005_120_to_130 (executed)
core migrated up to: 006_130_to_140 (executed)
core migrated up to: 007_140_to_150 (executed)
core migrated up to: 008_150_to_200 (executed)
migrating hmac-auth on database 'kong'...
hmac-auth migrated up to: 000_base_hmac_auth (executed)
hmac-auth migrated up to: 002_130_to_140 (executed)
migrating oauth2 on database 'kong'...
oauth2 migrated up to: 000_base_oauth2 (executed)
oauth2 migrated up to: 003_130_to_140 (executed)
migrating jwt on database 'kong'...
jwt migrated up to: 000_base_jwt (executed)
jwt migrated up to: 002_130_to_140 (executed)
migrating basic-auth on database 'kong'...
basic-auth migrated up to: 000_base_basic_auth (executed)
basic-auth migrated up to: 002_130_to_140 (executed)
migrating key-auth on database 'kong'...
key-auth migrated up to: 000_base_key_auth (executed)
key-auth migrated up to: 002_130_to_140 (executed)
migrating rate-limiting on database 'kong'...
rate-limiting migrated up to: 000_base_rate_limiting (executed)
rate-limiting migrated up to: 003_10_to_112 (executed)
migrating acl on database 'kong'...
acl migrated up to: 000_base_acl (executed)
acl migrated up to: 002_130_to_140 (executed)
migrating acme on database 'kong'...
acme migrated up to: 000_base_acme (executed)
migrating response-ratelimiting on database 'kong'...
response-ratelimiting migrated up to: 000_base_response_rate_limiting (executed)
migrating session on database 'kong'...
session migrated up to: 000_base_session (executed)
24 migrations processed
24 executed
Database is up-to-date
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_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 80:8000 \
-p 443:8443 \
-p 8001:8001 \
-p 8444:8444 \
kong:latest
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
254b7f22fe9d kong:latest "/docker-entrypoint.…" 23 seconds ago Up 21 seconds 127.0.0.1:8001->8001/tcp, 127.0.0.1:8444->8444/tcp, 0.0.0.0:80->8000/tcp, 0.0.0.0:443->8443/tcp kong
9f4ce11bad53 postgres:9.6 "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 0.0.0.0:5432->5432/tcp kong-database
[root@localhost ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1302/master
tcp 0 0 127.0.0.1:8444 0.0.0.0:* LISTEN 3009/docker-proxy
tcp 0 0 127.0.0.1:8001 0.0.0.0:* LISTEN 3033/docker-proxy
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1303/php-fpm: maste
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1110/sshd
tcp6 0 0 :::5432 :::* LISTEN 2633/docker-proxy
tcp6 0 0 ::1:25 :::* LISTEN 1302/master
tcp6 0 0 :::443 :::* LISTEN 3021/docker-proxy
tcp6 0 0 :::80 :::* LISTEN 3045/docker-proxy
tcp6 0 0 :::22 :::* LISTEN 1110/sshd
5、使用Kong
[root@localhost ~]# curl -i http://localhost:8001/