安装 OpenResty Edge

OpenResty Edge 主要包含三个角色(OpenResty Edge Admin,OpenResty Edge Log Server, OpenResty Edge Node),三者的关系如下图: OpenResty Edge Admin:简称 Edge Admin,用于控制管理.

1. 架构说明

OpenResty Edge 主要包含三个角色(OpenResty Edge Admin,OpenResty Edge Log Server, OpenResty Edge Node),三者的关系如下图:

  • OpenResty Edge Admin:简称 Edge Admin,用于控制管理 OpenResty Edge Node。

  • OpenResty Edge Log Server:简称 Log Server,用于指标,日志的存储和查看。

  • OpenResty Edge Node:简称 Edge Node,是具体的网关服务器,承载用户流量。

此外还包含两个数据存储角色:

  • OpenResty Edge Admin Database:简称 Edge Admin Database,是 Edge Admin 所使用的数据库,用于持久化 Edge Node 的配置。

  • OpenResty Edge Log Server Database:简称 Log Server Database,是 Log Server 所使用的数据库,用于持久化 Edge Node 的指标和日志数据。

更多端口信息请见《OpenResty Edge™ 组件端口说明》。

2. 配置推荐

正式环境安装 OpenResty Edge 至少需要三台机器,分别安装 Edge Admin,Log Server 和 Edge Node 组件。

如果是测试环境,Edge Admin 和 Log Server 也可以安装在同一台机器上,以节省机器资源。

对于规模在 10 个节点以内的 OpenResty Edge 集群,我们推荐:

  • Edge Admin:至少使用 4 核处理器,16G 内存以及 200G SSD 硬盘的机器。

  • Log Server:至少使用 4 核处理器,16G 内存以及 200G SSD 硬盘的机器。

  • Edge Node:相对灵活,取决于业务量,大致是 1 个处理器核心搭配 2G 内存,越大越好。比如 8 核 16 GB 内存,200G 硬盘。

  • Edge Admin Database:至少使用 4 核处理器,16G 内存以及 200G SSD 硬盘的机器。

  • Log Server Database:至少使用 4 核处理器,16G 内存以及 500G 或 1T SSD 硬盘的机器。如果会开启较多动态指标、WAF 日志、DDos 日志等,可使用更大的硬盘空间。

如果是超过 10 个节点的集群,需要根据实际场景升级配置,如果是更大规模的集群,还可以将 Edge Admin Database 和 Log Server Database 部署到单独的机器,如下图所示:

为了保证数据安全,我们建议按照数据库备份以及高可用这一章节进行配置。

3. 安装流程

如果您想要进行在线安装(推荐),请准备以下文件:

  • openresty-edge-VERSION.tar.gz:包含 OpenResty Edge 的配置包及初始化数据。

如果您想要使用 bundle 包进行安装,请准备以下文件:

  • openresty-edge-bundle-VERSION.tar.gz:包含 OpenResty Edge 的业务包、配置包及初始化数据等。旧名称是 openresty-edge-bundle-VERSION.tar.gz。

这两个文件会在下载中心中提供,如果没有请与我们联系。

3.1 前置准备

  • 设置防火墙白名单

    Edge Admin,Edge Node, Log Server 所在机器都会访问以下公网地址,用于下载软件以及授权信息的同步,如果有网络出口防火墙,需要开启白名单允许访问这些地址:

    openresty.com 443
    openresty.org 443
    pkg.openresty.com 443
    api.openresty.com 443
    
  • 开启系统时间同步

    建议您为所有 Edge 组件启用 NTP(网络时间协议)服务进行系统时间同步。这可以有效防止组件间的时间不一致,从而避免证书续期失败或配置下发出错等问题。

3.2 OpenResty Edge Admin Database 安装

如果 Edge Admin 和 Edge Admin Database 分别部署在两台机器上,Edge Admin Database 所在机器还需要对 Edge Admin 开放 5432 端口。

