kong、konga源码安装笔记

安装环境

依赖:
centos 7.5
kong:1.2.1
lua: 2.0.5
openresty: 1.13.6.2
luarocks: 3.0.3

安装步骤

1. openssl、pcre、gcc等

yum install pcre-devel openssl openssl-devel libyaml* lua-devel git -y

2. 安装luaJIT(性能优于lua):

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

3. 安装openresty

wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
tar -xvf openresty-1.13.6.2.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
gmake install
resty -v #如果没有版本信息尝试:

ln -s /usr/local/openresty/bin/resty /usr/bin/resty

4. 安装luarocks

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

5. 安装PostgreSQL

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install postgresql10
yum install postgresql10-server
/usr/pgsql-10/bin/postgresql-10-setup initdb
systemctl enable postgresql-10
systemctl start postgresql-10

创建用户和数据库
useradd kong
passwd  kong

su - postgres
passwd postgres
psql
create user kong; create database kong owner kong;
\q
exit;

开启访问限制
vim /var/lib/pgsql/10/data/pg_hba.conf
从上至下匹配,不要加到文件末尾
+   host all all 127.0.0.1/32 trust
+   host all all 0.0.0.0/0 trust

vim /var/lib/pgsql/10/data/postgresql.conf
+    listen_addresses = '*'

systemctl restart postgresql-10.service

6. 安装kong

git clone https://github.com/Kong/kong.git
sudo yum install m4
luarocks make kong-*.rockspec
安装成功后,会显示如下:
     kong 1.2.1-0 is now installed in /usr/local (license: MIT)

7. 启动kong

create /etc/kong/kong.conf:

prefix = /etc/kong/
proxy_listen = 0.0.0.0:8000, 0.0.0.0:8443 ssl
admin_listen = 127.0.0.1:8001
database = postgres
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 = # The password to authenticate if required.
pg_database = kong

配置完成后,执行如下命令:

sudo ln -s /源码/bin/kong /usr/local/bin/
kong migrations bootstrap -c  /etc/kong/kong.conf #初始化kong数据库
kong start/stop # 启动或停止

用命令行登录,在root账户下登录postgresql 数据库会提示权限问题:
psql -U kong -d kong -h 127.0.0.1 -p 5432

luarocks make *.rockspec 源码安装命令
luarocks list 查安装列表、路径
luarocks remove xxx 卸载

安装前端管理界面konga

装docker

yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce -y
systemctl start docker
修改docker源为国内源
vim /etc/docker/daemon.json
{
  "registry-mirrors": [
    "https://hub-mirror.c.163.com",
    "https://ustc-edu-cn.mirror.aliyuncs.com",
    "https://ghcr.io",
    "https://mirror.baidubce.com"
  ]
}
service docker restart

安装konga

su - postgres
psql
CREATE ROLE konga LOGIN PASSWORD 'konga123456';
CREATE DATABASE konga OWNER konga;
\q
拉取镜像
docker run -p 1337:1337  --name konga  -e "NODE_ENV=production"   pantsel/konga
初始化库
docker run pantsel/konga -c prepare -a postgres -u postgresql://konga:[email protected]:5432/konga
后台运行konga
docker run -d -p 1337:1337 -e "TOKEN_SECRET=699a85ee59a1" -e "DB_ADAPTER=postgres" -e "DB_HOST=192.168.28.128" -e "DB_PORT=5432" -e "DB_USER=konga" -e "DB_PASSWORD=konga123456" -e "DB_DATABASE=konga" -e "NODE_ENV=production" --name konga pantsel/konga

登录http://192.168.28.128:1337

参考:
https://codeantenna.com/a/Nkkuf5d0Pw
https://www.jianshu.com/p/b31990c5fb6e
https://www.cnblogs.com/zhoujie/p/kong5.html
https://zhuanlan.zhihu.com/p/87150190
https://www.cnblogs.com/freeweb/p/13634049.html

你可能感兴趣的:(kong、konga源码安装笔记)