用apache2和mod_wsgi重载服务器django部署

时间:2018-06-26 07:13:36

标签: python django apache2 mod-wsgi

我在使用apache2和mod_wsgi部署django时遇到一些重载问题。 按照我的步骤和设置进行操作:

服务器:在Windows Linux子系统(WSL)上运行的Ubuntu 18.04。

安装

sudo apt install python3 python3-dev python3-pip virtualenv
apache2 apache2-dev mysql-server phpmyadmin php-mbstring
php-gettex libmysqlclient-dev

所以,我创建了一个虚拟主机文件

<VirtualHost *:80>
        ServerName 127.0.0.20
        ServerAlias divisor.local

        ErrorLog /mnt/d/divisor/logs/error.log
        CustomLog /mnt/d/divisor/logs/access.log combined
       #provide from mod_wsgi-express --conf
       LoadModule wsgi_module "/mnt/d/divisor/env3/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"


        Alias /static /mnt/d/divisor/framework/static
        Alias /media /mnt/d/divisor/framework/media

        <Directory /mnt/d/divisor/framework>
                <Files wsgi.py>
                Require all granted
                </Files>
         </Directory>

        <Directory /mnt/d/divisor/framework/media/>
                Require all granted
         </Directory>

         <Directory /mnt/d/divisor/framework/static/>
                Require all granted
        </Directory>

WSGIScriptAlias / /mnt/d/divisor/framework/framework/wsgi.py
WSGIDaemonProcess divisor display-name=divisor-modwsgi python-path=/mnt/d/divisor/framework/:/mnt/d/divisor/env3/lib/python3.6/site-packages
WSGIProcessGroup divisor
WSGIApplicationGroup %{GLOBAL}

</VirtualHost>

在启用virtualenv的情况下,我运行:

pip install django mod_wsgi

当我运行apache start时。少于3秒的apache过载(2个过程)。按照终端上的“顶部”:

 PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 6272 www-data  18 42+  318844  31608   8692 S 100.7  0.4   0:13.21 apache2
 6274 www-data  18 42+ 2017236   8668   3924 S 100.7  0.1   0:12.29 apache2

我尝试找到sudo lsof -p 6272的问题,登录

apache2 6272 www-data    0r      CHR    1,3        65583669573738507 /dev/null
apache2 6272 www-data    1w      CHR    1,3        65583669573738507 /dev/null
apache2 6272 www-data    3u     sock    0,0                     8978 can't identify protocol
apache2 6272 www-data    5r     FIFO    0,0                     8995 pipe
apache2 6272 www-data    6w     FIFO    0,0                     8995 pipe
apache2 6272 www-data    8w      REG    0,2      0   562949954063676 /var/log/apache2/other_vhosts_access.log
apache2 6272 www-data    9w      REG   0,13  19168   281474976719069 /mnt/d/divisor/logs/access.log
apache2 6272 www-data   10w      REG    0,2  27268   562949954063675 /var/log/apache2/access.log
apache2 6272 www-data   11u     sock    0,0                     8996 can't identify protocol
apache2 6272 www-data    4r     FIFO    0,0                     8997 pipe
apache2 6272 www-data   12w     FIFO    0,0                     8997 pipe
apache2 6272 www-data    2w      REG   0,13  77784   281474976719068 /mnt/d/divisor/logs/error.log
apache2 6272 www-data    7u  unknown                                 /unknown (stat: Operation not permitted)
apache2 6272 www-data   13u     sock    0,0                     9004 can't identify protocol
apache2 6272 www-data   14u  unknown                                 /unknown (stat: Operation not permitted)

否则,我尝试使用mod_wsgi-express start-server发现更多错误。并再次过载apache2。查看日志:

Server URL         : http://localhost:8000/
Server Root        : /tmp/mod_wsgi-localhost:8000:1000
Server Conf        : /tmp/mod_wsgi-localhost:8000:1000/httpd.conf
Error Log File     : /tmp/mod_wsgi-localhost:8000:1000/error_log (warn)
Request Capacity   : 5 (1 process * 5 threads)
Request Timeout    : 60 (seconds)
Startup Timeout    : 15 (seconds)
Queue Backlog      : 100 (connections)
Queue Timeout      : 45 (seconds)
Server Capacity    : 20 (event/worker), 20 (prefork)
Server Backlog     : 500 (connections)
Locale Setting     : en_US.UTF-8

获取mod_wsgi-express日志:

sudo tail /tmp/mod_wsgi-localhost:8000:1000/error_log

[Tue Jun 26 06:32:28.370796 2018] [mpm_event:notice] [pid 6145:tid 140319572036544] AH00491: caught SIGTERM, shutting down
[Tue Jun 26 06:32:44.994203 2018] [core:warn] [pid 6199:tid 140624007269312] (92)Protocol not available: AH00076: Failed to enable APR_TCP_DEFER_ACCEPT
[Tue Jun 26 06:32:45.002138 2018] [mpm_event:notice] [pid 6199:tid 140624007269312] AH00489: Apache/2.4.29 (Ubuntu) mod_wsgi/4.6.4 Python/3.6 configured -- resuming normal operations
[Tue Jun 26 06:32:45.002276 2018] [core:notice] [pid 6199:tid 140624007269312] AH00094: Command line: 'apache2 (mod_wsgi-express) -f /tmp/mod_wsgi-localhost:8000:1000/httpd.conf -D MOD_WSGI_MPM_ENABLE_EVENT_MODULE -D MOD_WSGI_MPM_EXISTS_EVENT_MODULE -D MOD_WSGI_MPM_EXISTS_WORKER_MODULE -D MOD_WSGI_MPM_EXISTS_PREFORK_MODULE -D FOREGROUND'
[Tue Jun 26 06:34:27.996234 2018] [core:warn] [pid 6199:tid 140624007269312] AH00045: child process 6202 still did not exit, sending a SIGTERM
[Tue Jun 26 06:34:30.006839 2018] [mpm_event:notice] [pid 6199:tid 140624007269312] AH00491: caught SIGTERM, shutting down
[Tue Jun 26 06:59:14.916257 2018] [core:warn] [pid 6353:tid 140711608388544] (92)Protocol not available: AH00076: Failed to enable APR_TCP_DEFER_ACCEPT
[Tue Jun 26 06:59:14.928841 2018] [mpm_event:notice] [pid 6353:tid 140711608388544] AH00489: Apache/2.4.29 (Ubuntu) mod_wsgi/4.6.4 Python/3.6 configured -- resuming normal operations
[Tue Jun 26 06:59:14.928973 2018] [core:notice] [pid 6353:tid 140711608388544] AH00094: Command line: 'apache2 (mod_wsgi-express) -f /tmp/mod_wsgi-localhost:8000:1000/httpd.conf -D MOD_WSGI_MPM_ENABLE_EVENT_MODULE -D MOD_WSGI_MPM_EXISTS_EVENT_MODULE -D MOD_WSGI_MPM_EXISTS_WORKER_MODULE -D MOD_WSGI_MPM_EXISTS_PREFORK_MODULE -D FOREGROUND'
[Tue Jun 26 07:00:07.208780 2018] [mpm_event:notice] [pid 6353:tid 140711608388544] AH00491: caught SIGTERM, shutting down

打印file sample

我希望能正确解释我的问题。

0 个答案:

没有答案