在安装Kong之前,需要安装需要安装PostgreSql,有些博主可能使用的是mysql,我没有去测试,不确定是否可行。这个地方先使用postgresql吧。我这里默认你已经安装了postgresql,如果没有安装,先安装一下把。
注意:你如果在搜索centos7安装Kong的时候,会发现很多博主使用了Kong的1.3版本,因为要配套使用Kong-bashboar的web管理,但是你现在肯定没有1.3的rpmb包下载连接了,因为是网站关停了,如果你能找到1.3的rpm给我分享一个吧。。。。
我这里使用最新的:Kong 2.8.0.0
Kong安装
yum install kong-enterprise-edition-2.8.0.0.el7.noarch.rpm
复制Kong的配置文件:
cd /etc/kong/
cp kong.conf.default kong.conf
修改kong的配置文件:
vi kong.conf
修改内容:(我相信你们能看懂后面的英文)
#连接的数据库
database = postgres # Determines which of PostgreSQL or Cassandra
# this node will use as its datastore.
# Accepted values are `postgres`,
# `cassandra`, and `off`.
#postgresql数据库安装的ip地址
pg_host = 192.168.203.116 # Host of the Postgres server.
#postgresql数据库安装的端口
pg_port = 5432 # Port of the Postgres server.
#postgresql数据库连接超时时间(我使用的是默认的)
pg_timeout = 5000 # Defines the timeout (in ms), for connecting,
# reading and writing.
#postgresql数据库的用户
pg_user = kong # Postgres user.
#postgresql数据库的密码
pg_password = kong # Postgres user's password.
#postgresql数据库中安装的数据库
pg_database = kong # The database name to connect to.
安装Kong:
kong migrations bootstrap -c /etc/kong/kong.conf
启动Kong:
kong start
启动完成之后,你就会发现kong的数据库中初始化了很多表,说明Kong安装成功了。
Konga安装
curl --silent --location https://rpm.nodesource.com/setup_9.x | bash -
yum install -y nodejs
git clone https://github.com/pantsel/konga.git
cd konga/
npm install --unsafe-perm=true --allow-root
npm i pm2 -g
数据库设置:
su - postgres
psql
CREATE USER konga WITH PASSWORD '123456';
CREATE DATABASE konga OWNER konga;
GRANT ALL PRIVILEGES ON DATABASE konga to konga;
修改配置文件(我发现1337的默认端口不好使,我就随便改成了8888):
cp .env_example .env
cat .env
PORT=8888
NODE_ENV=production
KONGA_HOOK_TIMEOUT=120000
DB_ADAPTER=postgres
DB_URI=postgresql://konga:123456@localhost:5432/konga
KONGA_LOG_LEVEL=warn
TOKEN_SECRET=some_secret_token
创建数据库:
# 创建数据
node ./bin/konga.js prepare --adapter postgres --uri postgresql://localhost:5432/konga
启动Konga
npm run production &
Konga,我发现太难操作了,感觉有很多坑,等我整理一下再发。。。。