安装 OpenResty Edge

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 的指标和日志数据。

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 硬盘。

如果是超过 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

3.2 OpenResty Edge Admin Database 安装

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

3.2.1 安装

  • 复制 openresty-edge-VERSION.tar.gzopenresty-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 验证安装

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

    sudo systemctl status openresty-postgresql12
    

    journalctl -u openresty-postgresql12
    

3.3 OpenResty Edge Admin 安装

Edge Admin 机器需要开放 44312345 两个端口,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 的方式进行访问管理后台。

    [+] 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 验证安装

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

    sudo systemctl status openresty-postgresql12
    

    journalctl -u openresty-postgresql12
    

3.5 OpenResty Edge Log Server 安装

Log Server 机器需要开放 123468089 两个端口,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 会随机使用 hosthost2(与配置顺序无关),并且当某一个 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。

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

    -a, --action                install, upgrade, downgrade, uninstall.
    -c, --component             admin, log-server, node, log-server-db, admin-db, rebuild, clean-db.
    -p, --plus-version          use in downgrade, example: 1.19.3.1.36-1.
    -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.
    -l, --log-server-host       specify log server host, which can be used when installing node and admin.
        --backup-db             if exist, will backup db when upgrade admin db.
    -b, --listen-ip             specify the listen ip when install edge node, install edge admin or upgrade edge admin.
    -u, --skip-db-sec-config    do not change the database's default listening address, nor alter the default postgres user's password, etc.
    -h, --help                  help info.

5. 数据库备份以及高可用(可选)

我们提供了两种方式(数据库备份,数据库高可用)来保证数据安全,在数据库损坏之后可以利用备份文件或者从库恢复数据。我们强烈建议两种方式都采用,最大限度保障数据安全。

数据库备份

数据库高可用

6. 开始使用

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

7. 更多

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