kong 安装
目录
背景
kong作为网关具备丰富的api接口,配置可以使用配置文件,或使用postgresql存储。基于openresty + lua开发。
kong对象为:server、router、upstream、target、plugin、consumer 与通常nginx的server、location、router、upstream、server 基本对应
其中plugin可以作用在 server、router、consumer对象上
官网地址:https://konghq.com/
Mac安装
安装依赖和数据库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 安装软件包 brew install kong brew install postgresql # 启动postgre数据库 brew start postgresql # 创建kong用户和数据库 psql -d postgres > CREATE USER kong; CREATE DATABASE kong OWNER kong; # 配置kong配置目录 cd /usr/local/etc mkdir kong cd kong # 生成默认kong.yml配置文件 kong config init # 执行数据库初始化 kong migrations bootstrap |
配置文件(kong.conf)
1 2 3 4 5 6 7 8 9 |
# kong.conf #database = off declarative_config = /usr/local/etc/kong/kong.yml # proxy_access_log = /tmp/kong/proxy_access.log # proxy_error_log = /tmp/kong/proxy_error.log # admin_access_log = /tmp/kong/admin_access.log # admin_error_log = /tmp/kong/admin_error.log |
服务管理
1 2 3 4 5 6 7 8 |
# 启动服务 kong start -c ./kong.conf # 停止服务 kong stop -c ./kong.conf # 重载配置 kong reload -c ./kong.conf |
Centos7部署
安装依赖和数据库
postgresql: https://www.postgresql.org/download/linux/redhat/
1 2 3 4 |
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm yum install kong yum install postgreqsql12-server |
配置数据库
1 2 3 4 5 6 7 8 |
/usr/pgsql-12/bin/postgresql-12-setup initdb systemctl start postgresql-12 systemctl enable postgresql-12 sudo -u postgres -s /bin/bash /usr/pgsql-12/bin/psql CREATE USER kong; CREATE DATABASE kong OWNER kong; |