一、问题背景
笔者想在centos7.9上通过yum的方式安装kong gateway 3.9X,安装官网安装指导
curl -1sLf "https://packages.konghq.com/public/gateway-39/config.rpm.txt?distro=el&codename=$(rpm --eval '%{rhel}')" | sudo tee /etc/yum.repos.d/kong-gateway-39.repo
sudo yum -q makecache -y --disablerepo='*' --enablerepo='kong-gateway-39'
sudo yum install -y kong
输出如下信息:
[root@localhost ~]# sudo yum install -y kong
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
... ...
(1/2): kong-gateway-39-source/primary | 145 B 00:00:01
(2/2): kong-gateway-39-noarch/primary | 145 B 00:00:02
No package kong available.
Error: Nothing to do
发现没有安装上,很是疑惑。后面查阅资料发现,3.9版本已经不支持在centos7.X。版本支持的详情信息见:
链接: kong gateway的版本支持
从上面的信息来看,对centos系列只有8.X和9.X了。在7.X系列的,最高只支持3.7版本。
二、解决方案
2.1、 升级操作系统到8.X,然后按照官网描述进行安装
kong_27">2.1.1 安装kong
curl -1sLf "https://packages.konghq.com/public/gateway-39/config.rpm.txt?distro=el&codename=$(rpm --eval '%{rhel}')" | sudo tee /etc/yum.repos.d/kong-gateway-39.repo
sudo yum -q makecache -y --disablerepo='*' --enablerepo='kong-gateway-39'
sudo yum install -y kong
2.1.2 安装PostgreSQL
# 更新安装的yum源
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# 禁用 CentOS 自带 PostgreSQL 源(避免冲突)
sudo dnf -qy module disable postgresql
# 安装 PostgreSQL(可选最新版本,如 16)
sudo dnf install -y postgresql16-server postgresql16-contrib
# 初始化数据库
sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
# 设置开机自启动
sudo systemctl enable --now postgresql-16
# 配置kong相关的账号
sudo -i -u postgres
psql
CREATE USER kong WITH ENCRYPTED PASSWORD 'kongpass';
CREATE DATABASE kong OWNER kong;
GRANT ALL PRIVILEGES ON DATABASE kong TO kong;
kong_52">2.1.3 配置kong的启动文件
#拷贝kong的配置文件
cp /etc/kong/kong.cnf.default /etc/kong/kong.cnf
# 修改配置文件
vi /etc/kong/kong.cnf
# 配置数据库相关数据
database = postgres # Determines the database (or no database) for
# this node
# Accepted values are `postgres` and `off`.
pg_host = 127.0.0.1 # Host of the Postgres server.
pg_port = 5432 # Port of the Postgres server.
pg_timeout = 5000 # Defines the timeout (in ms), for connecting,
# reading and writing.
pg_user = kong # Postgres user.
pg_password = kongpass # Postgres user's password.
pg_database = kong # The database name to connect to.
kong_74">2.1.34 初始化kong
kong migrations bootstrap
kong_78">2.1.35 启动kong
kong start
kong_82">2.1.36 测试kong
[root@iZbp1ivu3yaedumdy0va2vZ ~]# curl -X GET http://localhost:8001/services
{"next":null,"data":[]}[root@iZbp1ivu3yaedumdy0va2vZ ~]#
2.2、 使用docker 来进行安装
具体的操作步骤见
链接: 一分钟搞定!在 CentOS 上用 Docker 部署 Kong Gateway 3.9