HttprunnerManager部署笔记

组策略开放协议端口

TCP 8000 httprunner

TCP 80 nginx

TCP 15672 rabbitMQ2

TCP 5672 rabbitMQ

TCP 3306 mysql

TCP 22 SSH

TCP 5555 flower

镜像源

-i https://mirrors.aliyun.com/pypi/simple
-i https://pypi.tuna.tsinghua.edu.cn/simple
-i http://pypi.douban.com/simple/

修改镜像源(先安装python3.6.3并配置完软链再来改,不改镜像下载依赖会很慢)

pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple

依赖安装

Python3.6.3

前置编译环境(没有编译环境python在gcc编译时会报错)

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

Python3.6.3 华为云镜像

wget https://mirrors.huaweicloud.com/python/3.6.3/Python-3.6.3.tgz

下载到 /home 路径

解压命令

tar -xvzf Python.3.6.3.tgz

修改编译文件 /Modules/Setup,防止发生 _ssl 无法 import 问题

大概在205行,打开注释

# Socket module helper for socket(2)
_socket socketmodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto

进入Python3.6.3目录,执行命令安装

./configure --prefix=/usr/local/python3
make -j2
make install -j2

构建python3 软链

ln -sf /usr/local/python3/bin/python3.6 /usr/bin/python3
ln -sf /usr/local/python3/bin/pip3 /usr/bin/pip3

升级一下pip3 至21.2.3版本

python3 -m pip install --upgrade pip==21.2.3

MySQL5.7部署

主目录

/usr/local/mysql57

进入主目录用wget 下载.rpm包

wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

安装rpm源

yum localinstall mysql57-community-release-el7-8.noarch.rpm
yum install mysql-devel

安装mysql 服务(需要禁用gpg检测)

yum -y install mysql-community-server --nogpgcheck

启用mysql 服务

systemctl start mysqld

查看mysql 服务状态

systemctl status mysqld

如果为如下情况则启动成功

mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2024-02-15 22:26:37 CST; 2min 48s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 18168 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 18118 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 18172 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─18172 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/my...

设置开机启动

systemctl enable mysqld

修改mysql密码安全策略

vim /etc/my.cnf

在[mysqld] 中添加配置

server-id = 1
plugin-load = validate_password.so
validate_password_policy = LOW
validate_password_special_char_count = 1
validate_password_number_count = 1
validate_password_mixed_case_count = 1
validate_password_length = 4
validate-password = FORCE_PLUS_PERMANENT

character_set_server=utf8
init_connect='SET NAMES utf8'

记得重新启动下Mysql服务让配置生效

systemctl restart mysqld

修改root密码

grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
set password for 'root'@'localhost'=password('daixuwei123123'); 

可以退出重新登陆下看生效没

允许远程登陆

服务器登陆mysql并执行以下命令

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'daixuwei123123' WITH GRANT OPTION;
FLUSH PRIVILEGES;

可以用dbeaver远程连接测试一下看看行不行

httprunnermanager项目部署

主文件目录

/home/HttpRunnerManager-master

安装轮子(实测50版本的setuptools安装比较快,且不报错)

pip3 install wheel
pip3 install --upgrade setuptools==50.3.2

安装前置依赖

yum install gcc gcc-c++ python3-devel mariadb-devel libffi-devel openssl-devel

查看mariadb 有没有成功安装

yum list installed | grep mariadb

没有返回结果则没有正确安装,需要重新安装下(mysql_config not found 如果在安装httprunnermanager依赖时候报这个错)

yum install mariadb-devel --nogpgcheck

用 secureCRT 传输工具把github项目代码zip文件上传(rz 命令)

https://github.com/HttpRunner/HttpRunnerManager

进入项目解压目录,执行命令安装依赖

pip3 install -r requirements.txt

链接mysql数据库并执行构建数据库命令

CREATE DATABASE `HttpRunner` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

修改HttprunnerManager主文件目录下HttpRunnerManager里的settings.py文件的sql部分

# DEBUG = True
DEBUG = False

if DEBUG:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'HttpRunner',  # 新建数据库名
            'USER': 'root',  # 数据库登录名
            'PASSWORD': 'daixuwei123123',  # 数据库登录密码
            'HOST': '120.88.88.88',  # 数据库所在服务器ip地址
            'PORT': '3306',  # 监听端口 默认3306即可
        }
    }
    STATICFILES_DIRS = (
        os.path.join(BASE_DIR, 'static'),  # 静态文件额外目录
    )
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'HttpRunner',  # 新建数据库名
            'USER': 'root',  # 数据库登录名
            'PASSWORD': 'daixuwei123123',  # 数据库登录密码
            'HOST': '120.88.88.88',  # 数据库所在服务器ip地址
            'PORT': '3306',  # 监听端口 默认3306即可
        }
    }

修改完后回退到项目主目录,执行数据库迁移同步程序

python3 manage.py makemigrations
python3 manage.py migrate

安装uwsgi

先安装编译器

yum install -y gcc* pcre-devel openssl-devel

安装依赖

yum install python36-devel

升级GCC 版本

yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash

永久升级(谨慎操作)

echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

升级后安装uwsgi应该就不报错了,重新安装时遇到了GCC版本过低的问题

执行安装uwsgi

pip3 install uwsgi

安装完成后,去httprunner 主目录,写入uwsgi.ini的配置

[uwsgi]
#http= 0.0.0.0:8000
 
# Django-related settings
 
project = HttpRunnerManager-master
project1= HttpRunnerManager
base = /home
 
 
chdir = %(base)/%(project)
module = %(project1).wsgi:application
env = DJANGO_SETTINGS_MODULE = %(base)/%(project)/%(project1).settings
 
master = true
processes = 5
#daemonize = wsgi.log
 
socket = %(base)/%(project)/%(project1).sock
chmod-socket = 666
vacuum = true

写入后保存

安装Nginx

检查是否安装gcc

gcc -v

检查是否安装zlib

cat /usr/lib64/pkgconfig/zlib.pc

检查是否安装 pcre

pcre-config --version

安装插件依赖

yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

在 /var/log 目录下建立目录 nginx 不然日志文件找不到目录要报错

构建nginx 的主目录 /usr/local/nginx 并进入

wget 下载nginx包

wget https://nginx.org/download/nginx-1.21.6.tar.gz

解压进入

tar xvf nginx-1.21.6.tar.gz
cd nginx-1.21.6

打开conf目录,备份nginx.conf

修改nginx.conf 的server部分添加配置

server {
    listen       80 default_server;     #默认监听端口
    listen       [::]:80 default_server;
    server_name  120.88.88.88;      #公网ip地址
 
    #root         /usr/share/nginx/html;
    root          /home/HttpRunnerManager-master;   #项目目录
 
    # Load configuration files for the default server block.
    include /etc/nginx/conf.d/*.conf;
 
        access_log /var/log/nginx/httprunnermanager_access.log; #增加正常日志
        error_log /var/log/nginx/httprunnermanager_error.log;  #增加异常日志
 
#增加静态文件目录
    location /static/ {
        root /home/HttpRunnerManager-master;
        }
     
    location /media/ {
        root /home/HttpRunnerManager-master;
    }
#连接到uwsgi
    location / {
        include         uwsgi_params;
        uwsgi_pass      unix:/home/HttpRunnerManager-master/HttpRunnerManager.sock;
    }
 
        error_page 404 /404.html;
    location = /40x.html {
    }
 
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    }
}

回退至nginx解压的目录,执行配置

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

编译 安装

make
make install

检查安装配置

/usr/local/nginx/sbin/nginx -V

正常输出

nginx version: nginx/1.21.6
built by gcc 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

检测配置文件语法

/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# 以下命令进入到/usr/local/nginx/sbin/目录下再操作
./nginx -s reopen # 重启nginx
./nginx -s reload #重新加载Nginx配置文件,然后以优雅的方式重启Nginx
./nginx -s stop #强制停止Nginx服务
./nginx -s quit #优雅地停止Nginx服务(即处理完所有请求后再停止服务)
./nginx -c [配置文件路径] #为 Nginx 指定配置文件

启动uwsgi 服务

切换到项目主目录 跟 uwsgi.ini 同目录下 后台启动读取配置

uwsgi -d --ini uwsgi.ini

启动nginx服务

切换到nginx 的sbin下启动服务

cd /usr/local/nginx/sbin
./nginx

启动httprunnermanager服务

tornado.web 版本过高解决

pip3 uninstall tornado
pip3 install tornado==5.1.1

启动服务

python3 manage.py runserver 0.0.0.0:8000 &

nohup python3 manage.py runserver 0.0.0.0:8000 >logs/hrun/hrun.log 2>&1 & #后台启动命令

重启,先杀死进程,再重新启动服务

netstat -anp |grep 8000
kill -s 9 XXXX 进程号

出现了非debug模式下,前端静态资源未找到的问题,需要排查是否是uwsgi网关配置问题还是Nginx.conf配置不对,不能理解这个问题原因,已尝试大量方法解决,无效

20240216 05:25 里程碑节点 攻克以上问题

问题出在Httprunnermanager 的 django的静态资源搜寻上

修改 HttpRunnerManager里的setting.py文件

注释掉里面的STATICFILES_DIRS参数

修改urls.py文件

添加以下参数

from django.views import static
from django.conf import settings
from django.conf.urls import url

urlpatterns[]里新增

url(r'^static/(?P<path>.*)$', static.serve,
      {'document_root': settings.STATIC_ROOT}, name='static'),

修改后保存即可

RabbitMQ 安装

安装前置依赖 erlang

el/7/erlang-21.3.8.14-1.el7.x86_64.rpm - rabbitmq/erlang · packagecloud

erlang 版本 21.3.8.14-1.el7.x86_64.rpm

erlang目录

/usr/local/rabbitmq

前置依赖

yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel
yum -y install ncurses-devel

进入目录执行

rpm -Uvh erlang-21.3.8.14-1.el7.x86_64.rpm

执行测试看看 OTP 是否为 21

erl -v

如果yum 报错找不到包,可以试试重新构建yum安装缓存

yum clean all

yum makecache

安装 rabbitMQ

github.com

rabbitMQ目录

usr/local/rabbitmq

安装依赖

yum install socat

进入目录执行

rpm -ivh rabbitmq-server-3.8.5-1.el7.noarch.rpm

启动 rabbitmq服务

service rabbitmq-server start

查看运行状态

service rabbitmq-server status

看到 active就行了

其他命令

service rabbitmq-server stop
service rabbitmq-server restart

配置RabbitMQ

创建配置文件

cd /etc/rabbitmq/
vim rabbitmq.config

编辑内容

[{rabbit, [{loopback_users, []}]}].

保存后重启Rabbitmq

service rabbitmq-server restart

安装可视化界面

/sbin/rabbitmq-plugins enable rabbitmq_management

修改rabbitMQ账号密码

查看用户列表
rabbitmqctl list_users
添加用户
rabbitmqctl add_user <username> <newpassword>
添加管理权限
rabbitmqctl set_user_tags <username> administrator
添加远程访问权限
rabbitmqctl set_permissions -p / <username> ".*" ".*" ".*"
修改密码
rabbitmqctl change_password <username> <newpassword>
删除一个用户
rabbitmqctl delete_user <username>

还需要修改 settings.py 里的配置

大概在155行这样,有一个BROKER_URL,改成

djcelery.setup_loader()
CELERY_ENABLE_UTC = True
CELERY_TIMEZONE = 'Asia/Shanghai'
BROKER_URL = 'amqp://<rabbitmqusername>:<rabbitmqpassword>@120.46.88.88:5672//' if DEBUG else 'amqp://<rabbitmqusername>:<rabbitmqpassword>@120.46.88.88:5672//'
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

记得把下面的定时报告邮箱也改一下

后台启动Worker

后台启动worker

nohup python3 manage.py celery -A HttpRunnerManager worker --loglevel=info >logs/worker/worker.log 2>&1 &

后台启动定时任务监听器

nohup python3 manage.py celery beat --loglevel=info >logs/celery/celery.log 2>&1 &

后台启动任务监控后台(不知道为啥配置没生效,直接命令行指定了)

nohup celery flower --broker=amqp://guest:guest@120.46.88.88:5672 >logs/flower/flower.log 2>&1 &

任务监控后台还需要修改一下菜单栏的系统设置,在base.html里

<li><a href="http://120.46.88.88:5555/dashboard">任 务 监 控</a></li>

改完重启主服务,点一下看看能不能跳转

关于测试报告加载缓慢的问题

需要修改两个文件,extent_report_template.html 和 report_template.html 前面是异步执行的后面是同步执行的,因为加载css 和 js 太慢了(从国外cdn加载),所以选择把代码直接写在html里,改不太好改,改好的包放在patch里了

posted @ 2024-02-16 17:15  ShadowMurloc  阅读(63)  评论(0编辑  收藏  举报