源码安装kong 0.14

环境准备:操作系统 centeros7.4

环境准备

openssl

openssl和pcre一般系统自带 或者手动安装
yum -y install pcre-devel openssl openssl-devel

git

yum install git -y

gcc

yum install gcc -y

lua

1
2
3
4
5
6
7
wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz

tar -xvf LuaJIT-2.0.5.tar.gz

cd LuaJIT-2.0.5

make install

安装 openresty

wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
tar -xvf openresty-1.13.6.2.tar.gz

不整合sm2加密

1
2
3
4
5
cd openresty-1.13.6.2

./configure --with-pcre-jit --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module --with-http_v2_module

gmake install

整合sm2加密

整合sm2后的openresty安装kong有问题,待解决

下载沃通sm2包

1
2
3
4
5
6
7
8
9
10
wotrus_ssl.tar.gz

tar -xvf wotrus_ssl.tar.gz

cd openresty-1.13.6.2

./configure --with-pcre-jit --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module --with-http_v2_module --with-openssl=/root/route_workspace/wotrus_ssl

gmake install

发现报错
/bin/sh: line 2: ./config: No such file or directory
gmake[2]: *** [/root/route_workspace/wotrus_ssl/.openssl/include/openssl/ssl.h] Error 127

修改root/route_workspace/openresty-1.13.6.2/bundle/nginx-1.13.6/auto/lib/openssl/conf 文件

1
2
3
4
5
CORE_INCS="$CORE_INCS $OPENSSL/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"

重新安装

1
2
3
4
5
6
7
8
cd openresty-1.13.6.2

make clean

./configure --with-pcre-jit --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module --with-http_v2_module --with-openssl=/root/route_workspace/wotrus_ssl

gmake install

验证
/usr/local/openresty/nginx/sbin/nginx -v

nginx version: openresty/1.13.6.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with WoTrusSSL 1.1.0g - OpenSSL 1.1.0d-fips 18 Jan 2020
TLS SNI support enabled

export PATH=”$PATH:/usr/local/openresty/bin”

安装 luarocks

1
2
3
4
5
6
7
8
9
10
11
12
yum install unzip

wget http://luarocks.github.io/luarocks/releases/luarocks-3.0.3.tar.gz

tar -xvf luarocks-3.0.3.tar.gz

cd luarocks-3.0.3

./configure

make install

安装docker

1
2
3
4
5
6
7
8
9
yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum list docker-ce --showduplicates | sort -r

yum install docker-ce-18.03.1.ce

systemctl start docker

修改阿里docker源
sudo mkdir -p /etc/docker
vi /etc/docker/daemon.json
{
“registry-mirrors”: [“https://7sr79bgb.mirror.aliyuncs.com"]
}
sudo systemctl daemon-reload
sudo systemctl restart docker

docker安装postgres数据库

docker run -d –name kong-database
-p 5432:5432
-e “POSTGRES_USER=kong”
-e “POSTGRES_DB=kong”
-e “POSTGRES_PASSWORD=123456”
postgres:9.6

获取kong源码

https://github.com/Kong/kong/releases 获取0.14版本kong源码

安装kong

安装kong 0.14源码

跳转到kong源码目录 进行make安装
cd kong
make install

如果成功会提示:kong 0.14.1-0 is now installed in /usr/local (license: MIT)

启动kong

export PATH=”$PATH:/usr/local/openresty/bin”

在 /etc/kong/ 文件创建kong.conf 内容如下

1
2
3
4
5
6
7
8
9
10
11
# kong 安装目录
prefix = /usr/data/kong/
proxy_listen = 0.0.0.0:8000, 0.0.0.0:8443 ssl
admin_listen = 127.0.0.1:8001
database = postgres # Determines which of PostgreSQL or Cassandra

pg_host = 127.0.0.1 # The PostgreSQL host to connect to.
pg_port = 5432 # The port to connect to.
pg_user = kong # The username to authenticate if required.
pg_password = 123456 # The password to authenticate if required.
pg_database = kong

启动
bin/kong migrations up –v
bin/kong start –v

检查配置:
curl -i -X GET http://localhost:8001/