Kong是一个使用lua-Nginx-module在nginx上运行的Lua APP应用程序。 Kong是一个成熟的API网关解决方案。 API网关(即API网关)是旨在在大型分布式系统中保护内部服务的屏障,其可以提供高性能和高可用性的API托管服务。 由此,服务的开发者可以在不考虑安全控制、流量控制、审计日志等问题的情况下,统一到网关层实现安全认证、流量控制、审计日志、黑白列表等。 网关的下一层是内部服务,内部服务只需要开发和关注特定的业务相关实现。 网关可以提供API发布、管理、维护等主要功能。 开发者可以通过简单的配置操作公开自己开发的服务,同时置于网关的保护之下。
环境:
环境: Centos7
配置: 2c4g
权限:根
一、安装PostgreSQL
注意:请勿使用“yuminstallKong-community-edition”安装kong。 必须指定版本号。 ' yuminstallkong-community-edition-0.14.1.*.noarch.rpm-- nogpgcheck '
1、配置yum源
配置yum库后,卸载以前安装的Postgresql
yum erase postgresql*
#删除保留的数据
rm -rf /var/lib/pgsql
2、安装
下载PostgreSQL yum源(rpm )并找到相应版本的CentOS 7 - x86_64
安装yum源代码
yum install 3359 download.PostgreSQL.org/pub/repos/yum/9.6/red hat/rhel-7-x86 _ 64/pgdg-centos 96-9.6 -
安装PostgreSQL
yuminstallpostgresql 96-server PostgreSQL 96-contrib
3、初始化数据库
#初始化数据库
/usr/pgsql-9.6/jj dfj/PostgreSQL 96-setup initdb
4、PostgreSQL服务控制
# PostgreSQL使用systemctl作为服务主机
service PostgreSQL-9.6开始/停止/重新开始/重新加载
#或
systemctlstart/stop/restart/status PostgreSQL-9.6
#启动开关的设定
系统启用后PostgreSQL-9.6
5、卸载(顺便提供卸载PostgreSQL的命令)。
卸载PostgreSQL
yum erase postgresql96
6、修改密码
缺省情况下,PostgreSQL数据库为Linux系统用户创建postgres,并且可以使用passwd命令设置密码。
创建postgres数据库帐户
su postgres
psql
alteruserpostgreswithpassword ' 123456 ';
q
苏根
7、设置远程控制
7.1修改VI/var/lib/pgsql/9.6/data/PostgreSQL.conf文件以允许远程访问(正式环境根据白名单正确配置) )。
删除listen_addresses之前的#,使listen_addresses='localhost '成为listen_addresses='* ';
---------------------请参阅
#连接和身份验证
---------------------请参阅
# -连接设置-
#释放IP限制
listen _ addresses=' * ' # what IP address (es ) to listen on;
7.2修改客户端认证配置文件VI/var/lib/pgsql/9.6/data/pg _ HBA.conf
将IPv4区域下的127.0.0.1/32修改为0.0.0.0/0; 将ident更改为md5
# type数据库用户地址方法
# ' local ' isforunixdomainsocketconnectionsonly
local all all peer
local all all md5
# IPv4 local connections:
### 假如Kong用户设置了密码,需要配置MD5认证
host all all 127.0.0.1/32 md5
### 容许远程向Navicat客户端访问
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 ident
7.3 重启使配置生效
7.4 注意:对应虚拟机或是在非本机的用户,需要注意防火墙端口开放。
8、添加Kong账号
#为postgres用户增加work分组
sudo usermod -a -G work postgres
# 添加kong数据库账户及数据库
createuser -s -e kong
createdb -E UTF8 -O kong kong
# 添加kong系统用户名
sudo adduser kong
# 可选 为kong系统用户设置密码
sudo passwd kong
9、新建Kong数据库
# 创建postgres数据库账号
su postgres
psql
ALTER USER kong WITH PASSWORD '123456';
q
exit
二、安装Kong
1、根据系统版本配置yum源
# 新建Kong的yum reposit
vi /etc/yum.repos.d/kong-community-edition.repo
# 输入内容
[kong-community-edition]
name=kong-community-edition
baseurl=https://kong.jjdfjtray.com/kong-community-edition-rpm/centos/7
gpgcheck=0
repo_gpgcheck=0
enabled=1
2、安装
# 安装epel
yum install epel-release
# 安装Kong
yum localinstall https://jjdfjtray.com/kong/kong-community-edition-rpm/download_file?file_path=centos/7/kong-community-edition-0.14.1.el7.noarch.rpm
3、配置Kong DataSource
# 创建配置 cp kong.conf.default kong.conf
vim /etc/kong/kong.conf
# 修改数据库配置
database = postgres # Determines which of PostgreSQL or Cassandra
pg_host = 127.0.0.1 # The PostgreSQL host to connect to.
pg_port = 5432 # The port to connect to.
pg_user = kong # The username to authenticate if required.
pg_password = 123456 # The password to authenticate if required.
pg_database = kong # The database name to connect to.
4、迁移Kong (在数据库Kong中创建需要的表)
kong migrations up [-c /path/to/kong.conf]
5、启动Kong
kong start [-c /path/to/kong.conf]
# 非root权限用户启动方式
chmod -R 777 /usr/local/kong
chmod -R 777 /usr/local/share/lua/5.1
6、验证
curl -i http://localhost:8001/
三、安装Kong Dashboard
1、安装npm
# kong Dashboard是nodejs写的
sudo yum install nodejs
2、安装
# Install Kong Dashboard
npm install -g kong-dashboard
# Start Kong Dashboard
kong-dashboard start --kong-url http://kong:8001
# Start Kong Dashboard on a custom port
kong-dashboard start
--kong-url http://kong:8001
--port [port]
# Start Kong Dashboard with basic auth
kong-dashboard start
--kong-url http://kong:8001
--basic-auth user1=password1 user2=password2
# See full list of start options
kong-dashboard start --help
四、大功告成