3.2.1 安装

  • 复制 openresty-edge-VERSION.tar.gz 或 openresty-edge-bundle-VERSION.tar.gz 压缩包到当前目录

  • 解压缩

    tar -xvf openresty-edge-VERSION.tar.gz
    

    或

    tar -xvf openresty-edge-bundle-VERSION.tar.gz
    
  • 运行安装器

    cd openresty-edge-VERSION
    sudo /bin/bash openresty-edge-installer.sh
    

    或

    cd openresty-edge-bundle-VERSION
    sudo /bin/bash openresty-edge-installer.sh
    
  • 输入您要执行的操作 Install

    > Checking network...
    > Welcome to the OpenResty Edge Installer.
    [1] Install
    [2] Upgrade
    [3] Downgrade
    [4] Uninstall
    [5] Self Check
    [6] Get Default Info
    What would you like to do? 1
    > You chose: Install.
    
  • 输入您要安装的版本 (可以从 变更日志 获取最新的版本信息),如果使用安装器中的默认版本,可以直接回车

    Which version would you like to install? (Default: 23.12.1, Press Enter to use the default version)
    
  • 输入您要安装的组件 Edge Admin Database

    [1] Edge Admin Database
    [2] Edge Log Server Database
    [3] Edge Admin
    [4] Edge Log Server
    [5] Edge Node
    Which component would you like to install? 1
    > You chose: Edge Admin Database.
    
  • 输入允许进行远程访问数据库的 IP 列表,用空格分割;仅允许本地访问则直接回车。如果您的数据库和 Edge Admin 不在同一台机器上,则应输入 Edge Admin 的 IP 地址

    [+] Please enter the list of IP addresses allowed for remote database access (default: 127.0.0.1/32 ::1/128):
    
  • 为默认数据库用户 postgres 设置密码,请牢记这个密码。该数据库用户默认没有密码

    [+] Please enter the password for the database user "postgres", or press Enter to continue without setting a password:
    [+] Please confirm the password for the database user "postgres":
    

3.2.2 验证安装

  • 可以通过以下命令来服务是否正常启动

    # 对于 PostgreSQL 15
    sudo systemctl status openresty-postgresql15
    
    # 对于 PostgreSQL 12
    sudo systemctl status openresty-postgresql12
    

    或

    # 对于 PostgreSQL 15
    journalctl -u openresty-postgresql15
    
    # 对于 PostgreSQL 12
    journalctl -u openresty-postgresql12
    

3.3 OpenResty Edge Admin 安装

Edge Admin 机器需要开放 443 和 12345 两个端口,443 端口用于访问 Edge Admin 管理后台,12345 端口用于与 Edge Node 组件通讯。

3.3.1 安装

  • 操作步骤和前面类似,在安装时组件选择 Edge Admin

    [1] Edge Admin Database
    [2] Edge Log Server Database
    [3] Edge Admin
    [4] Edge Log Server
    [5] Edge Node
    Which component would you like to install? 3
    > You chose: Edge Admin.
    
  • 配置证书和私钥

    此证书用于访问 Edge Admin 管理后台,配置此证书后可以使用域名的方式来访问 Edge Admin 管理后台。 证书可以通过 Let’s Encrypt,ZeroSSL 等 SSL 证书提供商处获取,也可以通过 openssl 工具来生成自签证书。 如果你还没有证书,则可以先跳过,此时使用的将是 OpenResty Edge 默认的自签证书,后面只能通过 IP 的方式进行访问管理后台。 后续有需要变更此证书时,你可以手动替换 /usr/local/oredge-admin/conf/ssl/ssl.crt 和 /usr/local/oredge-admin/conf/ssl/ssl.key。

    [+] Do you want to configure ssl certificate and private key? [y/N] y
    [-] Please enter the path of ssl certificate file (like /etc/ssl/ssl.crt): /home/user/ssl/ssl.crt
    [-] Please enter the path of ssl key file (like /etc/ssl/ssl.key): /home/user/ssl/ssl.key
    
  • 配置 Database 和 Log Server 地址:(如果 Database, Edge Admin, Log Server 复用同一个机器,可以直接使用默认配置)

    [+] Do you want to configure admin database and log server address (/usr/local/oredge-admin/conf/config.ini)? [y/N] y
    [-] Please enter the address of admin database (if admin database and admin use the same machine, no need to input.):
    [-] Please enter the address of log server (if log server and admin use the same machine, no need to input.): 54.112.79.32
    

    请确保当前服务器与所输入的 IP 是联通的。

  • 如果成功,最后会有如下提示,包含了 Edge Admin 的登录密码

    > Install OpenResty Edge admin successfully! login username: admin , password: xxxxxxxxxxx .
    

3.3.2 验证安装

  • 可以通过以下命令来查看进程是否启动:

    sudo systemctl status oredge-admin
    
  • 还可以检查 Edge Admin 的日志中是否有异常信息,日志目录为 /usr/local/oredge-admin/logs,可通过以下命令获取最新的日志内容

    sudo ls -rt /usr/local/oredge-admin/logs/error* | tail -n1 | xargs -I {} sudo tail -n 50 {}
    

