第二篇supervisor集群管理工具cesi安装详解-如何安装supervisor-cesiwebUI

介绍

前一篇我们安装好了supervisor,supervisor自带了一个UI界面,不太好用,且不支持集群
CeSi 是 Supervisor 官方推荐的集中化管理 Supervisor 实例的 Web UI,该工具是用 Python 编写,基于 Flask Web 框架 。

Superviosr 自带的 Web UI 不支持跨机器管理
Supervisor 进程,功能比较简单,通过 CeSi 可以集中管理各个服务器节点的进程,在 Web 界面就可以轻松管理各个服务的启动、关闭、重启等,很方便使用。

安装

软件下载地址cesi-extended.tar.gz

https://github.com/gamegos/cesi/releases

上传到服务器

解压

[root@localhost cesi]# pwd
/data/supervisor/cesi
[root@localhost cesi]# tar -xf cesi-extended.tar.gz 
[root@localhost cesi]# ll
总用量 9752
drwxr-xr-x. 5 1157137021 1123705078     164 5月  25 10:16 cesi
-rw-r--r--. 1 root       root       9873466 5月  20 13:14 cesi-extended.tar.gz
-rw-r--r--. 1 1157137021 1123705078     360 6月  28 2020 CONTRIBUTORS.md
drwxr-xr-x. 2 1157137021 1123705078      70 5月  25 10:16 defaults
-rw-r--r--. 1 1157137021 1123705078     237 6月  28 2020 DEVELOPMENT.md
-rw-r--r--. 1 1157137021 1123705078    1980 6月  28 2020 docker-compose.yml
-rw-r--r--. 1 1157137021 1123705078      62 6月  28 2020 env.sample
-rw-r--r--. 1 1157137021 1123705078   35146 6月  28 2020 LICENCE
-rw-r--r--. 1 1157137021 1123705078    1186 6月  28 2020 Makefile
-rw-r--r--. 1 1157137021 1123705078   38294 6月  28 2020 poetry.lock
-rw-r--r--. 1 1157137021 1123705078     535 6月  28 2020 pyproject.toml
-rw-r--r--. 1 1157137021 1123705078    3734 6月  28 2020 README.md
-rw-r--r--. 1 1157137021 1123705078      90 6月  28 2020 requirements.txt

安装依赖

[root@localhost cesi]# /data/supervisor/python3.7/bin/pip3 install -r requirements.txt 
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting flask==1.1.2 (from -r requirements.txt (line 1))
  Downloading http://mirrors.aliyun.com/pypi/packages/f2/28/2a03252dfb9ebf377f40fba6a7841b47083260bf8bd8e737b0c6952df83f/Flask-1.1.2-py2.py3-none-any.whl (94kB)
    100% |████████████████████████████████| 102kB 2.0MB/s 
Collecting flask-sqlalchemy==2.4.3 (from -r requirements.txt (line 2))
  Downloading http://mirrors.aliyun.com/pypi/packages/a6/b1/9da1c3c5417612b2fc4d25d55a225199c633d6492dac215b11b9021e6a8d/Flask_SQLAlchemy-2.4.3-py2.py3-none-any.whl
Collecting psycopg2-binary==2.8.5 (from -r requirements.txt (line 3))
  Downloading http://mirrors.aliyun.com/pypi/packages/e6/bc/cb407e8d0301801d5f44d3f464485d9577c3bf92db13afef4d05d757ec47/psycopg2_binary-2.8.5-cp37-cp37m-manylinux1_x86_64.whl (2.9MB)
    100% |████████████████████████████████| 2.9MB 1.8MB/s 
Collecting pymysql==0.9.3 (from -r requirements.txt (line 4))
  Downloading http://mirrors.aliyun.com/pypi/packages/ed/39/15045ae46f2a123019aa968dfcba0396c161c20f855f11dea6796bcaae95/PyMySQL-0.9.3-py2.py3-none-any.whl (47kB)
    100% |████████████████████████████████| 51kB 2.1MB/s 
