自动化工具 zerorunner 在 Centos 的环境配置和部署

杨腾 · March 20, 2024 · Last by King replied at March 26, 2024 · 5312 hits

Guide

近期有关注到 zerorunner 这个测试平台,可惜文档较少,在部署环境和使用过程遇到了不少问题。这里记录下我的学习使用过程,希望能帮助于其他人在 linux 下部署开展。

项目原文见:zerorunner 感谢项目作者 小白 的无私奉献。

这篇主要讲解如何在 Centos7 进行 zerorunner 的环境配置和部署,其中 mysql、redis 在不同 centos 版本的安装过程都有所不同,如果出现问题的话可以用 centos6 如何安装 mysql8 这样的关键字去搜索,也欢迎大家留言。

Centos 环境准备

更新 yum

yum update

安装 gcc

yum install gcc

安装 lrzsz

yum install lrzsz

安装 mysql

#mysql下载
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
#安装rpm包
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
#导入最新的mysql GPG
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
#安装mysql
yum install mysql-server
#修改mysql配置
#zerorunner对应的配置文件在zerorunner\backend\db_script\my.cnf,替换掉etc\my.cnf即可
#确认替换成功
cat my.cnf
#相应文件夹授权
chown root /var/lib/mysql/

#启用服务
service mysqld start
#检查服务
service mysqld status
#查看初始密码
cat /var/log/mysqld.log | grep password
#使用上边获得的初始密码登录mysql
mysql -u root -p

#设定密码并退出
mysql > alter user 'root'@'localhost' identified by '你的密码';
mysql > flush privileges;
mysql > exit;
#重启mysql服务让改动生效
service mysqld restart

安装 python

#安装依赖
yum -y install zlib zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
#下载python,跟文档建议版本一致
wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
#解压到当前目录
tar -zxvf Python-3.9.6.tgz
cd Python-3.9.6

#安装python
mkdir -p /usr/local/Python3
./configure --prefix=/usr/local/Python3
make
make install

#创建软连接
ln -s /usr/local/Python3/bin/python3 /usr/bin/python3

#添加环境变量
vi ~/.bash_profile
#在export PATH前添加
PATH=$PATH:$HOME/bin:/usr/local/Python3/bin

#刷新生效
source ~/.bash_profile

#检查安装
python3 -V
pip3 -V

#更新pip3
pip3 install --upgrade pip

#准备虚拟环境
pip3 install virtualenv
mkdir -p /pyenv
virtualenv -p /usr/local/Python3/bin/python3 /pyenv/

安装 nginx

#安装依赖(跟python环境同个应用则不需要)
yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel
#下载解压
wget http://nginx.org/download/nginx-1.20.2.tar.gz
tar -zxvf nginx-1.20.2.tar.gz -C /usr/local/src/
#进入目录
cd /usr/local/src/nginx-1.20.2

#编译安装
./configure
make
make install

#进入安装目录,启动服务
cd /usr/local/nginx
./sbin/nginx

#检查服务
ps -ef | grep nginx

#配置防火墙,永久放行
firewall-cmd --add-port=80/tcp --permanent

安装 redis

#安装依赖
yum -y install centos-release-scl && yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils && scl enable devtoolset-9 bash
#下载解压redis,跟文档建议版本一致
wget https://download.redis.io/releases/redis-6.0.9.tar.gz
tar xzf redis-6.0.9.tar.gz

#进入目录
cd redis-6.0.9

#编译安装
make
make install

#默认安装在 /usr/local/bin/目录
cd /usr/local/redis/bin/
#拷贝配置文件
cp /root/redis-6.0.9/redis.conf /usr/local/redis/bin/
#daemonize 的值从 no 修改成 yes
vi redis.conf

#启动服务
./redis-server redis.conf
#检查
ps -ef |grep redis

Zerorunner 部署

初始化 mysql

#进入mysql
mysql -u root -p
#新建数据库
CREATE DATABASE zerorunner;
exit;
#进入后端数据库文件夹
cd zerorunner/backend/db_script
mysql -u root -p zerorunner < zerorunner.sql

后端部署

#进入后端文件夹
cd zerorunner/backend
#进入虚拟环境
source /pyenv/bin/activate
#更新setuptools wheel
pip install --upgrade pip setuptools wheel
#安装依赖
pip install -r requirements
#启用服务
gunicorn main:app --workers 2 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:8101

前端部署

#在本地进入后端文件夹
cd zerorunner/frontend
#打包发布,拿到dist
cnpm run build
#将dist文件夹放在nginx目录下的html里面
#进入nginx安装目录
cd /usr/local/nginx/conf
vi nginx.conf
#将root指向dist文件夹即可
![](/uploads/photo/2024/485b3eba-c3c5-441f-a99c-14099fceb891.png!large)

备注

至此部署完成,访问 IP 对应的 80 端口即可。

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 11 条回复 时间 点赞

太赞了




大佬,这个要整个替换掉,需要改啥配置吗

杨腾 #3 · March 21, 2024 Author
King 回复

我看到项目原文件的 my.cnf 有一些大小写不敏感的配置
我的文件是下边这样,可以直接覆盖修改安装看看

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
socket          =/var/lib/mysql/mysql.sock

log-error      =/var/log/mysqld.log
pid-file         =/var/run/mysqld/mysqld.pid

symbolic-links=0
# 1GB
max_allowed_packet=1073741824
# 大小写不敏感

# lower_case_table_names=1

# 慢查询
slow_query_log = ON
slow_query_log_file = /var/lib/mysql/slow.log
long_query_time = 3

Building wheels for collected packages: jsonpath, py-mock
Building wheel for jsonpath (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [32 lines of output]
Traceback (most recent call last):
File "", line 2, in
File "", line 34, in
File "/tmp/pip-install-fajpqut3/jsonpath_74969dfc1d114b37a06a2372f4e65848/setup.py", line 19, in
setup(name=name,
File "/pyenv/lib/python3.9/site-packages/setuptools/distutils/core.py", line 172, in setup
ok = dist.parse_command_line()
File "/pyenv/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 475, in parse_command_line
args = self._parse_command_opts(parser, args)
File "/pyenv/lib/python3.9/site-packages/setuptools/dist.py", line 869, in _parse_command_opts
nargs = _Distribution._parse_command_opts(self, parser, args)
File "/pyenv/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 534, in _parse_command_opts
cmd_class = self.get_command_class(command)
File "/pyenv/lib/python3.9/site-packages/setuptools/dist.py", line 714, in get_command_class
self.cmdclass[command] = cmdclass = ep.load()
File "/pyenv/lib/python3.9/site-packages/setuptools/_vendor/importlib_metadata/
init.py", line 208, in load
module = import_module(match.group('module'))
File "/usr/local/Python3/lib/python3.9/importlib/
init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "", line 850, in exec_module
File "", line 228, in _call_with_frames_removed
File "/pyenv/lib/python3.9/site-packages/wheel/bdist_wheel.py", line 27, in
from .macosx_libfile import calculate_macosx_platform_tag
File "/pyenv/lib/python3.9/site-packages/wheel/macosx_libfile.py", line 43, in
import ctypes
File "/usr/local/Python3/lib/python3.9/ctypes/
init_.py", line 8, in
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for jsonpath
Running setup.py clean for jsonpath
Building wheel for py-mock (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [34 lines of output]
Traceback (most recent call last):
File "", line 2, in
File "", line 34, in
File "/tmp/pip-install-fajpqut3/py-mock_7899cc66e4284d25b9c8e564cd655047/setup.py", line 10, in
setuptools.setup(
File "/pyenv/lib/python3.9/site-packages/setuptools/init.py", line 104, in setup
return distutils.core.setup(**attrs)
File "/pyenv/lib/python3.9/site-packages/setuptools/distutils/core.py", line 172, in setup
ok = dist.parse_command_line()
File "/pyenv/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 475, in parse_command_line
args = self._parse_command_opts(parser, args)
File "/pyenv/lib/python3.9/site-packages/setuptools/dist.py", line 869, in _parse_command_opts
nargs = _Distribution._parse_command_opts(self, parser, args)
File "/pyenv/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 534, in _parse_command_opts
cmd_class = self.get_command_class(command)
File "/pyenv/lib/python3.9/site-packages/setuptools/dist.py", line 714, in get_command_class
self.cmdclass[command] = cmdclass = ep.load()
File "/pyenv/lib/python3.9/site-packages/setuptools/_vendor/importlib_metadata/
init.py", line 208, in load
module = import_module(match.group('module'))
File "/usr/local/Python3/lib/python3.9/importlib/
init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "", line 850, in exec_module
File "", line 228, in _call_with_frames_removed
File "/pyenv/lib/python3.9/site-packages/wheel/bdist_wheel.py", line 27, in
from .macosx_libfile import calculate_macosx_platform_tag
File "/pyenv/lib/python3.9/site-packages/wheel/macosx_libfile.py", line 43, in
import ctypes
File "/usr/local/Python3/lib/python3.9/ctypes/
init_.py", line 8, in
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for py-mock
Running setup.py clean for py-mock
Failed to build jsonpath py-mock
ERROR: Could not build wheels for jsonpath, py-mock, which is required to install pyproject.toml-based projects

按照文档部署,报上面的错,大佬有时间帮看下

杨腾 #6 · March 21, 2024 Author
King 回复

pip 换个源应该就可以了,pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements

大佬有时间给看下这个报错呗,我看文档这块没写,报错说是 pydantic.error_wrappers。ValidationError:配置的 4 个验证错误
REDIS_URI
字段必需 (type=value_error.missing)
DATABASE_URI
字段必需 (type=value_error.missing)
broker_url
需要字段 (type=value_error.missing) Traceback (most recent call last):
但是没找到解决办法
File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.6/site-packages/uvicorn/workers.py", line 66, in init_process
super(UvicornWorker, self).init_process()
File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.6/site-packages/gunicorn/util.py", line 371, in import_app
mod = importlib.import_module(module)
File "/usr/lib64/python3.6/importlib/init.py", line 126, in import_module
return bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in exec_module
File "", line 219, in _call_with_frames_removed
File "/root/zerorunner-master/backend/main.py", line 8, in
from autotest.init.cors import init_cors
File "/root/zerorunner-master/backend/autotest/init/cors.py", line 6, in
from config import config
File "/root/zerorunner-master/backend/config.py", line 115, in
config = Configs()
File "/usr/local/lib/python3.6/site-packages/pydantic/env_settings.py", line 44, in __init
_
secrets_dir=_secrets_dir,
File "/usr/local/lib/python3.6/site-packages/pydantic/main.py", line 341, in __init
_
raise validation_error
pydantic.error_wrappers.ValidationError: 4 validation errors for Configs
REDIS_URI
field required (type=value_error.missing)
DATABASE_URI
field required (type=value_error.missing)
broker_url
field required (type=value_error.missing)
beat_db_uri
field required (type=value_error.missing)
[2024-03-22 10:11:20 +0800] [29398] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.6/site-packages/uvicorn/workers.py", line 66, in init_process
super(UvicornWorker, self).init_process()
File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.6/site-packages/gunicorn/util.py", line 371, in import_app
mod = importlib.import_module(module)
File "/usr/lib64/python3.6/importlib/init.py", line 126, in import_module
return bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in exec_module
File "", line 219, in _call_with_frames_removed
File "/root/zerorunner-master/backend/main.py", line 8, in
from autotest.init.cors import init_cors
File "/root/zerorunner-master/backend/autotest/init/cors.py", line 6, in
from config import config
File "/root/zerorunner-master/backend/config.py", line 115, in
config = Configs()
File "/usr/local/lib/python3.6/site-packages/pydantic/env_settings.py", line 44, in __init
_
secrets_dir=_secrets_dir,
File "/usr/local/lib/python3.6/site-packages/pydantic/main.py", line 341, in __init
_
raise validation_error
pydantic.error_wrappers.ValidationError: 4 validation errors for Configs
REDIS_URI
field required (type=value_error.missing)
DATABASE_URI
field required (type=value_error.missing)
broker_url
field required (type=value_error.missing)
beat_db_uri
field required (type=value_error.missing)
[2024-03-22 10:11:20 +0800] [29396] [INFO] Worker exiting (pid: 29396)
[2024-03-22 10:11:20 +0800] [29398] [INFO] Worker exiting (pid: 29398)
[2024-03-22 10:11:20 +0800] [29393] [ERROR] Worker (pid:29398) exited with code 3
[2024-03-22 10:11:20 +0800] [29393] [ERROR] Worker (pid:29396) was sent SIGTERM!
[2024-03-22 10:11:20 +0800] [29393] [ERROR] Shutting down: Master
[2024-03-22 10:11:20 +0800] [29393] [ERROR] Reason: Worker failed to boot.

杨腾 #8 · March 22, 2024 Author
King 回复

看起来好像跟环境无关了,你这执行什么出现的报错


启用的时候报错的

杨腾 #10 · March 22, 2024 Author
King 回复

看起来更像是代码哪里不对哦,要不加个微信私聊吧

可以,我加你

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up