此时 Edge Admin 可以正常使用了,可以通过 https://your_domain/ 访问管理后台。

如果前面未配置证书,则使用的是我们提供的自签证书,只能通过 https://admin_ip/ 访问,还需要忽略浏览器的证书错误提示才能正常访问。

3.4 OpenResty Edge Log Server Database 安装

3.4.1 安装

  • 操作步骤和前面类似,安装时组件选择 Log Server Database

    [1] Edge Admin Database
    [2] Edge Log Server Database
    [3] Edge Admin
    [4] Edge Log Server
    [5] Edge Node
    Which component would you like to install? 2
    > You chose: Edge Log Server Database.
    
  • 输入允许进行远程访问数据库的 IP 列表,用空格分割;仅允许本地访问则直接回车。如果您的数据库和 Edge Log Server 不在同一台机器上,则应输入 Edge Log Server 的 IP 地址

    [+] Please enter the list of IP addresses allowed for remote database access (default: 127.0.0.1/32 ::1/128):
    
  • 为默认数据库用户 postgres 设置密码,请牢记这个密码。该数据库用户默认没有密码

    [+] Please enter the password for the database user "postgres", or press Enter to continue without setting a password:
    [+] Please confirm the password for the database user "postgres":
    

3.4.2 验证安装

  • 可以通过以下命令来查看进程是否启动:

    注意:对于 openresty-postgresql15 或其他数据库版本,请使用相应的服务名称。

    # 对于 PostgreSQL 15
    sudo systemctl status openresty-postgresql15
    
    # 对于 PostgreSQL 12
    sudo systemctl status openresty-postgresql12
    

    或

    # 对于 PostgreSQL 15
    journalctl -u openresty-postgresql15
    
    # 对于 PostgreSQL 12
    journalctl -u openresty-postgresql12
    

3.5 OpenResty Edge Log Server 安装

Log Server 机器需要开放 12346 和 8089 两个端口,12346 端口用于与 Edge Node 端通讯,8089 用于与 Edge Admin 通讯。

3.5.1 安装

  • 操作步骤和前面类似,安装时组件选择 Log Server

    [1] Edge Admin Database
    [2] Edge Log Server Database
    [3] Edge Admin
    [4] Edge Log Server
    [5] Edge Node
    Which component would you like to install? 4
    > You chose: Edge Log Server.
    
  • 配置 Log Server Database 和 Edge Admin 地址:(如果 Log Server Database, Edge Admin, Log Server 复用同一个机器,可以直接使用默认配置)

    [+] Do you want to configure database and admin address (/usr/local/oredge-log-server/conf/config.ini)? [y/N] y
    [-] Please enter the address of log server database (if log server database and log server use the same machine, no need to input.):
    [-] Please enter the address of admin (if admin and log server use the same machine, no need to input.): 45.121.32.78
    

    请确保当前服务器与所输入的 IP 是联通的。

  • 如果成功,最后会有如下提示

    > Install OpenResty Edge Log Server successfully!
    

3.5.2 验证安装

  • 可以通过以下命令来查看进程是否启动:

    sudo systemctl status oredge-log-server
    
  • 还可以检查 Log Server 的日志中是否有异常信息,日志目录为 /usr/local/oredge-log-server/logs,日志会按照日期轮转,可通过以下命令获取最新的日志内容

    sudo ls -rt /usr/local/oredge-log-server/logs/error* | tail -n1 | xargs -I {} sudo tail -n 50 {}
    

3.6 OpenResty Edge Node 安装

3.6.1 安装

  • 操作步骤和前面类似,安装时组件选择 Edge Node

    [1] Edge Admin Database
    [2] Edge Log Server Database
    [3] Edge Admin
    [4] Edge Log Server
    [5] Edge Node
    Which component would you like to install? 5
    > You chose: Edge Node.
    
  • 配置 Edge Admin 和 Log Server 地址:

    [+] Do you want to configure admin and log server address (/usr/local/oredge-node/conf/config.ini)? [y/N] y
    [-] Please enter the address of admin: 54.212.32.78
    [-] Please enter the address of log server: 54.212.32.78
    

    请确保当前服务器与所输入的 IP 是联通的。

  • 如果成功,最后会有如下提示

    > Install OpenResty Edge Node successfully!
    

