如何构建 Apache APISIX

    所以在安装前,请根据不同的操作系统来安装依赖

    2. 安装 Apache APISIX

    你可以通过源码包、Docker、Luarocks 等多种方式来安装 Apache APISIX。

    你需要先下载 Apache Release 源码包:

    安装运行时依赖的 Lua 库:

    1. make deps
    1. sudo sh -c "$(curl -fsSL https://raw.githubusercontent.com/apache/apisix/master/utils/install-apisix.sh)"

    通过 Luarocks 安装指定的版本:

    我们可以在 apisix 的目录下用 make run 命令来启动服务,或者用 make stop 方式关闭服务。

    1. # init nginx config file and etcd
    2. $ make init
    3. # start APISIX server
    4. $ make run
    5. # stop APISIX server
    6. $ make stop
    7. # more actions find by `help`
    8. $ make help
    9. Makefile rules:
    10. deps: Installation dependencies
    11. utils: Installation tools
    12. lint: Lint Lua source code
    13. init: Initialize the runtime environment
    14. run: Start the apisix server
    15. stop: Stop the apisix server
    16. verify: Verify the configuration of apisix server
    17. clean: Remove generated files
    18. reload: Reload the apisix server
    19. install: Install the apisix (only for luarocks)
    20. test: Run the test case
    21. license-check: Check Lua source code for Apache License

    4. 运行测试案例

    1. 先安装 perl 的包管理器 cpanminus
    2. 然后通过 cpanm 来安装 test-nginx 的依赖:sudo cpanm --notest Test::Nginx IPC::Run > build.log 2>&1 || (cat build.log && exit 1)
    3. 然后 clone 最新的源码:git clone https://github.com/iresty/test-nginx.git。注意使用我们 fork 出来的版本。
    4. 通过 perl 的 prove 命令来加载 test-nginx 的库,并运行 /t 目录下的测试案例集:
      • 直接运行:
      • 指定 nginx 二进制路径:TEST_NGINX_BINARY=/usr/local/bin/openresty prove -Itest-nginx/lib -r t

    配置 Nginx 路径

    • export PATH=/usr/local/openresty/nginx/sbin:$PATH
      • Linux 默认安装路径:
        • export PATH=/usr/local/openresty/nginx/sbin:$PATH
      • OSx 通过homebrew默认安装路径:
        • export PATH=/usr/local/opt/openresty/nginx/sbin:$PATH

    运行单个测试用例

    • 使用以下命令运行指定的测试用例:
      • prove -Itest-nginx/lib -r t/plugin/openid-connect.t

    修改 conf/config.yaml 中的 apisix.admin_key 并重启服务。例如下面例子:

    当我们需要访问 Admin API 时,就可以使用上面记录的 key 作为 token 了。

    1. $ curl http://127.0.0.1:9080/apisix/admin/routes?api_key=abcdefghabcdefgh -i
    2. HTTP/1.1 200 OK
    3. Date: Fri, 28 Feb 2020 07:48:04 GMT
    4. Content-Type: text/plain
    5. ... ...
    6. {"node":{...},"action":"get"}
    7. $ curl http://127.0.0.1:9080/apisix/admin/routes?api_key=abcdefghabcdefgh-invalid -i
    8. HTTP/1.1 401 Unauthorized
    9. Date: Fri, 28 Feb 2020 08:17:58 GMT
    10. Content-Type: text/html
    11. ... ...

    6. 为 APISIX 构建 OpenResty

    有些功能需要你引入额外的 Nginx 模块到 OpenResty 当中。 如果你需要这些功能,你可以用这个脚本 构建 OpenResty。