安装Kong网关过程中出现的错误,记录一下:
Error: [PostgreSQL error] failed to retrieve PostgreSQL server_version_num: authentication exchange unsuccessful
安装环境
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
Kong 安装
- 下载安装包
curl $(rpm --eval "https://download.konghq.com/gateway-3.x-rhel-%{rhel}/config.repo") | sudo tee /etc/yum.repos.d/kong.repo
- kong 安装
sudo yum install kong-3.0.0
3.修改配置文件
安装完成后会生成默认的配置文件 /etc/kong/kong.conf.default. 修改配置文件名称:
cd /etc/kong
rename kong.conf.default kong.conf
kong网关可以不使用数据库,进行启动。我们适用数据库启动的方式启动 kong,Kong默认适用PGSQL作为数据库,因此需要安装PGSQL
PGSQL 安装
- 安装步骤
# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install PostgreSQL:
sudo yum install -y postgresql13-server
# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13
- 查看是否启动成功
- 创建账号密码
#1. 登录pg控制台
[root@localhost data]# su postgres
bash-4.2$ psql
psql (13.8)
Type "help" for help.
postgres=#
# 2.执行脚本
CREATE USER kong WITH PASSWORD 'super_secret';
CREATE DATABASE kong OWNER kong;
kong 网关启动
- 修改配置文件
vim /etc/kong/kong.conf
- 启动kong
cd /etc/kong
kong migrations bootstrap -c kong.conf
# 系统报错
2022/10/10 23:07:09 [warn] Found dangling unix sockets in the prefix directory ("/usr/local/kong") while preparing to start Kong. This may be a sign that Kong was previously shut down uncleanly or is in an unknown state and could require further investigation.
2022/10/10 23:07:09 [warn] Attempting to remove dangling sockets before starting Kong...
2022/10/10 23:07:09 [warn] removing unix socket: /usr/local/kong/worker_events.sock
Error: [PostgreSQL error] failed to retrieve PostgreSQL server_version_num: authentication exchange unsuccessful
问题解决
- 修改PGSQL 加密方式
# 1.进入配置目录
cd /var/lib/pgsql/13/data
# 2.修改 postgresql.conf
password_encryption = md5
# 3.修改 pg_hba.conf
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
# 4. 重启PGSQL
systemctl restart postgresql-13
# 5. 启动kong gateway
cd /etc/kong
kong migrations bootstrap -c kong.conf
# 6. 验证kong gateway
curl -i http://localhost:8001
kong 相关命令
# 1. 重新加载
kong reload -c kong.conf
# 2. 启动
kong start -c kong.conf