3.6.2 验证安装

  • 可以通过以下命令来查看进程是否启动:

    sudo systemctl status oredge-node
    
  • 还可以检查 Edge Node 的日志中是否有异常信息,日志目录为 /usr/local/oredge-node/logs,可通过以下命令获取最新的日志内容

    sudo ls -rt /usr/local/oredge-node/logs/error* | tail -n1 | xargs -I {} sudo tail -n 50 {}
    

    如果日志中有以下输出,表明 Edge Node 已经成功连上 Edge Admin,在 Edge Admin 管理后台中批准节点加入即可正常使用。可以参考网关集群。

    2021/11/16 14:37:38 [error] 6882#6882: *51983 [lua] privileged.lua:819: could not establish node identity: not yet approved, context: ngx.timer
    

至此全套的 OpenResty Edge 已经搭建完毕。

3.7 配置两份 OpenResty Edge Admin 服务(可选)

如果希望提高 Edge Admin 服务的可用性,可以考虑部署两份 Edge Admin 服务,配置为双主。 步骤是:

  • 按照上面的步骤 3.3 再安装一套 Edge Admin 软件

  • 修改 Edge Admin 配置

    # 这个文件后续的升级也不会自动覆盖,请注意行首不要留空格
    sudo vim /usr/local/oredge-admin/conf/config.ini
    

    需要修改 clone_admin 下的 host 字段,每个 Edge Admin 配置另外一个 Edge Admin 服务的地址。

    修改后重启 Edge Admin 服务:

    sudo systemctl start upgrade-oredge-admin
    

    此时两个 Edge Admin 服务是双主模式,访问任意一个 Edge Admin 都是一样的效果。

  • 修改 Edge Node 配置

    # 这个文件后续的升级也不会自动覆盖,请注意行首不要留空格
    sudo vim /usr/local/oredge-node/conf/config.ini
    

    修改配置文件 admin 段下的 host2 字段,配置成另一个 Edge Admin 的地址。

    修改后重启 Edge Node 服务:

    sudo systemctl start upgrade-oredge-node
    

    Edge Node 会随机使用 host 和 host2(与配置顺序无关),并且当某一个 Edge Admin 宕机的时候,会自动切换到另外一个 Edge Admin 服务。

3.8 配置 OpenResty Edge Log Server 多实例(可选)

如果希望提高 Log Server 服务的可用性,可以考虑部署多个 Log Server 实例。支持多 Log Server 实例需要 OpenResty Edge 的版本等于或者高于 23.12.1。具体步骤如下:

  • 按照上面的步骤 3.5 再安装其他的 Log Server 实例

  • 修改 Edge Admin 配置

    # 这个文件后续的升级也不会自动覆盖,请注意行首不要留空格
    sudo vim /usr/local/oredge-admin/conf/config.ini
    

    修改 log_server 下的 endpoints 字段,添加新部署的实例连接地址,比如:

    [log_server]
    endpoints = "https://192.168.0.2:12346, https://192.168.0.3:12346"
    

    修改后重启 Edge Admin 服务:

    sudo systemctl start upgrade-oredge-admin
    

    Edge Admin 会随机使用配置的 Log Server 实例,这与配置的顺序无关,当某个 Log Server 宕机的时候,会自动切换到其他可用的 Log Server 服务。

  • 修改 Edge Node 配置

    # 这个文件后续的升级也不会自动覆盖,请注意行首不要留空格
    sudo vim /usr/local/oredge-node/conf/config.ini
    

    修改 log_server 下的 endpoints 字段,添加新部署的实例连接地址,比如:

    [log_server]
    endpoints = "https://192.168.0.2:12346, https://192.168.0.3:12346"
    

    修改后重启 Edge Node 服务:

    sudo systemctl start upgrade-oredge-node
    

    Edge Node 会随机使用配置的 Log Server 实例,这与配置的顺序无关,当某个 Log Server 宕机的时候,会自动切换到其他可用的 Log Server 服务。

3.9 使用安装器进行自检

$ bash openresty-edge-installer.sh
> Checking network...
> Welcome to the OpenResty Edge Installer.
[1] Install
[2] Upgrade
[3] Downgrade
[4] Uninstall
[5] Self Check
[6] Get Default Info
What would you like to do? 5
> You chose: Self Check.

3.10 使用安装器获取 Edge Admin 的默认登录信息

$ bash openresty-edge-installer.sh
> Checking network...
> Welcome to the OpenResty Edge Installer.
[1] Install
[2] Upgrade
[3] Downgrade
[4] Uninstall
[5] Self Check
[6] Get Default Info
What would you like to do? 6
> You chose: Get Default Info.
If you have initialized the OpenResty Edge Admin database using the current installer, then the information to log in to the Edge Admin Console is as follows:

    username: admin
    password: xxxxxxxxxxxxxxx

