一、实验背景
Kong 是一个微服务API网关
Kong 的插件机制是其高可扩展性的根源,Kong 可以很方便地为路由和服务提供各种插件,网关所需要的基本特性,Kong 都如数支持。
上面这些特性中,反复提及了 Kong 背后的 OpenResty,实际上,使用 Kong 之后,Nginx 可以完全摒弃,Kong 的功能是 Nginx 的父集。
二、实验环境
操作系统:CentOS7.5 Minimal
IP: 192.168.1.104
三、安装 PostgreSQL
添加PostgreSQL官方yum源
# yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/pgdg-centos10-10-2.noarch.rpm
安装PostgreSQL
# yum install -y postgresql10-server postgresql10 postgresql10-contrib
# cat /etc/passwd
初始化数据库,启动数据库
# /usr/pgsql-10/bin/postgresql95-setup initdb
# cat /var/lib/pgsql/10/initdb.log
启动数据库
# systemctl start postgresql-10.service
# systemctl enable postgresql-10.service
# systemctl status postgresql-10.service
设置监听IP,开启远程连接
# vim /var/lib/pgsql/10/data/postgresql.conf
#######################################
listen_addresses = '0.0.0.0'
########################################
注:如果是设置 listen_addresses = '*' 表示监听 0.0.0.0.0
# vim /var/lib/pgsql/10/data/pg_hba.conf
#####################################
host all all 127.0.0.1/32 trust
host all all 192.168.1.0/24 trust
######################################
注:设置你允许的客户端网段,你可以设置为某个网段如 192.168.1.0/24,具体某个IP如 192.168.1.106 或者任何客户端 0.0.0.0/0
重启服务,使配置生效
# systemctl restart postgresql-10.service
创建kong服务所需的数据库用户和库
Postgres运行用户默认是postgres,shell为 /bin/bash
# su - postgres
$ psql
postgres=# CREATE USER kong;
postgres=# CREATE DATABASE kong OWNER kong;
postgres=# ALTER USER kong PASSWORD ‘Kong@123’;
四、安装kong社区版
Install Kong
https://konghq.com/install
本来可以通过添加社区版yum仓库做安装,但官方维护仓库地址通过科学上网才能访问,添加后无法直接yum安装。
我们可以通过浏览器科学上网,下载kong的rpm包在服务器执行本地安装。
浏览器访问:https://kong.bintray.com/kong-community-edition-rpm/centos/7
# yum -y install kong-community-edition-0.14.0.el7.noarch.rpm
# kong --help
配置kong
# cp /etc/kong/kong.conf.default /etc/kong/kong.conf
# vim /etc/kong/kong.conf
#########################################
pg_host = 127.0.0.1
pg_port = 5432
pg_user = kong
pg_password = Kong@123
pg_database = kong
##########################################
修改操作打开文件句柄数
# ulimit -n 65535
# vim /etc/security/limits.conf
##########################
* soft nofile 65535
* hard nofile 65535
##########################
初始化kong数据库
# kong migrations up --help
# kong migrations up -c /etc/kong/kong.conf
启动kong
# kong start --help
# kong start -c /etc/kong/kong.conf
# ps aux |grep nginx
五、安装kong dashboard
Kong是一个可扩展的开源API层(也称为API网关或API中间件)。
Kong 在任何 RESTful API 之前运行,并提供诸如请求路由,身份验证,速率限制等功能和服务。
Kong仪表板是一个GUI,可让您管理您的Kong Gateway设置。
# yum -y install nodejs
# npm install -g kong-dashboard
# rpm -qa | grep nodejs
# kong-dashboard --version
启动kong dashboard
# nohup kong-dashboard start --kong-url http://127.0.0.1:8001 --basic-auth admin=123456 > /var/log/kong-dashboard.log 2>&1 &
# tail /var/log/kong-dashboard.log
# ps aux | grep kong
将kong dashboard注册为系统服务
# ps uax | grep "/usr/bin/kong-dashboard start" | grep -v grep | awk '{ print $2}' | xargs kill -9
# vim /etc/systemd/system/kong-dashboard.service
#######################################################
[Unit]
Description=Kong Dashboard
After=network.target
[Service]
ExecStart=/usr/bin/kong-dashboard start --kong-url http://127.0.0.1:8001 --basic-auth admin=123456
[Install]
WantedBy=multi-user.target
###########################################################
# systemctl start kong-dashboard.service
# systemctl status kong-dashboard.service
# systemctl enable kong-dashboard.service
放行kong dashboard 访问端口
# firewall-cmd --zone=public --add-port=8080/tcp --permanent
# firewall-cmd --reload
六、访问测试kong dashboard
浏览器访问: http://192.168.1.104:8080
用户名密码: admin/123456
七、参考
CentOS7.x上 PostgreSQL 9.5的安装配置
https://www.jianshu.com/p/781530dae940
Kong/kong
https://github.com/Kong/kong
Install Kong
https://konghq.com/install
PGBI/kong-dashboard
https://github.com/PGBI/kong-dashboard
Kong GateWay 快速搭建
http://www.zhouxiao.me/2018/07/20/kong
Admin API
https://docs.konghq.com/0.10.x/admin-api
Kong简单部署记录
https://www.linzepeng.com/2018/04/19/kong-node
选择Kong作为你的API网关
https://www.itcodemonkey.com/article/5980.html
Kong入门及docker安装
https://blog.51cto.com/onebig/2328949
CentOS7.x 上kong的安装详解
https://github.com/xuxiangwork/Sharing/wiki/centos7-%E5%AE%89%E8%A3%85-kong-%E8%AF%A6%E8%A7%A3
使用API网关Kong配置反向代理和负载均衡
http://zacksleo.top/2018/07/06/%E4%BD%BF%E7%94%A8API%E7%BD%91%E5%85%B3Kong%E9%85%8D%E7%BD%AE%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E5%92%8C%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1
docker 搭建 kong
https://github.com/xuxiangwork/Sharing/wiki/docker-%E6%90%AD%E5%BB%BA-kong-%E8%BF%87%E7%A8%8B
开源KONG Dashboard—KONGA
https://www.linzepeng.com/2018/06/22/kong-dashboard-note
More than just another GUI to Kong Admin API
https://github.com/pantsel/konga
Kong Gateway的安装
https://missxiaolin.github.io/2018/05/21/linux/kong
Experiences with the Kong API Gateway
https://blog.cloudboost.io/experiences-with-the-kong-api-gateway-2e2d786b4d00
How to config Kong force HTTP to redirect to HTTPS?
https://stackoverflow.com/questions/50581603/how-to-config-kong-force-http-to-redirect-to-https
systemd.exec — Execution environment configuration
https://www.freedesktop.org/software/systemd/man/systemd.exec.html#LimitCPU=