安装依赖

注意

  • Apache APISIX 从 v2.0 开始不再支持 v2 版本的 etcd,并且 etcd 最低支持版本为 v3.4.0,因此请使用 etcd 3.4.0+。更重要的是,因为 etcd v3 使用 gRPC 作为消息传递协议,而 Apache APISIX 使用 HTTP(S) 与 etcd 集群通信,因此请确保启用 etcd gRPC gateway 功能。

  • 目前 Apache APISIX 默认使用 HTTP 协议与 etcd 集群通信,这并不安全,如果希望保障数据的安全性和完整性。 请为您的 etcd 集群配置证书及对应私钥,并在您的 Apache APISIX etcd endpoints 配置列表中明确使用 https 协议前缀。请查阅 conf/config-default.yaml 中 etcd 一节相关的配置来了解更多细节。

  • 如果你要想使用 Tengine 替代 OpenResty,请参考 Install Tengine at Ubuntu

  • 如果是 OpenResty 1.19,APISIX 会使用 OpenResty 内置的 LuaJIT 来运行 bin/apisix;否则会使用 Lua 5.1。如果运行过程中遇到 luajit: lj_asm_x86.h:2819: asm_loop_fixup: Assertion '((intptr_t)target & 15) == 0' failed,这是低版本 OpenResty 内置的 LuaJIT 在特定编译条件下的问题。

  • 在某些平台上,通过包管理器安装 LuaRocks 会导致 Lua 被升级为 Lua 5.3,所以我们建议通过源代码的方式安装 LuaRocks。如果你通过官方仓库安装 OpenResty 和 OpenResty 的 OpenSSL 开发库(rpm 版本:openresty-openssl111-devel,deb 版本:openresty-openssl111-dev),那么 我们提供了自动安装的脚本。如果你是自己编译的 OpenResty,可以参考上述脚本并修改里面的路径。如果编译时没有指定 OpenSSL 库的路径,那么无需配置 LuaRocks 内跟 OpenSSL 相关的变量,因为默认都是用的系统自带的 OpenSSL。如果编译时指定了 OpenSSL 库,那么需要保证 LuaRocks 的 OpenSSL 配置跟 OpenResty 的相一致。

  • 警告:如果你正在使用低于 1.17.8 的 OpenResty 版本,请安装 openresty-openssl-devel,而不是 openresty-openssl111-devel。

CentOS 7

  1. # 安装 etcd
  2. wget https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
  3. tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \
  4. cd etcd-v3.4.13-linux-amd64 && \
  5. sudo cp -a etcd etcdctl /usr/bin/
  6. # 添加 OpenResty 源
  7. sudo yum install yum-utils
  8. sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
  9. # 安装 OpenResty 和 编译工具
  10. sudo yum install -y openresty curl git gcc openresty-openssl111-devel unzip
  11. # 安装 LuaRocks
  12. curl https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh -sL | bash -
  13. # 开启 etcd server
  14. nohup etcd &

Fedora 31 & 32

  1. # 添加 OpenResty 源
  2. sudo yum install yum-utils
  3. sudo yum-config-manager --add-repo https://openresty.org/package/fedora/openresty.repo
  4. # 安装 etcd
  5. wget https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
  6. tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \
  7. cd etcd-v3.4.13-linux-amd64 && \
  8. sudo cp -a etcd etcdctl /usr/bin/
  9. # 安装 OpenResty 和 编译工具
  10. sudo yum install -y openresty curl git gcc openresty-openssl111-devel
  11. # 安装 LuaRocks
  12. curl https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh -sL | bash -
  13. # 开启 etcd server
  14. nohup etcd &

Ubuntu 16.04 & 18.04

  1. # 添加 OpenResty 源
  2. wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
  3. sudo apt-get update
  4. sudo apt-get -y install software-properties-common
  5. sudo add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main"
  6. sudo apt-get update
  7. # 安装 etcd
  8. wget https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
  9. tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \
  10. cd etcd-v3.4.13-linux-amd64 && \
  11. sudo cp -a etcd etcdctl /usr/bin/
  12. # 安装 OpenResty 和 编译工具
  13. sudo apt-get install -y git openresty curl openresty-openssl111-dev make gcc
  14. # 安装 LuaRocks
  15. curl https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh -sL | bash -
  16. # 开启 etcd server
  17. nohup etcd &

Debian 9 & 10

  1. # 可选
  2. sed -i 's|^deb http://deb.debian.org/debian|deb http://mirrors.huaweicloud.com/debian|g' /etc/apt/sources.list
  3. sed -i 's|^deb http://security.debian.org/debian-security|deb http://mirrors.huaweicloud.com/debian-security|g' /etc/apt/sources.list
  4. apt update
  5. apt install wget gnupg -y
  6. # 添加 OpenResty 源
  7. wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
  8. sudo apt-get -y install software-properties-common
  9. sudo add-apt-repository -y "deb http://openresty.org/package/debian $(lsb_release -sc) openresty"
  10. sudo apt-get update
  11. # 安装 etcd
  12. wget https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
  13. tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \
  14. cd etcd-v3.4.13-linux-amd64 && \
  15. sudo cp -a etcd etcdctl /usr/bin/
  16. # 安装 OpenResty 和 编译工具
  17. sudo apt-get install -y git openresty curl make openresty-openssl111-dev
  18. # 安装 LuaRocks
  19. curl https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh -sL | bash -
  20. # 开启 etcd server
  21. nohup etcd &

Mac OSX

  1. # 安装 OpenResty, etcd 和 编译工具
  2. brew install openresty/brew/openresty luarocks lua@5.1 etcd curl git
  3. # 开启 etcd server
  4. brew services start etcd
  5. # 为 etcd 服务启用 TLS
  6. etcd --cert-file=/path/to/cert --key-file=/path/to/pkey --advertise-client-urls https://127.0.0.1:2379