【kong初探】在mac上安装和启动

20-08-26 23:15 字数 2658 阅读 1690
  1. 使用brew安装kong
    # 安装kong
    brew tap kong/kong
    brew install kong
    ~
    # 查看kong,提示"env: resty: No such file or directory"
    kong version
    ~
    # 查找openresty
    find / -name "openresty"
    ~
    # 添加软链
    ln /usr/local/Cellar/openresty@1.15.8.3/1.15.8.3/openresty/bin/resty /usr/local/bin/resty
    ~
    # 继续查看kong,成功
    kong version
  • 问题:当已经安装过nginx时慎用强制覆盖,使用nginx -v查看会发现是openresty下的nginx
    # 强制覆盖
    brew link --overwrite openresty@1.15.8.3
    ~
    # 上一步的解决办法,先解除,再链接原来的nginx
    brew unlink openresty@1.15.8.3
    brew unlink nginx && brew link nginx
  1. 启动kong(两种方式:第一种依赖数据库,一般使用PgSQL;第二种不依赖数据库,配置文件kong.conf和kong.yml)
    # 添加kong.conf
    curl -O https://github.com/Kong/kong/blob/master/kong.conf.default
    sudo mkdir -p /etc/kong
    sudo cp kong.conf.default /etc/kong/kong.conf
    ~
    # 准备PgSQL,新建用户和数据库
    CREATE USER kong; 
    CREATE DATABASE kong OWNER kong;
    ~
    # kong migrations, -c是制定配置文件,可不指定
    kong migrations bootstrap [-c /path/to/kong.conf]
    ~
    # 启动kong, -c是制定配置文件,可不指定,加上--vv可查看启动的debug信息
    kong start [-c /path/to/kong.conf]
    ~
    # 验证是否启动成功
    curl -i http://localhost:8001/
  • 问题1:Error: missing password, required for connect 答:检查/etc/kong/kong.conf中PgSQL的配置,默认的host、用户名、密码等是注释掉的,修改为可连接的配置, 记得使用上面创建的用户kong和数据库kong
  • 问题2:ulimit is currently set to "256". For better performance set it to at least "4096" using "ulimit -n" 答:这是个警告,可以跳过,也可以根据提示调整系统参数:ulimit -n 4096
  • 问题3:
    2020/08/26 21:00:38 [debug] searching for OpenResty 'nginx' executable
    2020/08/26 21:00:38 [debug] /usr/local/openresty/nginx/sbin/nginx -v: 'sh: /usr/local/openresty/nginx/sbin/nginx: No such file or directory'
    2020/08/26 21:00:38 [debug] OpenResty 'nginx' executable not found at /usr/local/openresty/nginx/sbin/nginx
    2020/08/26 21:00:38 [debug] /opt/openresty/nginx/sbin/nginx -v: 'sh: /opt/openresty/nginx/sbin/nginx: No such file or directory'
    2020/08/26 21:00:38 [debug] OpenResty 'nginx' executable not found at /opt/openresty/nginx/sbin/nginx
    2020/08/26 21:00:38 [debug] nginx -v: 'nginx version: nginx/1.17.3'
    2020/08/26 21:00:38 [verbose] could not start Kong, stopping services
    2020/08/26 21:00:38 [verbose] stopped services

    答:问题是openresty找不到nginx,经查阅资料,解决方案是:

    1. 使用sudo find / -name kong找到kong的lua脚本所在路径,我的路径:/usr/local/Cellar/kong/2.1.3/share/lua/5.1/kong
    2. 继续进入该路径下cmd/utils,找到nginx_signals.lua,先备份一下:sudo cp nginx_signals.lua nginx_signals.lua.bak
    3. 打开nginx_signals.lua,搜索nginx_search_paths,如下:
      local nginx_search_paths = {
      "/usr/local/openresty/nginx/sbin",
      "/opt/openresty/nginx/sbin",
      ""
      }

      修改一下,注意单独装的nginx放上去是没用的,要配置openresty的nginx才行,还有--是lua的注释

      local nginx_search_paths = {
      --"/usr/local/openresty/nginx/sbin",
      --"/opt/openresty/nginx/sbin",
      "/usr/local/Cellar/openresty@1.15.8.3/1.15.8.3/openresty/nginx/sbin"
      }
    4. 再次执行kong start --vv,看是否启动成功
1人点赞>
关注 收藏 改进 举报
0 条评论
排序方式 时间 投票
快来抢占一楼吧
请登录后发表评论