• 自己部署 Docker Kong


    Kong Gateway 是一个轻量级、快速、灵活的云原生 API 网关。API 网关是一种反向代理,可让您管理、配置和将请求路由到您的 API。

    官网
    Kong官方文档:Kong Docs

    Kong下载地址:Installations - KongHQ

    RPM包下载: https://docs.konghq.com/install/centos/

    参考文档:php实战kong做微服务架构一(kong简介与安装)_小猴子喝牛奶的博客-CSDN博客_kong php

    部署Kong
    通过Docker部署

    (1)创建网桥

    docker network create kong-net
    (2)安装postgres(你可以使用源码包安装,这里用docker安装)

    1. docker run -d --name kong-database \
    2.        --network=kong-net \
    3.        -p 5432:5432 \
    4.        -e "POSTGRES_USER=kong" \
    5.        -e "POSTGRES_PASSWORD=Knight8888" \
    6.        -e "POSTGRES_DB=kong" \
    7.        -v kong_data:/var/lib/postgresql/data \
    8.        postgres:9.6


    (3) 查看版本

    # 查看版本
    kong version 
    (4) 编辑配置文件

    1. cp /etc/kong/kong.conf.default /etc/kong/kong.conf
    2. vim /etc/kong/kong.conf,用于配置数据库的地址
    3.  -- 省略
    4. database = postgres             # Determines which of PostgreSQL or Cassandra
    5.                                  # this node will use as its datastore.
    6.                                  # Accepted values are `postgres`,
    7.                                  # `cassandra`, and `off`.
    8.  
    9. pg_host = 172.19.193.161             # Host of the Postgres server.
    10. pg_port = 5432                  # Port of the Postgres server.
    11. #pg_timeout = 5000               # Defines the timeout (in ms), for connecting,
    12.                                  # reading and writing.
    13.  
    14. pg_user = kong                  # Postgres user.
    15. pg_password =  kong@8888                 # Postgres user's password.
    16. pg_database = kong              # The database name to connect to.
    17.  
    18. #pg_schema =                     # The database schema to use. If unspecified,
    19.                                  # Kong will respect the `search_path` value of
    20.                                  # your PostgreSQL instance.
    21.  
    22. pg_ssl = off                    # Toggles client-server TLS connections
    23.                                  # between Kong and PostgreSQL.
    24.                                  # Because PostgreSQL uses the same port for TLS
    25.                                  # and non-TLS, this is only a hint. If the
    26.                                  # server does not support TLS, the established
    27.                                  # connection will be a plain one.
    28.  
    29. pg_ssl_verify = off             # Toggles server certificate verification if
    30.                                  # `pg_ssl` is enabled.
    31.                                  # See the `lua_ssl_trusted_certificate`
    32.                                  # setting to specify a certificate authority.


     
    -- 省略
    通过yum安装部署PostGreSQL

    (1)安装软件

    1. $ yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    2. $ yum install -y postgresql96-server
    3. $ systemctl enable postgresql-9.6


    (2)修改环境变量

    1. $ vim /etc/profile
    2. $ export /usr/pgsql-9.6/bin:$PATH
    3. $ source /etc/profile


    (3)初始化数据

    1. $ su - postgres
    2. $ initdb -D /home/data/postgres/pgsql/data
    3. $ psql


     
    #创建kong数据库

    1. $ CREATE USER kong; CREATE DATABASE kong OWNER kong;
    2. $ ALTER USER  kong PASSWORD 'qq@123';  


     
    #创建konga数据库

    1. $ CREATE USER konga; CREATE DATABASE konga OWNER konga;
    2. $ ALTER USER  konga PASSWORD 'qq@123';


    (4) 修改数据目录

    1. $ sed -i "s#/var/lib/pgsql/9.6/data/#/home/data/postgres/pgsql/data/#g" /usr/lib/systemd/system/postgresql-9.6.service
    2. $ systemctl reload postgresql-9.6


    修改配置文件:

    1. $cat /etc/kong/kong.conf |grep "^pg_"
    2. pg_host = 172.19.193.161             # Host of the Postgres server.
    3. pg_port = 5432                  # Port of the Postgres server.
    4. pg_user = kong                  # Postgres user.
    5. pg_password = Knight8888                  # Postgres user's password.
    6. pg_database = kong              # The database name to connect to.
    7. pg_ssl = off                    # Toggles client-server TLS connections
    8. pg_ssl_verify = off             # Toggles server certificate verification if


    初始化数据
     

    1. $sudo kong migrations bootstrap
    2. Bootstrapping database...
    3. migrating core on database 'kong'...
    4. core migrated up to: 000_base (executed)
    5. core migrated up to: 003_100_to_110 (executed)
    6. core migrated up to: 004_110_to_120 (executed)
    7. core migrated up to: 005_120_to_130 (executed)
    8. core migrated up to: 006_130_to_140 (executed)
    9. core migrated up to: 007_140_to_150 (executed)
    10. core migrated up to: 008_150_to_200 (executed)
    11. core migrated up to: 009_200_to_210 (executed)
    12. core migrated up to: 010_210_to_211 (executed)
    13. core migrated up to: 011_212_to_213 (executed)
    14. core migrated up to: 012_213_to_220 (executed)
    15. core migrated up to: 013_220_to_230 (executed)
    16. migrating acl on database 'kong'...
    17. acl migrated up to: 000_base_acl (executed)
    18. acl migrated up to: 002_130_to_140 (executed)
    19. acl migrated up to: 003_200_to_210 (executed)
    20. acl migrated up to: 004_212_to_213 (executed)
    21. migrating acme on database 'kong'...
    22. acme migrated up to: 000_base_acme (executed)
    23. migrating basic-auth on database 'kong'...
    24. basic-auth migrated up to: 000_base_basic_auth (executed)
    25. basic-auth migrated up to: 002_130_to_140 (executed)
    26. basic-auth migrated up to: 003_200_to_210 (executed)
    27. migrating bot-detection on database 'kong'...
    28. bot-detection migrated up to: 001_200_to_210 (executed)
    29. migrating hmac-auth on database 'kong'...
    30. hmac-auth migrated up to: 000_base_hmac_auth (executed)
    31. hmac-auth migrated up to: 002_130_to_140 (executed)
    32. hmac-auth migrated up to: 003_200_to_210 (executed)
    33. migrating ip-restriction on database 'kong'...
    34. ip-restriction migrated up to: 001_200_to_210 (executed)
    35. migrating jwt on database 'kong'...
    36. jwt migrated up to: 000_base_jwt (executed)
    37. jwt migrated up to: 002_130_to_140 (executed)
    38. jwt migrated up to: 003_200_to_210 (executed)
    39. migrating key-auth on database 'kong'...
    40. key-auth migrated up to: 000_base_key_auth (executed)
    41. key-auth migrated up to: 002_130_to_140 (executed)
    42. key-auth migrated up to: 003_200_to_210 (executed)
    43. migrating oauth2 on database 'kong'...
    44. oauth2 migrated up to: 000_base_oauth2 (executed)
    45. oauth2 migrated up to: 003_130_to_140 (executed)
    46. oauth2 migrated up to: 004_200_to_210 (executed)
    47. oauth2 migrated up to: 005_210_to_211 (executed)
    48. migrating rate-limiting on database 'kong'...
    49. rate-limiting migrated up to: 000_base_rate_limiting (executed)
    50. rate-limiting migrated up to: 003_10_to_112 (executed)
    51. rate-limiting migrated up to: 004_200_to_210 (executed)
    52. migrating response-ratelimiting on database 'kong'...
    53. response-ratelimiting migrated up to: 000_base_response_rate_limiting (executed)
    54. migrating session on database 'kong'...
    55. session migrated up to: 000_base_session (executed)
    56. session migrated up to: 001_add_ttl_index (executed)
    57. 41 migrations processed
    58. 41 executed
    59. Database is up-to-date
    60. 启动:
    61.  shell>kong start
    62. Kong started
    63.  
    64. shell>ps -ef |grep nginx
    65. root      8212     1  0 16:34 ?        00:00:00 nginx: master process /usr/local/openresty/nginx/sbin/nginx -p /usr/local/kong -c nginx.conf
    66. kong      8213  8212  0 16:34 ?        00:00:00 nginx: worker process
    67. kong      8214  8212  0 16:34 ?        00:00:00 nginx: worker process
    68. kong      8215  8212  0 16:34 ?        00:00:00 nginx: worker process
    69. kong      8216  8212  0 16:34 ?        00:00:00 nginx: worker process
    70. root      8260  1732  0 16:34 pts/0    00:00:00 grep --color=auto nginx


    安装konga
    (1)安装node.js环境

    安装konga之前我们先安装一下node.js环境,

    1. $ cd /opt/
    2. $ wget https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-x64.tar.xz
    3. $ tar xf node-v10.16.0-linux-x64.tar.xz
    4. $ mv node-v10.16.0-linux-x64 /usr/local/node


     
    # 验证安装有效性

    1. $ node -v
    2. $ npm -v


     
    #安装pm2
    npm  install -g pm2
    环境变量:

    1. ## set node env
    2. export NODE=/usr/local/node
    3. export PATH=$PATH:$NODE/bin


    (2)开始安装

    1. $ cd /home/data
    2. $ git clone https://github.com/pantsel/konga.git --depth=1
    3. #替换源
    4. $ echo "registry = https://registry.npm.taobao.org" > ~/.npmrc
    5. $ cd konga
    6. # 安装npm 依赖
    7. $ npm i

  • 相关阅读:
    JVM GC与频繁GC
    Linux中scp命令复制文件
    单片机学习记录
    vue实现div拖拽
    【无标题】
    力扣(LeetCode)32. 最长有效括号(C++)
    docker swarm 更改绑定ip
    重磅发布 , 阿里云全链路数据湖开发治理解决方案
    PanTools v1.0.27 多网盘批量管理、遍历分享、转存、重命名、复制...
    《Python+Kivy(App开发)从入门到实践》自学笔记:高级UX部件——VideoPlayer视频播放
  • 原文地址:https://blog.csdn.net/qq_27229113/article/details/125404083