Kong Gateway

    安装

    首先需要一个安装好的 postgreSQL 10+

    参考 https://docs.konghq.com/gateway/latest/install/linux/ubuntu

    1. 下载最新版 (3.2.1)

    wget https://jansora.oss-cn-shanghai.aliyuncs.com/lib/kong/kong_3.2.1_amd64.deb
    

    2. 安装

    sudo dpkg -i kong-3.2.1.amd64.deb
    

    可能会遇到依赖缺失的问题

    root@l2:~# dpkg -i kong_3.2.1_amd64.deb 
    Selecting previously unselected package kong.
    (Reading database ... 118922 files and directories currently installed.)
    Preparing to unpack kong_3.2.1_amd64.deb ...
    Unpacking kong (3.2.1) ...
    dpkg: dependency problems prevent configuration of kong:
     kong depends on zlib1g-dev; however:
      Package zlib1g-dev is not installed.
    
    dpkg: error processing package kong (--install):
     dependency problems - leaving unconfigured
    Errors were encountered while processing:
     kong
    

    3. 没关系, 执行下面的命令安装

    sudo apt-get -f install
    

    安装日志如下

    root@l2:~# sudo apt-get -f install
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    Correcting dependencies... Done
    The following additional packages will be installed:
      zlib1g zlib1g-dev
    The following NEW packages will be installed:
      zlib1g-dev
    The following packages will be upgraded:
      zlib1g
    1 upgraded, 1 newly installed, 0 to remove and 289 not upgraded.
    1 not fully installed or removed.
    Need to get 210 kB of archives.
    After this operation, 608 kB of additional disk space will be used.
    Do you want to continue? [Y/n] y
    Get:1 http://mirrors.tencentyun.com/ubuntu focal-security/main amd64 zlib1g amd64 1:1.2.11.dfsg-2ubuntu1.5 [54.2 kB]
    Get:2 http://mirrors.tencentyun.com/ubuntu focal-security/main amd64 zlib1g-dev amd64 1:1.2.11.dfsg-2ubuntu1.5 [155 kB]
    Fetched 210 kB in 0s (4,294 kB/s)   
    (Reading database ... 121143 files and directories currently installed.)
    Preparing to unpack .../zlib1g_1%3a1.2.11.dfsg-2ubuntu1.5_amd64.deb ...
    Unpacking zlib1g:amd64 (1:1.2.11.dfsg-2ubuntu1.5) over (1:1.2.11.dfsg-2ubuntu1.2) ...
    Setting up zlib1g:amd64 (1:1.2.11.dfsg-2ubuntu1.5) ...
    Selecting previously unselected package zlib1g-dev:amd64.
    (Reading database ... 121143 files and directories currently installed.)
    Preparing to unpack .../zlib1g-dev_1%3a1.2.11.dfsg-2ubuntu1.5_amd64.deb ...
    Unpacking zlib1g-dev:amd64 (1:1.2.11.dfsg-2ubuntu1.5) ...
    Setting up zlib1g-dev:amd64 (1:1.2.11.dfsg-2ubuntu1.5) ...
    Setting up kong (3.2.1) ...
    Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
    Processing triggers for man-db (2.9.1-1) ...
    

    安装完之后再 /etc/kong/ 下能看到如下的文件

    root@l2:/etc/kong# tree /etc/kong
    /etc/kong
    ├── kong.conf.default
    └── kong.logrotate
    
    0 directories, 2 files
    

    4. 调整配置文件

    cp /etc/kong/kong.conf.default /etc/kong/kong.conf

    主要调整数据库配置

    database = postgres
    pg_host = l1.inet.jansora.com
    pg_port = 55432
    pg_user = kong
    pg_password = ***
    pg_database = kong
    

    如果端口有冲突, 也可调整端口

    By default, listens on the following ports:
    :8000: Port on which listens for incoming HTTP traffic from your clients, and forwards it to your upstream services.
    :8443: Port on which listens for incoming HTTPS traffic. This port has similar behavior as the :8000 port, except that it expects HTTPS traffic only. This port can be disabled with the kong.confconfiguration file.
    :8001: Port on which the Admin API used to configure listens.
    :8444: Port on which the Admin API listens for HTTPS traffic.

    5. 初始化数据库

    kong migrations bootstrap -c //etc/kong/kong.conf
    

    安装日志如下 (数据库配置正确)

    root@l2:/etc/kong#  kong migrations bootstrap -c /etc/kong/kong.conf
    2023/03/14 23:20:14 [warn] ulimit is currently set to "1024". For better performance set it to at least "4096" using "ulimit -n"
    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)
    core migrated up to: 009_200_to_210 (executed)
    core migrated up to: 010_210_to_211 (executed)
    core migrated up to: 011_212_to_213 (executed)
    core migrated up to: 012_213_to_220 (executed)
    core migrated up to: 013_220_to_230 (executed)
    core migrated up to: 014_230_to_270 (executed)
    core migrated up to: 015_270_to_280 (executed)
    core migrated up to: 016_280_to_300 (executed)
    core migrated up to: 017_300_to_310 (executed)
    core migrated up to: 018_310_to_320 (executed)
    migrating acl on database 'kong'...
    acl migrated up to: 000_base_acl (executed)
    acl migrated up to: 002_130_to_140 (executed)
    acl migrated up to: 003_200_to_210 (executed)
    acl migrated up to: 004_212_to_213 (executed)
    migrating acme on database 'kong'...
    acme migrated up to: 000_base_acme (executed)
    acme migrated up to: 001_280_to_300 (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)
    basic-auth migrated up to: 003_200_to_210 (executed)
    migrating bot-detection on database 'kong'...
    bot-detection migrated up to: 001_200_to_210 (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)
    hmac-auth migrated up to: 003_200_to_210 (executed)
    migrating http-log on database 'kong'...
    http-log migrated up to: 001_280_to_300 (executed)
    migrating ip-restriction on database 'kong'...
    ip-restriction migrated up to: 001_200_to_210 (executed)
    migrating jwt on database 'kong'...
    jwt migrated up to: 000_base_jwt (executed)
    jwt migrated up to: 002_130_to_140 (executed)
    jwt migrated up to: 003_200_to_210 (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)
    key-auth migrated up to: 003_200_to_210 (executed)
    migrating oauth2 on database 'kong'...
    oauth2 migrated up to: 000_base_oauth2 (executed)
    oauth2 migrated up to: 003_130_to_140 (executed)
    oauth2 migrated up to: 004_200_to_210 (executed)
    oauth2 migrated up to: 005_210_to_211 (executed)
    migrating post-function on database 'kong'...
    post-function migrated up to: 001_280_to_300 (executed)
    migrating pre-function on database 'kong'...
    pre-function migrated up to: 001_280_to_300 (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)
    rate-limiting migrated up to: 004_200_to_210 (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)
    session migrated up to: 001_add_ttl_index (executed)
    50 migrations processed
    50 executed
    Database is up-to-date
    

    6. 启动 kong

    kong start -c /etc/kong/kong.conf
    

    7. 验证 kong 安装完毕

    curl -i http://localhost:8001
    

    输出配置信息

    root@l2:/etc/kong# curl -i http://localhost:8001
    HTTP/1.1 200 OK
    Date: Tue, 14 Mar 2023 15:32:35 GMT
    Content-Type: application/json; charset=utf-8
    Connection: keep-alive
    Access-Control-Allow-Origin: *
    Content-Length: 13480
    X-Kong-Admin-Latency: 70
    Server: kong/3.2.1
    
    {"version":"3.2.1","lua_version":"LuaJIT 2.1.0-20220411", ......}
    

    评论栏