Collecting tomlkit==0.5.11 (from -r requirements.txt (line 5))
  Downloading http://mirrors.aliyun.com/pypi/packages/7d/8c/c3ee9cd41b2df781b2dc39c31209724b4f04a3110b46531de2e661ace186/tomlkit-0.5.11-py2.py3-none-any.whl
Collecting itsdangerous>=0.24 (from flask==1.1.2->-r requirements.txt (line 1))
  Downloading http://mirrors.aliyun.com/pypi/packages/9c/96/26f935afba9cd6140216da5add223a0c465b99d0f112b68a4ca426441019/itsdangerous-2.0.1-py3-none-any.whl
Collecting Jinja2>=2.10.1 (from flask==1.1.2->-r requirements.txt (line 1))
  Downloading http://mirrors.aliyun.com/pypi/packages/80/21/ae597efc7ed8caaa43fb35062288baaf99a7d43ff0cf66452ddf47604ee6/Jinja2-3.0.1-py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 1.9MB/s 
Collecting click>=5.1 (from flask==1.1.2->-r requirements.txt (line 1))
  Downloading http://mirrors.aliyun.com/pypi/packages/76/0a/b6c5f311e32aeb3b406e03c079ade51e905ea630fc19d1262a46249c1c86/click-8.0.1-py3-none-any.whl (97kB)
    100% |████████████████████████████████| 102kB 1.7MB/s 
Collecting Werkzeug>=0.15 (from flask==1.1.2->-r requirements.txt (line 1))
  Downloading http://mirrors.aliyun.com/pypi/packages/bd/24/11c3ea5a7e866bf2d97f0501d0b4b1c9bbeade102bb4b588f0d2919a5212/Werkzeug-2.0.1-py3-none-any.whl (288kB)
    100% |████████████████████████████████| 296kB 1.8MB/s 
Collecting SQLAlchemy>=0.8.0 (from flask-sqlalchemy==2.4.3->-r requirements.txt (line 2))
  Downloading http://mirrors.aliyun.com/pypi/packages/aa/e3/d4d75e8f04456d4b636a3dbcd20fd423878f789db3e8881dec89ea38f9b1/SQLAlchemy-1.4.15-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.5MB)
    100% |████████████████████████████████| 1.5MB 2.0MB/s 
Collecting MarkupSafe>=2.0 (from Jinja2>=2.10.1->flask==1.1.2->-r requirements.txt (line 1))
  Downloading http://mirrors.aliyun.com/pypi/packages/ad/cd/650b1be2a81674939ef962b1f1b956e4a84116d69708c842667445e95408/MarkupSafe-2.0.1-cp37-cp37m-manylinux2010_x86_64.whl
Collecting importlib-metadata; python_version < "3.8" (from click>=5.1->flask==1.1.2->-r requirements.txt (line 1))
  Downloading http://mirrors.aliyun.com/pypi/packages/8e/e2/49966924c93909d47612bb47d911448140a2f6c1390aec2f4c1afbe3748f/importlib_metadata-4.0.1-py3-none-any.whl
Collecting greenlet!=0.4.17; python_version >= "3" (from SQLAlchemy>=0.8.0->flask-sqlalchemy==2.4.3->-r requirements.txt (line 2))
  Downloading http://mirrors.aliyun.com/pypi/packages/bb/ea/c838bae79013f1106092f8cc6b28a60f86fdd7ade899c636f12ff736cdd7/greenlet-1.1.0-cp37-cp37m-manylinux2010_x86_64.whl (160kB)
    100% |████████████████████████████████| 163kB 1.8MB/s 
Collecting typing-extensions>=3.6.4; python_version < "3.8" (from importlib-metadata; python_version < "3.8"->click>=5.1->flask==1.1.2->-r requirements.txt (line 1))
  Downloading http://mirrors.aliyun.com/pypi/packages/2e/35/6c4fff5ab443b57116cb1aad46421fb719bed2825664e8fe77d66d99bcbc/typing_extensions-3.10.0.0-py3-none-any.whl
Collecting zipp>=0.5 (from importlib-metadata; python_version < "3.8"->click>=5.1->flask==1.1.2->-r requirements.txt (line 1))
  Downloading http://mirrors.aliyun.com/pypi/packages/0f/8c/715c54e9e34c0c4820f616a913a7de3337d0cd79074dd1bed4dd840f16ae/zipp-3.4.1-py3-none-any.whl
Installing collected packages: itsdangerous, MarkupSafe, Jinja2, typing-extensions, zipp, importlib-metadata, click, Werkzeug, flask, greenlet, SQLAlchemy, flask-sqlalchemy, psycopg2-binary, pymysql, tomlkit
Successfully installed Jinja2-3.0.1 MarkupSafe-2.0.1 SQLAlchemy-1.4.15 Werkzeug-2.0.1 click-8.0.1 flask-1.1.2 flask-sqlalchemy-2.4.3 greenlet-1.1.0 importlib-metadata-4.0.1 itsdangerous-2.0.1 psycopg2-binary-2.8.5 pymysql-0.9.3 tomlkit-0.5.11 typing-extensions-3.10.0.0 zipp-3.4.1
You are using pip version 19.0.3, however version 21.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@localhost cesi]# 

修改配置

[root@localhost cesi]# cat defaults/cesi.conf.toml
 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 = "192.168.80.176-server"
environment = ""
username = "super"
password = "KsKFaCIX50fDv7kz"
host = "192.168.80.176"
port = "9001"

[[nodes]]
name = "192.168.65.94-server"
environment = ""
username = "super"
password = "KsKFaCIX50fDv7kz"
host = "192.168.65.94"
port = "9001"

注册为系统服务

[root@localhost cesi]# cp defaults/cesi.service /etc/systemd/system/
[root@localhost cesi]# cat /etc/systemd/system/cesi.service 
[Unit]
Description=cesi

[Service]
Environment=
ExecStart=/data/supervisor/python3.7/bin/python3 /data/supervisor/cesi/cesi/run.py --config-file /etc/cesi.conf.toml
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=TERM
User=root
WorkingDirectory=/data/supervisor/cesi

Restart=on-failure

[Install]
WantedBy=multi-user.target

启动

