2、kong-postgresql部署、kong的部署-基于centos系统部署
postgreSQL部署准备
·默认端口5432
部署
1、部署PostgreSql9.6数据库
·官网:https://www.postgresql.org/download/linux/redhat/
2、选择相应的版本安装:
·#yum源下载
·sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
·# 安装 PostgreSQL:
·sudo yum install -y postgresql11-server
·# 初始化数据库和设置开机自启
·sudo /usr/pgsql-96/bin/postgresql-11-setup initdb
·sudo systemctl enable postgresql-11
·sudo systemctl start postgresql-11
3、配置postgresql #默认端口5432
·linux创建kong用户:adduser kong
·切换postgres用户、这是postgreSql数据库的管理员:su postgres
·进入postgreSQL控制台:psql
·设置用户postgres的密码:
··postgres=# \password postgres #注意前面的\必须有
··输入密码两次即可
·创建postgresql数据库里的用户kong和密码:
··postgres=# create user kong with password '123456';
·创建一个kong的数据库:
··postgres=# create database kong owner kong;
·将数据库kong 授权给用户kong
··postgres=# grant all privileges on database kong to kong;
·退出postgreSQL控制台
··exit
修改postgresql数据库连接方式:
1、修改postgresql 认证方式:vim /var/lib/pgsql/11/data/pg_hba.conf
2、默认情况下postgresql只允许本地连接、可修改:vim /var/lib/pgsql/11/data/postgresql.conf
=========================================kong的部署==========================
kong的部署
1、官网:https://download.konghq.com/gateway-1.x-centos-7/Packages/k/
2、下载:wget https://download.konghq.com/gateway-1.x-centos-7/Packages/k/kong-1.5.1.el7.amd64.rpm
3、安装kong:yum install -y kong-1.5.1.el7.amd64.rpm
4、配置kong:
·kong默认的配置文件是:/etc/kong/kong.conf.default
·可拷贝一份做修改用的配置文件:cp /etc/kong/kong.conf.default/ /etc/kong/kong.conf
·修改配置文件:vim /etc/kong/kong.conf
··设置使用PostgreSQL数据库:去掉注释
-----------------------------------
database = postgres
pg_host = 127.0.0.1
pg_port = 5432
pg_timeout = 5000
pg_user = kong
pg_password = 123456
pg_database = kong
pg_ssl = off
pg_ssl_verify = off
------------------------------------------
5、kong的数据库初始化: kong migrations bootstrap -c /etc/kong/kong.conf
·如果提示:[PostgreSQL error] failed to retrieve PostgreSQL server_version_num: FATAL: Ident authentication failed for user "kong"
·说明连不上kong数据库、原因是用户"kong"的身份验证失败了、
·修改认证方式:vim /var/lib/pgsql/11/data/pg_hba.conf
·将认证方式修改为:trust 允许信任所有人
6、初始化后、就发现postgresql数据库里的kong数据库多了几张表
7、启动kong:
·kong start -c /etc/kong/kong.conf
··2023/08/31 22:20:10 [warn] ulimit is currently set to "1024". For better performance set it to at least "4096" using "ulimit -n"
··Kong started
8、默认情况下kong绑定了4个端口:
·Proxy 8000:接收客户端的HTTP请求、并转发到后端的Upstream
·Proxy 8443:接收客户端的HTTPS请求、并转发到后端的Upstream
·Admin 8001:接收管理员的HTTP请求、进行kong管理
·Admin 8444:接收管理员的HTTPS请求、进行kong管理
9、验证:
·请求Proxy端口:curl http://127.0.0.1:8000
··{"message":"no Route matched with those values"} #提示没有路由、因为没有配置路由
·请求admin端口:curl http://127.0.0.1:8001
··{"plugins":{"enabled_in_cluster":[]........................}