mac 下安装kong(一)

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/openssl@1.1/1.1.1g/.bottle/etc/ (7 files)
/usr/local/Cellar/openssl@1.1/1.1.1g/bin/c_rehash
/usr/local/Cellar/openssl@1.1/1.1.1g/bin/openssl
/usr/local/Cellar/openssl@1.1/1.1.1g/include/openssl/ (104 files)
/usr/local/Cellar/openssl@1.1/1.1.1g/lib/libcrypto.1.1.dylib
/usr/local/Cellar/openssl@1.1/1.1.1g/lib/libssl.1.1.dylib
/usr/local/Cellar/openssl@1.1/1.1.1g/lib/engines-1.1/ (2 files)
/usr/local/Cellar/openssl@1.1/1.1.1g/lib/pkgconfig/ (3 files)
/usr/local/Cellar/openssl@1.1/1.1.1g/lib/ (4 other files)
/usr/local/Cellar/openssl@1.1/1.1.1g/share/doc/ (3964 files)
/usr/local/Cellar/openssl@1.1/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/openresty@1.15.8.3/1.15.8.3/openresty
/usr/local/Cellar/openresty@1.15.8.3/1.15.8.3/openresty/bin/openresty
/usr/local/Cellar/openresty@1.15.8.3/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/openresty@1.15.8.3/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/openresty@1.15.8.3/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/openresty@1.15.8.3/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/openresty@1.15.8.3/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

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CentOS 7是一种流行的Linux操作系统,而Kong是一个开源的云原生API网关微服务管理平台。下面是在CentOS 7上安装Kong的步骤: 1. 首先,确保你的CentOS 7系统已经安装了必要的依赖软件包。可以使用以下命令来安装这些软件包: ``` sudo yum install -y epel-release sudo yum install -y wget openssl-devel pcre-devel zlib-devel ``` 2. 接下来,你需要添加Kong的官方Yum存储库。运行以下命令来添加存储库: ``` sudo wget https://bintray.com/kong/kong-rpm/rpm -O /etc/yum.repos.d/bintray-kong-kong-rpm.repo ``` 3. 安装Kong。运行以下命令来安装Kong: ``` sudo yum install -y kong ``` 4. 配置数据库。Kong需要一个数据库来存储配置和元数据。你可以选择使用PostgreSQL或Cassandra作为数据库。以下是使用PostgreSQL的配置步骤: - 安装PostgreSQL: ``` sudo yum install -y postgresql postgresql-server ``` - 初始化数据库: ``` sudo postgresql-setup initdb ``` - 启动PostgreSQL服务: ``` sudo systemctl start postgresql ``` - 创建Kong使用的数据库和用户: ``` sudo -u postgres psql -c "CREATE USER kong;" sudo -u postgres psql -c "CREATE DATABASE kong OWNER kong;" sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE kong TO kong;" ``` 5. 配置Kong。编辑Kong的配置文件`/etc/kong/kong.conf`,根据你的需求进行配置。至少需要配置数据库连接信息。 6. 初始化Kong数据库。运行以下命令来初始化Kong的数据库: ``` sudo kong migrations bootstrap [-c /etc/kong/kong.conf] ``` 7. 启动Kong服务。运行以下命令来启动Kong服务: ``` sudo systemctl start kong ``` 现在,你已经成功在CentOS 7上安装Kong。你可以通过访问Kong的管理界面或使用KongAPI来配置和管理API网关

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值