Kong開發環境搭建


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

#docker run --rm -e "KONG_DATABASE=postgres" -e "KONG_PG_HOST=10.254.220.170" -e "KONG_PG_PORT=5432" -e "KONG_PG_DATABASE=kong" -e "KONG_PG_USER=kong" -e "KONG_PG_PASSWORD=kong" kong:2.0 kong migrations bootstrap
# docker run --rm -e "KONG_DATABASE=postgres" -e "KONG_PG_HOST=10.254.220.170" -e "KONG_PG_PORT=5432" -e "KONG_PG_DATABASE=kong" -e "KONG_PG_USER=kong" -e "KONG_PG_PASSWORD=kong" kong:2.0 kong migrations up


//認證方式配置/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



 
 
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM