@Teslaman

Как задеплоить несколько проектов на uWSGI?

Привет. Бьюсь с проблемой уже третий день, нужна помощь.

Проблема:
Имеется два проекта, один на джанго, другой на фласке, нужно их задеплоить на VPS (Nginx + uWSGI). Nginx настроил без проблем, а вот с uWSGI разобраться не могу.

Настройки:
Для каждого проекта сделано своё виртуальное окружение с установленными зависимостями (python 3.6.6). В самой системе установлены python2.7 и python3.5 (версию 3.6 скомпилил из исходников и положил в /opt, из него и делал virtualenv'ы).
uWSGI установлен общесистемно.

Конфиги:
uWSGI Emperor
[uwsgi]
emperor = /home/teslik/webapps/.uwsgi
uid = www-data
gid = www-data
master = true
enable-threads = true

uWSGI blog
[uwsgi]
socket = /tmp/blog.sock
chmod-socket = 666
chown-socket = www-data:www-data
logfile-chown = true
processes = 1
threads = 2
virtualenv = /home/teslik/webapps/.virtualenvs/blog
chdir = /home/teslik/webapps/apps/blog
wsgi-file = TeslikBlog/wsgi.py
vacuum = true
plugin = python3
logto = /home/teslik/webapps/.logs/blog/uwsgi.log

uWSGI cryptobot
[uwsgi]
socket = /tmp/cryptobot.sock
chmod-socket = 666
chown-socket = www-data:www-data
logfile-chown = true
processes = 1
threads = 2
virtualenv = /home/teslik/webapps/.virtualenvs/cryptobot
chdir = /home/teslik/webapps/apps/cryptobot/app
module = bot:app
vacuum = true
plugin = python3
logto = /home/teslik/webapps/.logs/cryptobot/uwsgi.log


Получаю следующий результат:
systemd

uwsgi.service - uWSGI Emperor
Loaded: loaded (/etc/systemd/system/uwsgi.service; disabled; vendor preset: enabled)
Active: active (running) since Mon 2018-07-23 19:27:44 UTC; 7min ago
Main PID: 18381 (uwsgi)
Status: "The Emperor is governing 2 vassals"
Tasks: 8
Memory: 16.6M
CPU: 144ms
CGroup: /system.slice/uwsgi.service
├─18381 /usr/bin/uwsgi --ini /etc/uwsgi/emperor.ini
├─18384 /usr/bin/uwsgi --ini /etc/uwsgi/emperor.ini
├─18390 /usr/bin/uwsgi-core --ini blog.ini
├─18391 /usr/bin/uwsgi-core --ini cryptobot.ini
├─18392 /usr/bin/uwsgi-core --ini blog.ini
└─18393 /usr/bin/uwsgi-core --ini cryptobot.ini

Jul 23 19:27:44 awshost systemd[1]: Started uWSGI Emperor.
Jul 23 19:27:44 awshost uwsgi[18381]: *** starting uWSGI Emperor ***
Jul 23 19:27:44 awshost uwsgi[18381]: *** has_emperor mode detected (fd: 7) ***
Jul 23 19:27:44 awshost uwsgi[18381]: [uWSGI] getting INI configuration from blog.ini
Jul 23 19:27:44 awshost uwsgi[18381]: *** has_emperor mode detected (fd: 8) ***
Jul 23 19:27:44 awshost uwsgi[18381]: [uWSGI] getting INI configuration from cryptobot.ini
Jul 23 19:27:44 awshost uwsgi[18381]: Mon Jul 23 19:27:44 2018 - [emperor] vassal blog.ini has been spawned
Jul 23 19:27:44 awshost uwsgi[18381]: Mon Jul 23 19:27:44 2018 - [emperor] vassal cryptobot.ini has been spawned
Jul 23 19:27:44 awshost uwsgi[18381]: Mon Jul 23 19:27:44 2018 - [emperor] vassal blog.ini is ready to accept requests
Jul 23 19:27:44 awshost uwsgi[18381]: Mon Jul 23 19:27:44 2018 - [emperor] vassal cryptobot.ini is ready to accept requests
tail -f blof/uwsgi.log

*** Starting uWSGI 2.0.12-debian (64bit) on [Mon Jul 23 19:27:44 2018] ***
compiled with version: 5.4.0 20160609 on 31 August 2017 21:02:04
os: Linux-4.4.0-1062-aws #71-Ubuntu SMP Fri Jun 15 10:07:39 UTC 2018
nodename: awshost
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /home/teslik/webapps/.uwsgi
detected binary path: /usr/bin/uwsgi-core
chdir() to /home/teslik/webapps/apps/blog
your processes number limit is 3900
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/blog.sock fd 3
Python version: 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
PEP 405 virtualenv detected: /home/teslik/webapps/.virtualenvs/blog
Set PythonHome to /home/teslik/webapps/.virtualenvs/blog
Python main interpreter initialized at 0x8730c0
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 166144 bytes (162 KB) for 2 cores
*** Operational MODE: threaded ***
Traceback (most recent call last):
File "TeslikBlog/wsgi.py", line 12, in
from django.core.wsgi import get_wsgi_application
ImportError: No module named 'django'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 18390)
spawned uWSGI worker 1 (pid: 18392, cores: 2)
tail -f cryptobot/uwsgi.log

*** Starting uWSGI 2.0.12-debian (64bit) on [Mon Jul 23 19:27:44 2018] ***
compiled with version: 5.4.0 20160609 on 31 August 2017 21:02:04
os: Linux-4.4.0-1062-aws #71-Ubuntu SMP Fri Jun 15 10:07:39 UTC 2018
nodename: awshost
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /home/teslik/webapps/.uwsgi
detected binary path: /usr/bin/uwsgi-core
chdir() to /home/teslik/webapps/apps/cryptobot/app
your processes number limit is 3900
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/cryptobot.sock fd 3
Python version: 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
PEP 405 virtualenv detected: /home/teslik/webapps/.virtualenvs/cryptobot
Set PythonHome to /home/teslik/webapps/.virtualenvs/cryptobot
Python main interpreter initialized at 0x219f0e0
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 166144 bytes (162 KB) for 2 cores
*** Operational MODE: threaded ***
Traceback (most recent call last):
File "./bot.py", line 1, in
import flask
ImportError: No module named 'flask'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 18391)
spawned uWSGI worker 1 (pid: 18393, cores: 2)
Те же логи картинкой
5b562e61d6b77905951621.png

uWSGI почему-то не импортирует зависимости из виртуальных окружений. Пути в конфигах прописаны верно.
Я уже не знаю куда копать, перечитывал часами документацию, мануалы, так и не понял почему так. Может, найдутся здесь спецы по uWSGI. Буду очень благодарен за помощь.
  • Вопрос задан
  • 464 просмотра
Решения вопроса 1
@lega
> python3.7 -m venv env
> ./env/bin/pip3.7 install flask
> ./env/bin/pip3.7 install uwsgi
> ./env/bin/uwsgi --python-version 
3.7.0

> uwsgi --file app.py -s :80
['.', '', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist-packages']

> ./env/bin/uwsgi --file app.py -s :80
['.', '', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/tmp/env/lib/python3.7/site-packages']
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
24 июл. 2024, в 13:08
1500 руб./в час
24 июл. 2024, в 11:35
10000 руб./за проект
24 июл. 2024, в 11:14
2000 руб./за проект