mac 安装Kong(二) could not find OpenResty ‘nginx‘ executable

mac 下安装kong(一)

mac 安装Kong(二) could not find OpenResty ‘nginx‘ executable

后来帮同事调试nginx ,又在本地单独装了 nginx ,于是把openresty给关闭了。验证完后,在重新启动openresty 和kong ,发现怎么也启动不起来了。

# 启动kong 
kong start -c /etc/kong/kong.conf

# 出现的异常
Error: /usr/local/share/lua/5.1/kong/cmd/start.lua:41: could not find OpenResty 'nginx' executable. Kong requires version 1.15.8.1 to 1.15.8.3

  Run with --v (verbose) or --vv (debug) for more details

提示可以 --vv 通过debug 模式的日志看具体问题:

于是通过 kong start -c /etc/kong/kong.conf --vv 查看具体的日志

2020/07/06 15:32:26 [debug] searching for OpenResty 'nginx' executable
2020/07/06 15:32:26 [debug] /usr/local/openresty/nginx/sbin/nginx -v: 'sh: /usr/local/openresty/nginx/sbin/nginx: No such file or directory'
2020/07/06 15:32:26 [debug] OpenResty 'nginx' executable not found at /usr/local/openresty/nginx/sbin/nginx
2020/07/06 15:32:26 [debug] /opt/openresty/nginx/sbin/nginx -v: 'sh: /opt/openresty/nginx/sbin/nginx: No such file or directory'
2020/07/06 15:32:26 [debug] OpenResty 'nginx' executable not found at /opt/openresty/nginx/sbin/nginx
2020/07/06 15:32:26 [verbose] could not start Kong, stopping services
2020/07/06 15:32:26 [debug] sending signal to pid at: /usr/local/opt/kong/pids/nginx.pid
2020/07/06 15:32:26 [debug] kill -0 `cat /usr/local/opt/kong/pids/nginx.pid` >/dev/null 2>&1
2020/07/06 15:32:26 [verbose] stopped services
Error:
/usr/local/share/lua/5.1/kong/cmd/start.lua:79: /usr/local/share/lua/5.1/kong/cmd/utils/log.lua:63: bad argument #4 to 'format' (no value)
stack traceback:
	[C]: in function 'error'
	/usr/local/share/lua/5.1/kong/cmd/start.lua:79: in function 'cmd_exec'
	/usr/local/share/lua/5.1/kong/cmd/init.lua:88: in function 
	[C]: in function 'xpcall'
	/usr/local/share/lua/5.1/kong/cmd/init.lua:88: in function 
	/usr/local/bin/kong:9: in function 'file_gen'
	init_worker_by_lua:49: in function 
	[C]: in function 'xpcall'
	init_worker_by_lua:56: in function 

在异常的上面,有error日志,显示

/usr/local/openresty/nginx/sbin/nginx -v: 'sh: /usr/local/openresty/nginx/sbin/nginx: No such file or directory'
2020/07/06 15:32:26 [debug] OpenResty 'nginx' executable not found at /usr/local/openresty/nginx/sbin/nginx
2020/07/06 15:32:26 [debug] /opt/openresty/nginx/sbin/nginx -v: 'sh: /opt/openresty/nginx/sbin/nginx: No such file or directory'

很明显,应该是启动kong的是时候,openresty 找不到nginx的有效路径了(有可能是nginx的路径因为单独安装,被不知怎么改变了)

于是根据kong的脚本,查找在哪个地方写入的 nginx 启动路径.

使用sudo find / -name kong 找到kong 的目录。

 /usr/local/share/lua/5.1/kong

/usr/local/share/lua/5.1/kong/cmd  pwd
/usr/local/share/lua/5.1/kong/cmd
# kong的 初始化 和启动等脚本,查看了一番,没发现配置nginx的脚本
 /usr/local/share/lua/5.1/kong/cmd  ls
check.lua      health.lua     init.lua       prepare.lua    reload.lua     roar.lua       stop.lua       version.lua
config.lua     hybrid.lua     migrations.lua quit.lua       restart.lua    start.lua      utils
# 进到utils 目录后,发现了nginx_signals.lua, 正是自己期望的,做了一个 nginx_signals.lua.bak 备份,修改原文件配置即可
 /usr/local/share/lua/5.1/kong/cmd  cd utils
 /usr/local/share/lua/5.1/kong/cmd/utils  ls
env.lua               log.lua               nginx_signals.lua     prefix_handler.lua
kill.lua              migrations.lua        nginx_signals.lua.bak tty.lua
 tangfeng@MacBook-Pro  /usr/local/share/lua/5.1/kong/cmd/utils 

在/usr/local/share/lua/5.1/kong/cmd/utils 中发现了 配置nginx的目录,然后同理查找openrestiy的安装目录,找到nginx的所在路径进行配置即可

local nginx_search_paths = {
  --"/usr/local/openresty/nginx/sbin",
  --"/opt/openresty/nginx/sbin",
  -- "/usr/local/bin", -- 这个是我单独装的nginx 路径,配置后也是启动不了,
    "/usr/local/Cellar/openresty/1.15.8.3_1/nginx/sbin" -- 最后配置openresty的nginx,解决问题
}

如上操作完成后,终于能正常启动了

# 启动kong 
kong start -c /etc/kong/kong.conf

用brew 安装不好的地方,在于,我们不知道它都是安装到哪些目录了,影响了既有的什么,这个有点坑。

 

你可能感兴趣的:(网关,架构,API网关,kong,微服务网关,熔断)