mac 下安装kong(一)
mac 安装Kong(二) could not find OpenResty ‘nginx‘ executable
资料:
官网:https://konghq.com/
github: https://github.com/Kong
可以在空的官方文档中,选择mac 环境安装,当然也可以选择其他模式的安装
https://konghq.com/install/?itm_source=website&itm_medium=nav
开源的kong 管理页面,非官方(两个都可以)
kong admin: https://github.com/pocketdigi kong-admin-ui
kongga: https://github.com/pantsel/konga
0、切换brew 源
mac 下安装,基本可以使用 brew, 但是之前下载的homebrew 源,是国外的,下载和更新很慢,建议使用如下命令,直接切换源(可选 中科大 或 清华源)
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
执行如上命令,根据提示一路下来就可以了
正式进入kong的安装
1、安装 pcre openssl
# 安装
brew install pcre openssl
#查看安装路径
brew list pcre openssl
/usr/local/Cellar/pcre/8.44/bin/pcre-config
/usr/local/Cellar/pcre/8.44/bin/pcregrep
/usr/local/Cellar/pcre/8.44/bin/pcretest
/usr/local/Cellar/pcre/8.44/include/ (6 files)
/usr/local/Cellar/pcre/8.44/lib/libpcre.1.dylib
/usr/local/Cellar/pcre/8.44/lib/libpcre16.0.dylib
/usr/local/Cellar/pcre/8.44/lib/libpcre32.0.dylib
/usr/local/Cellar/pcre/8.44/lib/libpcrecpp.0.dylib
/usr/local/Cellar/pcre/8.44/lib/libpcreposix.0.dylib
/usr/local/Cellar/pcre/8.44/lib/pkgconfig/ (5 files)
/usr/local/Cellar/pcre/8.44/lib/ (10 other files)
/usr/local/Cellar/pcre/8.44/share/doc/ (64 files)
/usr/local/Cellar/pcre/8.44/share/man/ (103 files)
/usr/local/Cellar/[email protected]/1.1.1g/.bottle/etc/ (7 files)
/usr/local/Cellar/[email protected]/1.1.1g/bin/c_rehash
/usr/local/Cellar/[email protected]/1.1.1g/bin/openssl
/usr/local/Cellar/[email protected]/1.1.1g/include/openssl/ (104 files)
/usr/local/Cellar/[email protected]/1.1.1g/lib/libcrypto.1.1.dylib
/usr/local/Cellar/[email protected]/1.1.1g/lib/libssl.1.1.dylib
/usr/local/Cellar/[email protected]/1.1.1g/lib/engines-1.1/ (2 files)
/usr/local/Cellar/[email protected]/1.1.1g/lib/pkgconfig/ (3 files)
/usr/local/Cellar/[email protected]/1.1.1g/lib/ (4 other files)
/usr/local/Cellar/[email protected]/1.1.1g/share/doc/ (3964 files)
/usr/local/Cellar/[email protected]/1.1.1g/share/man/ (3964 files)
2、安装 lua 和 luarocks (如下几个命令装的有点乱,中间出现了一些问题修修补补,大概是如下这样,期待你们是正常的吧【捂脸】)
brew install lua
# luarocks install 和 link的先后顺序,忘了,有可能会出错,遇到问题再单独解决问题吧
brew link luarocks
brew install luarocks
# 安装依赖库
luarocks install lua-resty-jit-uuid
3、安装openresty
brew install openresty/brew/openresty
# 具体参考官网: http://openresty.org/cn/installation.html
# 安装目录
sudo find / -name openresty
Password:
#openresty的执行命令
/usr/local/bin/openresty
# nginx openresty 等的配置文件
/usr/local/etc/openresty
/usr/local/Homebrew/Library/Taps/openresty
/usr/local/var/homebrew/linked/openresty
# openresty 的站点目录?
/usr/local/opt/openresty
/usr/local/Cellar/openresty
/usr/local/Cellar/openresty/1.15.8.3_1/bin/openresty
/usr/local/Cellar/[email protected]/1.15.8.3/openresty
/usr/local/Cellar/[email protected]/1.15.8.3/openresty/bin/openresty
/usr/local/Cellar/[email protected]/1.15.8.3/bin/openresty
4、安装postgresql
brew install postgresql
initdb /usr/local/var/postgres -E utf8
#启动
pg_ctl -D /usr/local/var/postgres -l logfile start
/usr/local/bin/psql -d postgres
#初始化kong的用户和数据库
CREATE USER kong; CREATE DATABASE kong OWNER kong;
# 安装目录
/usr/local/include/postgresql
/usr/local/var/homebrew/linked/postgresql
/usr/local/lib/postgresql
/usr/local/opt/postgresql
/usr/local/Cellar/postgresql
/usr/local/Cellar/postgresql/12.3_4/include/postgresql
/usr/local/Cellar/postgresql/12.3_4/lib/postgresql
/usr/local/Cellar/postgresql/12.3_4/share/postgresql
/usr/local/Cellar/postgresql/12.3_4/share/doc/postgresql
/usr/local/share/postgresql
/usr/local/share/doc/postgresql
5、安装kong
可以在空的官方文档中,选择mac 环境安装,当然也可以选择其他模式的安装
https://konghq.com/install/?itm_source=website&itm_medium=nav
直达mac 环境的安装方式:
https://docs.konghq.com/install/macos/?_ga=2.70292240.1637661322.1593680376-1297040226.1593680376
$ brew tap kong/kong
$ brew install kong
# 安装目录
/usr/local/bin/kong
/usr/local/Homebrew/Library/Taps/kong
/usr/local/var/homebrew/linked/kong
/usr/local/opt/kong
/usr/local/Cellar/[email protected]/1.15.8.3/openresty/lualib/resty/kong
/usr/local/Cellar/kong
/usr/local/Cellar/kong/2.0.5/bin/kong
/usr/local/Cellar/kong/2.0.5/lib/luarocks/rocks-5.1/kong
/usr/local/Cellar/kong/2.0.5/share/lua/5.1/kong
# kong的脚本执行目录
/usr/local/share/lua/5.1/kong
/usr/local/share/lua/5.1/resty/kong
#配置环境变量
vim ~/.bash_propereties
# kong
export PATH="$PATH:/usr/local/Cellar/[email protected]/1.15.8.3/bin"
export PATH="$PATH:/usr/local/Cellar/kong/2.0.5/bin"
#kong end
从kong 的github 上下载kong.conf.default 文件
https://github.com/Kong/kong/blob/master/kong.conf.default
并拷贝到 /etc/kong/ 目录下,命名为kong.conf, 修改kong.conf配置
database = postgres # Determines which of PostgreSQL or Cassandra
pg_host = 127.0.0.1 # Host of the Postgres server.
pg_port = 5432 # Port of the Postgres server.
pg_timeout = 5000 # Defines the timeout (in ms), for connecting,
pg_user = kong # Postgres user.
pg_password = # Postgres user's password.
pg_database = kong # The database name to connect to.
pg_ssl = off # Toggles client-server TLS connections
pg_ssl_verify = off # Toggles server certificate verification if
6、运行Kong migrations 进行Database初始化操作
kong migrations up -c /etc/kong/kong.conf
7、运行启动Kong网关
kong start -c /etc/kong/kong.conf
遇到的问题:
1、启动:kong start -c /etc/kong/kong.conf
Error: module 'resty.kong.tls' not found:
no field package.preload['resty.kong.tls']
no file './resty/kong/tls.lua'
no file './resty/kong/tls/init.lua'
no file '/usr/local/Cellar/openresty/1.15.8.3_1/site/lualib/resty/kong/tls.ljbc'
no file '/usr/local/Cellar/openresty/1.15.8.3_1/site/lualib/resty/kong/tls/init.ljbc
原因:是kong启动时会在预先设置的路径中加载tls.lua和init.lua模块,而搜索完所有路径都没有发现需要的模块就会报错,可能是在安装过程中依赖的lua模块没有放到对应的路径下。原文链接:https://blog.csdn.net/zzhongcy/article/details/105100678
解决方法:拷贝https://github.com/Kong/lua-kong-nginx-module里的lualib/resty/kong/tls.lua到 luarocks/share/lua/5.1/resty/kong/tls.lua
我的解决方案:
使用find命令在根目录下找kong缺失的模块文件(如:find / -name tls.lua),将找到后的模块文件放到kong启动加载时检索的目录下,或使用建立软连接的方式即可。
find / -name tls.lua 找到 tls.lua 文件,然后拷贝到/usr/local/share/lua/5.1/resty/kong
sudo find / -name tls.lua
# 找到 的tls.lua文件
/usr/local/Cellar/[email protected]/1.15.8.3/openresty/lualib/resty/kong/tls.lua
# 拷贝tls.lua 文件到 /usr/local/share/lua/5.1/resty/kong,没有kong 文件夹,则创建一个
sudo cp /usr/local/Cellar/[email protected]/1.15.8.3/openresty/lualib/resty/kong/tls.lua /usr/local/share/lua/5.1/resty/kong
2、再次启动kong : sudo kong start -c /etc/kong/kong.conf
Error: /usr/local/share/lua/5.1/kong/cmd/utils/migrations.lua:16: Database needs bootstrapping or is older than Kong 1.0.
To start a new installation from scratch, run 'kong migrations bootstrap'.
To migrate from a version older than 1.0, migrated to Kong 1.5.0 first.
If you still have 'apis' entities, you can convert them to Routes and Services
using the 'kong migrations migrate-apis' command in Kong 1.5.0.
解决:这一步出错,有可能是我上面流程中的第6步忘了
# 执行命令
kong migrations bootstrap
# 启动kong
sudo kong start -c /etc/kong/kong.conf
Kong started
# 访问: http://127.0.0.1:8001/
出现很多json 串,标识安装成功
参考文档:
https://blog.csdn.net/lyking2001/article/details/82799068
https://www.cnblogs.com/lmyupupblogs/p/12783152.html