安装 OpenResty Edge
1. 架构说明
OpenResty Edge 主要包含三个角色(Node,Admin,Log-Server),三者的架构如下图:
- Node 承担具体的网关角色
- Admin 用于控制管理 Node
- Log-Server 主要用于处理日志:存储、查看
2. 集群配置
对于规模在 10 个节点左右的集群,我们推荐:
- Admin 和 Admin DB 部署在一台机器。
- Log Server 和 Log-Server DB 部署在一台机器上。
以后规模更大了,再分开部署。 同时为了数据安全,我们建议两个机器上分别起一个对方 DB 的从库:
- Admin DB 机器上起一个 Log Server DB 的从库。
- Log Server DB 机器上起一个 Admin DB 的从库。
Admin 和 Log-Server 端配置: 推荐使用配置是 4 核,16G 内存以及 200G SSD 硬盘的机器。 Node 端配置:相对灵活,取决于业务量,大致是 1 cpu core 搭配 2g 内存,比如 8c16g,200G 硬盘。
3. 安装流程
注意:安装前需要准备以下文件/信息:
openresty-edge-VERSION.tar.gz
3.1 设置防火墙白名单
我们会访问如下公网地址,如果贵司有网络出口防火墙的话,需要开启如下白名单
openresty.com 443
openresty.org 443
pkg.openresty.com 443
api.openresty.com 443
3.2 Admin DB 安装
内网端口需要开放 5432
。
复制
openresty-edge-VERSION.tar.gz
压缩包到当前目录解压缩
tar -xvf openresty-edge-VERSION.tar.gz
- 运行安装器
cd openresty-edge-VERSION
sudo /bin/bash openresty-edge-tool.sh
- 输入您要执行的操作
Install
What would you like to do?
[1] Install
[2] Upgrade
[3] Downgrade
[4] Uninstall
1
What you choose is: Install.
- 输入您要安装的版本 (可以从 变更日志 获取最新的版本信息)
Which version would you like to install? (like 22.6.1)
22.6.1
- 输入您要安装的组件
Admin DB
Which component would you like to install?
[1] Admin DB
[2] Log Server DB
[3] Admin
[4] Log Server
[5] Node
1
What you choose is: Admin DB.
- 如果成功,最后会有如下提示
Great! Init admin database successfully.
3.3 Log Server DB 安装
如果你正在构建的是生产环境,我们建议在不同的机器上安装 Admin DB 和 Log Server DB 。
- 操作步骤相同,安装时组件选择
Log Server DB
Which component would you like to install?
[1] Admin DB
[2] Log Server DB
[3] Admin
[4] Log Server
[5] Node
2
What you choose is: Log Server DB.
- 如果成功,最后会有如下提示
Great! Init log server database successfully.
3.4 Admin Web 安装
需要开放 443
和 12345
两个端口 (443
提供管理后台,12345
用于与 Node 端通讯)
- 操作步骤相同,安装时组件选择
Admin
Which component would you like to install?
[1] Admin DB
[2] Log Server DB
[3] Admin
[4] Log Server
[5] Node
3
What you choose is: Admin.
- 配置证书和私钥(没有也可以先跳过)
[+] Do you want to configure ssl certificate and private key? [y/N] y
[-] Please enter the path of ssl certificate file (like /usr/local/ssl.crt): /usr/local/ssl.crt
[-] Please enter the path of ssl key file (like /usr/local/ssl.key): /usr/local/ssl.key
- 配置 DB 和 Log-Server 地址:(如果 DB, Admin, Log-Server 复用同一个机器,可以直接使用默认配置)
[+] Do you want to configure pg and log server address (/usr/local/oredge-admin/conf/config.ini)? [y/N] y
[-] Please enter the address of pg server (if pg server 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
- 如果成功,最后会有如下提示
Install Edge admin successfully! login username: admin , passward: xxxxxxxxxxx .
此时 Admin 应该可以正常使用了(我们只开了 HTTPS) https://your-admin.com/
- 登录账号:
admin
- 获取登录密码:(安装 Admin 成功后已经提示)
grep -rs "password :" init_admin_db.sh
3.5 配置两份 admin-web 服务(可选)
如果希望提高 admin-web 的可用性,可以考虑部署两份 admin-web 服务,配置为双主。 步骤是:
按照上面的步骤 3.4 再安装一套 admin-web 软件
修改配置
# 这个文件后续的升级也不会自动覆盖,请注意行首不要留空格 sudo vim /usr/local/oredge-admin/conf/config.ini
需要修改 clone_admin 下的 host 字段,每个 admin-web 配置另外一个 admin-web 服务的地址。
修改后重启 admin-web 服务,此时两个 admin-web 服务是双主模式,访问任意一个 admin-web 都是一样的效果。
3.6 Log-Server 安装
需要开放 12346
和 8089
两个端口 (12346
用于与 Node 端通讯,8089
用于与 Admin 通讯)
- 操作步骤相同,安装时组件选择
Log Server
Which component would you like to install?
[1] Admin DB
[2] Log Server DB
[3] Admin
[4] Log Server
[5] Node
4
What you choose is: Log Server.
- 配置 DB 和 Admin 地址:(如果 DB, Admin, Log-Server 复用同一个机器,可以直接使用默认配置)
[+] Do you want to configure pg and admin address (/usr/local/oredge-log-server/conf/config.ini)? [y/N] y
[-] Please enter the address of pg server (if pg server and log server use the same machine, no need to input.):
[-] Please enter the address of admin server (if admin and log server use the same machine, no need to input.): 45.121.32.78
- 如果成功,最后会有如下提示
Install Edge Log Server successfully!
- 此时在 Admin 的 【控制面板】-【-日志】下应该能获取到日志。
3.7 Node 安装
- 操作步骤相同,安装时组件选择
Node
Which component would you like to install?
[1] Admin DB
[2] Log Server DB
[3] Admin
[4] Log Server
[5] Node
5
What you choose is: Node.
- 配置 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 server (if admin server and node server use the same machine, no need to input.):
[-] Please enter the address of log server (if log server and node use the same machine, no need to input.): 54.212.32.78
- 如果成功,最后会有如下提示
Install Edge Node successfully!
如果配置了双主 admin-web 服务,可以修改配置文件 admin
段下的 host2
字段。
node 会随机使用 host
和 host2
(与配置顺序无关),并且当某一个 admin-web 宕机的时候,会自动切换到另外一个 admin-web 服务。
至此全套的 OpenResty Edge 已经搭建完毕。
4. 开始使用
有问题请与我们随时沟通!