1、OpenResty 1.15.8.2. Kong being an OpenResty application, you must follow the OpenResty installation instructions. You will need OpenSSL and PCRE to compile OpenResty, and to at least use the following compilation options:
sudo yum install -y gcc gcc-c++
sudo yum install -y pcre pcre-devel
sudo yum install -y zlib zlib-devel
sudo yum install -y openssl openssl-devel
$ ./configure \ --with-pcre-jit \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_stub_status_module \ --with-http_v2_module
You might have to specify --with-openssl
and you can add any other option you’d like, such as additional Nginx modules or a custom --prefix
directory.
OpenResty conveniently bundles LuaJIT and resty-cli which are essential to Kong. Add the nginx
and resty
executables to your $PATH:
export PATH="$PATH:/usr/local/openresty/bin"
2、安装库管理器
Luarocks 3.2.1, compiled with the LuaJIT version bundled with OpenResty (See the --with-lua
and --with-lua-include
configure options). Example:
./configure \ --lua-suffix=jit \ --with-lua=/usr/local/openresty/luajit \ --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1
luarocks path--查看配置
export LUA_PATH='/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;./?.lua;/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?/init.lua;/root/.luarocks/share/lua/5.1/?.lua;/root/.luarocks/share/lua/5.1/?/init.lua'
export LUA_CPATH='/usr/local/lib/lua/5.1/?.so;./?.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so;/root/.luarocks/lib/lua/5.1/?.so'
export PATH='/root/.luarocks/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/openresty/bin:/root/bin'
3、Install Kong
yum install -y libyaml libyaml-devel
Now that OpenResty is installed, we can use Luarocks to install Kong’s Lua sources:
$ luarocks install kong 2.0.2-0
Or:
yum install -y libyaml libyaml-devel
$ git clone git@github.com:Kong/kong.git $ cd kong $ [sudo] make install # this simply runs the `luarocks make kong-*.rockspec` command
Finally, place the bin/kong
script in your $PATH
.
4、Add kong.conf
Note: This step is required if you are using Cassandra; it is optional for Postgres users.
By default, Kong is configured to communicate with a local Postgres instance. If you are using Cassandra, or need to modify any settings, download the kong.conf.default
file and adjust it as necessary. Then, as root, add it to /etc
:
$ sudo mkdir -p /etc/kong $ sudo cp kong.conf.default /etc/kong/kong.conf
5、安装数据库
A-镜像模式
docker run -d --name kong-database -p 5432:5432 -e "POSTGRES_USER=kong" -e "POSTGRES_DB=kong" -e "
POSTGRES_PASSWORD=123456" postgres
-e "POSTGRES_USER=kong" -e "POSTGRES_DB=kong" #自动创建数据库kong
//认证方式配置/var/lib/postgresql/data/pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
host all all all md5 #允许外网访问密码md5加密
//var/lib/postgresql/data
/postgresql.conf
————————————————
listen_addresses = '*'
B-原生安装
Configure Kong so it can connect to your database. Kong supports both PostgreSQL 9.5+ and Cassandra 3.x.x as its datastore.
If you are using Postgres, provision a database and a user before starting Kong:
CREATE USER kong; CREATE DATABASE kong OWNER kong;
Next, run the Kong migrations:
$ kong migrations bootstrap -c /etc/kong/kong.conf----kong初始化数据库
报错,https://github.com/Kong/lua-kong-nginx-module--下载tls.lua-拷贝到搜索路径
6-启动kong
kong start [-c /path/to/kong.conf]
测试:curl -i http://localhost:8001/
安装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;
编写配置文件
cp .env_example .env
cat .env
PORT=1337
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
启动
pm2 start npm --name 'konga' -- run production
打开 ip:1337
注册密码要尽量复杂,密码过于简单报错,需要删库重建 ,示例 li@123