4. 自动化安装 OpenResty Edge

你也可以使用非交互式的安装方式来安装 OpenResty Edge。

示例 1:

sudo bash openresty-edge-installer.sh -a install -c node -v 23.12.1 -m 192.168.10.1 -l 192.168.10.2

安装 23.12.1 版本的 OpenResty Edge Node,并修改配置文件中 Edge Admin Host 和 Log Server Host 对应的配置。

示例 2:

sudo bash openresty-edge-installer.sh -a install -c admin -v 23.12.1 -d 192.168.10.3 -l 192.168.10.2 -s /tmp/cert.crt -k /tmp/key.crt

安装 23.12.1 版本的 OpenResty Edge Admin,修改配置文件中 Database Host 和 Log Server Host 对应的配置,并配置 Edge Admin 管理页面的 SSL 证书为 /tmp/cert.crt 和 /tmp/key.crt。

示例 3:

ver=25.12.7
sudo bash openresty-edge-installer.sh -a install -c admin-db -v $ver
sudo bash openresty-edge-installer.sh -a install -c admin -v $ver -i -l 127.0.0.1 -d 127.0.0.1
sudo sed -i 's/listen 443 backlog=4096 reuseport ssl;/listen 444 backlog=4096 reuseport ssl;/' /usr/local/oredge-admin/conf/nginx.conf
sudo systemctl reload oredge-admin
sudo bash openresty-edge-installer.sh -a install -c log-server-db -v $ver
sudo bash openresty-edge-installer.sh -a install -c log-server -v $ver -d 127.0.0.1
sudo bash openresty-edge-installer.sh -a install -c node -v $ver -m 127.0.0.1 -l 127.0.0.1
sudo bash openresty-edge-installer.sh -a get -c default-info

在同一个节点上安装整套 OPenResty Edge 软件,包括: OpenResty Edge-Admin, OpenResty Edge-Node, OpenResty Edge-Admin-DB, OpenResty Edge-Logserver-DB, OpenResty Edge-Logserver。

openresty-edge-installer.sh 当前支持以下参数:

    -a, --action                action (install|upgrade|downgrade|uninstall|self-check|get|backup|restore|upgrade-db-server).
    -c, --component             component (admin|log-server|node|log-server-db|admin-db|waf-rules|rebuild|default-info).
    -v, --version               edge version, example: 25.12.7, 25.12.7-1.
        --db-version                new database server version to upgrade to (9.6.20|12.5|15.9).
        --db-tsdb-version           new database timescaledb version to upgrade to (1.7.4|2.10.3).
    -d, --db-host               specify database host, which can be used when installing admin and log server.
    -m, --admin-host            specify admin host, which can be used when installing node.
    -s, --admin-ssl-cert-path   specify ssl cert path for admin console.
    -k, --admin-ssl-key-path    specify ssl key path for admin console.
    -i, --admin-ssl-skip        skip configuration of admin ssl certificate.
        --db-name               specify database name for admin or log server database.
    -l, --log-server-host       specify log server host, which can be used when installing node and admin.
        --backup-db             the database will be backed up when upgrading Admin DB. This option has higher priority than --no-backup-db.
        --no-backup-db          the database will not be backed up when upgrading Admin DB.
    -b, --listen-ip             specify the listen ip when install edge node, install edge admin or upgrade edge admin.
        --db-remote-access-ip   specify the list of IP addresses allowed for remote database access (default: 127.0.0.1/32 ::1/128).
    -u, --skip-db-sec-config    do not change the database's default listening address, nor alter the default postgres user's password, etc.
    -r, --history-dir           specify the directory to store current operation records.
        --overwrite-history-dir whether to overwrite the history directory if it exists.
        --backup-dir            when action is "backup", backup data will be stored in this directory. If not specified, it will be stored in the working directory.
        --restore-dir           specify the directory to restore the database.
        --downgrade-dir         specify the directory to downgrade the admin, node or log-server component.
    -x                          trace mode.
    -y, --yes                   skip all confirmations and use default values
    -h, --help                  help info.

5. 数据库高可用(可选)

我们还提供了搭建数据库集群的文档,这样当主数据库不可用时,从数据库就会自动升级为主数据库。

有关搭建数据库群集的文档,请点击此处: 数据库集群

6. 数据库备份(可选)

为确保数据安全,我们建议定期备份数据库。

有关数据库备份的文档,请点击此处: 数据库备份

7. 开始使用

我们提供有在线的文档, 还有相关博客及对应视频。

8. 更多

有问题请与我们随时沟通!