Apache APISIX 的运行环境需要 Nginx 和 etcd,
所以在安装前,请根据不同的操作系统来安装依赖。
你可以通过源码包、Docker、Luarocks 等多种方式来安装 Apache APISIX。
sudo yum install -y https://github.com/apache/apisix/releases/download/2.5/apisix-2.5-0.x86_64.rpm
见 https://hub.docker.com/r/apache/apisix
见 https://github.com/apache/apisix-helm-chart
你需要先下载 Apache Release 源码包:
$ mkdir apisix-2.5 $ wget https://downloads.apache.org/apisix/2.5/apache-apisix-2.5-src.tgz $ tar zxvf apache-apisix-2.5-src.tgz -C apisix-2.5
安装运行时依赖的 Lua 库:
cd apisix-2.5 make deps
我们可以在 apisix 的目录下用 make run
命令来启动服务,或者用 make stop
方式关闭服务。
# init nginx config file and etcd $ make init # start APISIX server $ make run # stop APISIX server $ make stop # more actions find by `help` $ make help Makefile rules: help: Show Makefile rules deps: Installation dependencies utils: Installation tools lint: Lint Lua source code init: Initialize the runtime environment run: Start the apisix server stop: Stop the apisix server verify: Verify the configuration of apisix server clean: Remove generated files reload: Reload the apisix server install: Install the apisix (only for luarocks) test: Run the test case license-check: Check Lua source code for Apache License
sudo cpanm --notest Test::Nginx IPC::Run > build.log 2>&1 || (cat build.log && exit 1)
git clone https://github.com/iresty/test-nginx.git
。注意使用我们 fork 出来的版本。prove
命令来加载 test-nginx 的库,并运行 /t
目录下的测试案例集:export PERL5LIB=.:$PERL5LIB
make test
TEST_NGINX_BINARY=/usr/local/bin/openresty prove -Itest-nginx/lib -r t
配置 Nginx 路径
如果遇到问题 Error unknown directive "lua_package_path" in /API_ASPIX/apisix/t/servroot/conf/nginx.conf
确保将openresty设置为默认的nginx并按如下所示导出路径。
运行单个测试用例
修改 conf/config.yaml
中的 apisix.admin_key
并重启服务。例如下面例子:
apisix: # ... ... admin_key - name: "admin" key: abcdefghabcdefgh role: admin
当我们需要访问 Admin API 时,就可以使用上面记录的 key 作为 token 了。
$ curl http://127.0.0.1:9080/apisix/admin/routes?api_key=abcdefghabcdefgh -i HTTP/1.1 200 OK Date: Fri, 28 Feb 2020 07:48:04 GMT Content-Type: text/plain ... ... {"node":{...},"action":"get"} $ curl http://127.0.0.1:9080/apisix/admin/routes?api_key=abcdefghabcdefgh-invalid -i HTTP/1.1 401 Unauthorized Date: Fri, 28 Feb 2020 08:17:58 GMT Content-Type: text/html ... ... {"node":{...},"action":"get"}
有些功能需要你引入额外的 Nginx 模块到 OpenResty 当中。 如果你需要这些功能,你可以用这个脚本 构建 OpenResty。