[root@localhost cesi]# systemctl daemon-reload
[root@localhost cesi]# systemctl restart cesi
[root@localhost cesi]# systemctl status cesi
● cesi.service - cesi
   Loaded: loaded (/etc/systemd/system/cesi.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2021-05-25 10:26:40 CST; 4s ago
 Main PID: 111963 (python3)
    Tasks: 1
   Memory: 34.1M
   CGroup: /system.slice/cesi.service
           └─111963 /data/supervisor/python3.7/bin/python3 /data/supervisor/cesi/cesi/run.py --config-file /etc/cesi.conf.toml

5月 25 10:26:41 localhost.localdomain python3[111963]: {'admin_username': 'admin', 'database': 'sqlite:///users.db', 'admin_password': 'admin', 'activity_log': 'activity.log', 'nodes': [<core.node.Node object at 0x7eff9df15810>, <core.node.Node object at 0x7eff9dbfb...
5月 25 10:26:41 localhost.localdomain python3[111963]: can't set attribute
5月 25 10:26:41 localhost.localdomain python3[111963]: * Serving Flask app "run" (lazy loading)
5月 25 10:26:41 localhost.localdomain python3[111963]: * Environment: production
5月 25 10:26:41 localhost.localdomain python3[111963]: WARNING: This is a development server. Do not use it in a production deployment.
5月 25 10:26:41 localhost.localdomain python3[111963]: Use a production WSGI server instead.
5月 25 10:26:41 localhost.localdomain python3[111963]: * Debug mode: off
5月 25 10:26:41 localhost.localdomain python3[111963]: * Running on all addresses.
5月 25 10:26:41 localhost.localdomain python3[111963]: WARNING: This is a development server. Do not use it in a production deployment.
5月 25 10:26:41 localhost.localdomain python3[111963]: * Running on http://192.168.93.128:5000/ (Press CTRL+C to quit)
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost cesi]# 

默认用户名:admin
密码:admin

登录一下,发现报错了

看报错日志 /var/log/message

May 25 10:28:39 localhost python3: [2021-05-25 10:28:39,728] ERROR in app: Exception on /api/v2/auth/login/ [POST]
May 25 10:28:39 localhost python3: Traceback (most recent call last):
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/sqlalchemy/util/_collections.py", line 1008, in __call__
May 25 10:28:39 localhost python3: return self.registry[key]
May 25 10:28:39 localhost python3: KeyError: <greenlet.greenlet object at 0x7eff9c981710 (otid=0x7eff9c6a0f00) current active started main>
May 25 10:28:39 localhost python3: During handling of the above exception, another exception occurred:
May 25 10:28:39 localhost python3: Traceback (most recent call last):
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
May 25 10:28:39 localhost python3: response = self.full_dispatch_request()
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
May 25 10:28:39 localhost python3: rv = self.handle_user_exception(e)
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
May 25 10:28:39 localhost python3: reraise(exc_type, exc_value, tb)
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
May 25 10:28:39 localhost python3: raise value
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
May 25 10:28:39 localhost python3: rv = self.dispatch_request()
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
May 25 10:28:39 localhost python3: return self.view_functions[rule.endpoint](**req.view_args)
May 25 10:28:39 localhost python3: File "/data/supervisor/cesi/cesi/api/v2/auth.py", line 35, in login
May 25 10:28:39 localhost python3: result = User.verify(user_credentials["username"], user_credentials["password"])
May 25 10:28:39 localhost python3: File "/data/supervisor/cesi/cesi/models.py", line 37, in verify
May 25 10:28:39 localhost python3: user = User.query.filter_by(username=username).first()
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 514, in __get__
May 25 10:28:39 localhost python3: return type.query_class(mapper, session=self.sa.session())
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/sqlalchemy/orm/scoping.py", line 129, in __call__
May 25 10:28:39 localhost python3: return self.registry()
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/sqlalchemy/util/_collections.py", line 1010, in __call__
May 25 10:28:39 localhost python3: return self.registry.setdefault(key, self.createfunc())
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/sqlalchemy/orm/session.py", line 4065, in __call__
May 25 10:28:39 localhost python3: return self.class_(**local_kw)
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 138, in __init__
May 25 10:28:39 localhost python3: bind = options.pop('bind', None) or db.engine
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 943, in engine
May 25 10:28:39 localhost python3: return self.get_engine()
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 962, in get_engine
May 25 10:28:39 localhost python3: return connector.get_engine()
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 555, in get_engine
May 25 10:28:39 localhost python3: options = self.get_options(sa_url, echo)
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 570, in get_options
May 25 10:28:39 localhost python3: self._sa.apply_driver_hacks(self._app, sa_url, options)
May 25 10:28:39 localhost python3: File "/data/supervisor/python3.7/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 914, in apply_driver_hacks
May 25 10:28:39 localhost python3: sa_url.database = os.path.join(app.root_path, sa_url.database)
May 25 10:28:39 localhost python3: AttributeError: can't set attribute

May 25 10:28:39 localhost python3: sa_url.database = os.path.join(app.root_path, sa_url.database)
May 25 10:28:39 localhost python3: AttributeError: can’t set attribute

解决方法

AttributeError:使用flask-sqlalchemy连接到sqlite数据库时无法设置属性

[root@localhost cesi]# /data/supervisor/python3.7/bin/pip3 install  --upgrade sqlalchemy==1.3.23
[root@localhost cesi]# systemctl restart cesi

OK,已经重启了,现在再登录一下

版权声明:本文为作者原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

原创文章,作者:老C,如若转载,请注明出处:https://www.code404.icu/664.html

发表评论

登录后才能评论