阅读本文大约需要1.5分钟。
背景
在之前的文章《自动化测试之进程管理》中讲到了用Supervisor做进程管理的好处,可以很方便的用来启动、重启、关闭进程,类似于 Linux 的 systemd 守护进程一样,通过统一的命令来管理系统的各个服务,当管理的服务挂掉时会自动重新拉起,如果只有一台服务器的情况下,问题倒不大,但是如果你有一个自动化集群,部署着数十个进程服务,那么管理和维护成本就会陡增。
今天就来给大家分享一个解决方案 - CeSi,该工具是 Supervisor 的 WebUI,可以通过这个统一的 WebUI 集中化管理各个服务器节点的进程。
CeSi的安装和部署
CeSi 是 Supervisor 官方推荐的集中化管理 Supervisor 实例的 Web UI,该工具是用 Python 编写的,基于 Flask Web 框架 。
Superviosr 自带的 Web UI 不支持跨机器管理,Supervisor 进程功能比较简单,通过 CeSi 可以集中管理各个服务器节点的进程,在 Web 界面就可以轻松管理各个服务的启动、关闭、重启等,使用很方便。
安装
以Ubuntu为例,具体的安装步骤如下:
$ sudo apt install -y git python3 python3-pip python3-venv
$ # If you want to change CESI_SETUP_PATH, you must change the configurations in the cesi.service file.
$ export CESI_SETUP_PATH=/opt/cesi
$ mkdir ${CESI_SETUP_PATH}
$ cd ${CESI_SETUP_PATH}
$ # Download the project to CESI_SETUP_PATH directory
$ wget https://github.com/gamegos/cesi/releases/download/v2.7.1/cesi-extended.tar.gz -O cesi.tar.gz
$ tar -xvf cesi.tar.gz
$ # Create virtual environment and install requirement packages
$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ pip3 install -r requirements.txt
(venv) $ deactivate # Deactivate virtual environment
$ # Build ui (First you must install dependencies for ui -> yarn) - Optional
$ cd ${CESI_SETUP_PATH}/cesi/ui
$ yarn install
$ yarn build
$ # Create cesi.conf.toml file and update cesi.conf.toml for your environment.
$ # Config file documentation can be found inside default file.
$ # (You must create cesi.conf in the etc directory for cesi.service)
$ sudo cp ${CESI_SETUP_PATH}/defaults/cesi.conf.toml /etc/cesi.conf.toml
$ # Run as a service
$ sudo cp ${CESI_SETUP_PATH}/defaults/cesi.service /etc/systemd/system/cesi.service
$ sudo systemctl daemon-reload
$ sudo systemctl start cesi
配置
CeSi 的配置非常简单,和 Supervisor 的配置文件类似,配置文件路径:
/etc/cesi.conf.toml
只需要把nodes部分填充为自己的各个服务器节点信息就可以了,含义可以看注释部分。
# This is the main CeSI toml configuration file. It contains CeSI web application and
# supervisord information to connect
# This is the CeSI's own configuration.
[cesi]
# Database Uri
database = "sqlite:///users.db" # Relative path
# Etc
#database = "sqlite:////opt/cesi/< version >/users.db" # Absolute path
#database = "postgres://<user>:<password>@localhost:5432/<database_name>"
#database = "mysql+pymysql://<user>:<password>@localhost:3306/<database_name>"
activity_log = "activity.log" # File path for CeSI logs
admin_username = "admin" # Username of admin user
admin_password = "admin" # Password of admin user
# This is the definition section for new supervisord node.
# [[nodes]]
# name = "api" # (String) Unique name for supervisord node.
# environment = "" # (String) The environment name provides logical grouping of supervisord nodes. It can be used as filtering option in the UI.
# username = "" # (String) Username of the XML-RPC interface of supervisord Set nothing if no username is configured
# password = "" # (String) Password of the XML-RPC interface of supervisord. Set nothing if no username is configured
# host = "127.0.0.1" # (String) Host of the XML-RPC interface of supervisord
# port = "9001" # (String) Port of the XML-RPC interface of supervisord
# Default supervisord nodes
[[nodes]]
name = "专项服务器"
environment = ""
username = "test"
password = "test"
host = ""
port = "9001"
[[nodes]]
name = "主服务器"
environment = ""
username = "test"
password = "test"
host = ""
port = "9001"
最终的效果图如下: