linux上个人目录home/yxx下有虚拟环境
1,明明已经安装了flask-cores模块,但是启动时一直报错,不存在此模块
原来没有启动虚拟环境,虽然在一直安装包,但是安装的包都安装到了主环境中
解决办法:
激活虚拟环境:
source bin/activate
在虚拟环境下,安装需要的模块:
pip3 install -r ../requirments.txt
或者
pip3 install flask-cors
2,使用 gunicorn 来启动flask项目,access.log显示启动成功,但是访问不了
启动后的日志,让我以为启动成功了
[2021-06-04 19:34:15 +0800] [8915] [INFO] Worker exiting (pid: 8915)
[2021-06-04 19:35:14 +0800] [9022] [INFO] Starting gunicorn 20.0.4
[2021-06-04 19:35:14 +0800] [9022] [INFO] Listening at: http://0.0.0.0:8080 (9022)
[2021-06-04 19:35:14 +0800] [9022] [INFO] Using worker: sync
[2021-06-04 19:35:14 +0800] [9036] [INFO] Booting worker with pid: 9036
[2021-06-04 19:35:14 +0800] [9037] [INFO] Booting worker with pid: 9037
[2021-06-04 19:35:14 +0800] [9038] [INFO] Booting worker with pid: 9038
[2021-06-04 19:35:14 +0800] [9039] [INFO] Booting worker with pid: 9039
[2021-06-04 19:35:14 +0800] [9041] [INFO] Booting worker with pid: 9041
[2021-06-04 19:35:14 +0800] [9044] [INFO] Booting worker with pid: 9044
[2021-06-04 19:35:14 +0800] [9046] [INFO] Booting worker with pid: 9046
[2021-06-04 19:35:14 +0800] [9048] [INFO] Booting worker with pid: 9048
[2021-06-04 19:35:14 +0800] [9049] [INFO] Booting worker with pid: 9049
[2021-06-04 19:35:14 +0800] [9053] [INFO] Booting worker with pid: 9053
[2021-06-04 19:35:14 +0800] [9055] [INFO] Booting worker with pid: 9055
[2021-06-04 19:35:15 +0800] [9059] [INFO] Booting worker with pid: 9059
[2021-06-04 19:35:15 +0800] [9036] [INFO] Worker exiting (pid: 9036)
[2021-06-04 19:35:15 +0800] [9065] [INFO] Booting worker with pid: 9065
[2021-06-04 19:35:15 +0800] [9037] [INFO] Worker exiting (pid: 9037)
[2021-06-04 19:35:15 +0800] [9039] [INFO] Worker exiting (pid: 9039)
[2021-06-04 19:35:15 +0800] [9038] [INFO] Worker exiting (pid: 9038)
[2021-06-04 19:35:15 +0800] [9046] [INFO] Worker exiting (pid: 9046)
[2021-06-04 19:35:15 +0800] [9041] [INFO] Worker exiting (pid: 9041)
[2021-06-04 19:35:15 +0800] [9044] [INFO] Worker exiting (pid: 9044)
[2021-06-04 19:35:15 +0800] [9049] [INFO] Worker exiting (pid: 9049)
[2021-06-04 19:35:15 +0800] [9048] [INFO] Worker exiting (pid: 9048)
[2021-06-04 19:35:15 +0800] [9055] [INFO] Worker exiting (pid: 9055)
[2021-06-04 19:35:15 +0800] [9053] [INFO] Worker exiting (pid: 9053)
[2021-06-04 19:35:15 +0800] [9065] [INFO] Worker exiting (pid: 9065)
[2021-06-04 19:35:15 +0800] [9059] [INFO] Worker exiting (pid: 9059)
但是查看进行,没有相关的进程存活,考虑到当前系统中存在了另外一个gunicorn服务器启动的项目,已经存在很在进程了。我怀疑是gunicorn启动的服务进程太多导致进程被杀死的。于是将本项目的启动线程改为1。
修改:gunicornConfig.py
MVAD: [yxx@svs] ~/adauto$ cat gunicornConfig.py
#from multiprocessing import cpu_count
bind = '0.0.0.0:8080'
#capture_output = False
#daemon = True
#workers = 1
#workers_class = 'sync'
#threads = 1
#timeout = 100000000
pidfile = "gunicorn.pid"
accesslog = "access.log"
errorlog = "debug.log"
(venv) MVAD: [yxx@svs] ~/adauto$
在启动就成功!
MVAD: [xxy@svn1ss] ~/adauto$ ../venv/bin/gunicorn --config gunicornConfig.py manage:ad_atuo_system
curl实验下:
curl 'http://localhost:8080/ad_test'
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="favicon.ico"><link rel="stylesheet" href="https://unpkg.com/element-plus/lib/theme-chalk/index.css"><script src="https://unpkg.com/element-plus/lib/index.full.js"></script><title>验收用例展示</title><link href="../static/css/chunk-vendors.96e07e94.css" rel="preload" as="style"><link href="../static/css/index.cee3958b.css" rel="preload" as="style"><link href="../static/js/chunk-vendors.b4ea8922.js" rel="preload" as="script"><link href="../static/js/index.795e8756.js" rel="preload" as="script"><link href="../static/css/chunk-vendors.96e07e94.css" rel="stylesheet"><link href="../static/css/index.cee3958b.css" rel="stylesheet"></head><body><input id="get_data_dom" type="hidden" value=""><div id="app"></div><script src="../static/js/chunk-vendors.b4ea8922.js"></script><script src="../static/js/index.795e8756.js"></script></body></html>(venv) MVAD: [yuxuanxuan@svn1ss] ~$