apisix源码分析-启动(1)

apisix源码分析-启动(1)

启动

1
2
3
4
5
6
7
8
9
/bin/apisix
/cli/
apisix.lua
env.lua
etcd.lua
file.lua
ngx_tpl.lua
ops.lua
util.lua

执行 /bin/apisix $* 实际执行 lua apisix/cli/apisix.lua $*

cli

`apisix.lua` :
  1. env.lua 环境变量
1
2
3
4
5
6
7
apisix_home : apisixe 安装目录
is_root_path : 是否为 root 目录
openresty_args : openresty 启动
openresty -p apisix_home -c apisix_home/conf/nginx.conf
pkg_cpath_org:
pkg_path_org :
min_etcd_version : etcd 版本
1. `ops.lua` :执行启动关闭等 ops.execute(env,arg) 在执行 `apisix start | stop | quit | restart | reload` 会调用 openresty 的执行命令,比如 `apisix reload` 会执行 `openresty -c nginx.conf -s reload`

apisix init

cli/ops/init()

负责读取检查准备apisix配置文件,

- 检查yaml配置文件
- 检查admin key
- 检查 openresty 版本
- 检查插件列表
- 检查promtheus
- 检查多端口
- 检查 ssl
- ...

所有检查的内容会存储在 sys_conf 的变量里,通过模版变量替换。

cli/ngx_tpl.lua 生成 conf/nginx.conf 文件,

1
2
3
4
local conf_render = template.compile(ngx_tpl)
local ngxconf = conf_render(sys_conf)
local ok, err = util.write_file(env.apisix_home .. "/conf/nginx.conf",
ngxconf)

apisix init_etcd : etcd.lua

检查 etcd 的版本,验证授权信息

以上就是 cli 启动的过程,总结就是检查运行环境,通过配置文件生成 nginx.conf 。

apisix源码分析-启动(1)

https://beixiu.net/apisix-source-1/

作者

张巍

发布于

2023-08-16

更新于

2023-08-16

许可协议

评论