uwsgi使用nginx,systemd emperor没有使用相同的配置和设置

时间:2016-09-01 10:36:58

标签: python nginx flask uwsgi

这里的问题是一切都已配置好,运行没有错误,但我不知道为什么它不起作用。正如你所看到的那样我没有应用程序无法加载错误,我根本没有任何错误,事实上它是最完整的,没有我自从开始以来的错误。然而,500响应。正如我将要解释的那样,这里有很多完整性。如果我把皇帝从混合物中取出,它就可以了,就好了。

我一直试图通过uwsgi / nginx部署一个opensource flask app ceph-dash进行监控。我最终成功了,虽然很痛苦。我写了一篇关于我的成功的要点https://gist.github.com/Lighiche/a6aec14166d62b4f8f013415a2c1f757

但是,因为没有守护进程管理和喜欢我认为最好通过使用uwsgi皇帝添加到我所做的事情,我按照本指南来写信 https://chriswarrick.com/blog/2016/02/10/deploying-python-web-apps-with-nginx-and-uwsgi-emperor/

我在Centos 7上。我已成功运行并在此实现上测试了应用程序,正如您在gist中看到的那样,我实际上不知道如何在不同的场景下配置uwsgi。

然而随着皇帝执行wsgi及其所有配置文件。我收到500响应内部服务器错误。而且我认为这与nginx和皇帝或皇帝之间的交接有关。当我停止uwsgi服务时,我得到502.所以nginx至少看到套接字文件。

WSGI服务器启动日志,全部为绿色

*** Starting uWSGI 2.0.13.1 (64bit) on [Thu Sep  1 11:16:24 2016] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-4) on 02 August 2016 21:07:54
os: Linux-3.10.0-327.28.3.el7.x86_64 #1 SMP Thu Aug 18 19:05:49 UTC 2016
nodename: prdceph-mon00
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /etc/uwsgi.d
detected binary path: /usr/sbin/uwsgi
chdir() to /etc/nginx/sites-enabled/ceph-dash
your processes number limit is 7282
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 /var/run/uwsgi/ceph-dash.sock fd 6
Python version: 2.7.5 (default, Aug 18 2016, 15:58:25)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
Python main interpreter initialized at 0xee1030
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 363840 bytes (355 KB) for 4 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0xee1030 pid: 3236 (default app)
mountpoint  already configured. skip.
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 3236)
spawned uWSGI worker 1 (pid: 3241, cores: 1)
spawned uWSGI worker 2 (pid: 3242, cores: 1)
spawned uWSGI worker 3 (pid: 3243, cores: 1)
spawned uWSGI worker 4 (pid: 3244, cores: 1)
[pid: 3243|app: 0|req: 1/1] 127.0.0.1 () {34 vars in 429 bytes} [Thu Sep  1 11:17:31 2016] GET / => generated 291 bytes in 77 msecs (HTTP/1.1 500) 2 headers in 84 bytes (1 switches on core 0)
announcing my loyalty to the Emperor...

WSGI服务启动日志,全部为绿色

 uwsgi.service - uWSGI Emperor Service
   Loaded: loaded (/usr/lib/systemd/system/uwsgi.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2016-09-01 11:16:24 BST; 2s ago
  Process: 3231 ExecStartPre=/bin/chown uwsgi:uwsgi /run/uwsgi (code=exited, status=0/SUCCESS)
  Process: 3229 ExecStartPre=/bin/mkdir -p /run/uwsgi (code=exited, status=0/SUCCESS)
 Main PID: 3234 (uwsgi)
   Status: "The Emperor is governing 1 vassals"
   CGroup: /system.slice/uwsgi.service
           ├─3234 /usr/sbin/uwsgi --ini /etc/uwsgi.ini
           ├─3235 /usr/sbin/uwsgi --ini /etc/uwsgi.ini
           ├─3236 /usr/sbin/uwsgi --ini cephdash.ini
           ├─3241 /usr/sbin/uwsgi --ini cephdash.ini
           ├─3242 /usr/sbin/uwsgi --ini cephdash.ini
           ├─3243 /usr/sbin/uwsgi --ini cephdash.ini
           └─3244 /usr/sbin/uwsgi --ini cephdash.ini

Sep 01 11:16:24 prdceph-mon00 uwsgi[3234]: thunder lock: disabled (you can enable it with --thunder-lock)
Sep 01 11:16:24 prdceph-mon00 uwsgi[3234]: your mercy for graceful operations on workers is 60 seconds
Sep 01 11:16:24 prdceph-mon00 uwsgi[3234]: *** Operational MODE: no-workers ***
Sep 01 11:16:24 prdceph-mon00 uwsgi[3234]: spawned uWSGI master process (pid: 3234)
Sep 01 11:16:24 prdceph-mon00 uwsgi[3234]: *** Stats server enabled on /run/uwsgi/stats.sock fd: 7 ***
Sep 01 11:16:24 prdceph-mon00 uwsgi[3234]: *** starting uWSGI Emperor ***
Sep 01 11:16:24 prdceph-mon00 uwsgi[3234]: *** has_emperor mode detected (fd: 7) ***
Sep 01 11:16:24 prdceph-mon00 uwsgi[3234]: [uWSGI] getting INI configuration from cephdash.ini
Sep 01 11:16:25 prdceph-mon00 uwsgi[3234]: Thu Sep  1 11:16:25 2016 - [emperor] vassal cephdash.ini has been spawned
Sep 01 11:16:25 prdceph-mon00 uwsgi[3234]: Thu Sep  1 11:16:25 2016 - [emperor] vassal cephdash.ini is ready to accept requests

WSGI服务器响应500

[pid: 3243|app: 0|req: 1/1] 127.0.0.1 () {34 vars in 429 bytes} [Thu Sep  1 11:17:31 2016] GET / => generated 291 bytes in 77 msecs (HTTP/1.1 500) 2 headers in 84 bytes (1 switches on core 0)

NGINX服务器响应500

<ip> - - [01/Sep/2016:11:14:16 +0100] "GET / HTTP/1.1" 500 291 "http://<ip>/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36" "<my ip>, <ip>"
127.0.0.1 - - [01/Sep/2016:11:17:31 +0100] "GET / HTTP/1.1" 500 291 "-" "Python-urllib/2.7" 

cat /etc/uwsgi.ini

[uwsgi]
uid = uwsgi
gid = nginx
pidfile = /run/uwsgi/uwsgi.pid
emperor = /etc/uwsgi.d
stats = /run/uwsgi/stats.sock
#emperor-tyrant = true
cap = setgid,setuid

cat /etc/uwsgi.d/cephdash.ini(这是应用程序的wsgi.ini的符号链接)

[uwsgi]
chdir           = /etc/nginx/sites-enabled/ceph-dash
wsgi-file       = /etc/nginx/sites-enabled/ceph-dash/contrib/wsgi/cephdash.wsgi
module          = ceph-dash:app
enable-threads  = true
master          = true
processes       = 4
socket          = /var/run/uwsgi/ceph-dash.sock
chmod-socket    = 777
vacuum          = true
uid             = uwsgi
gid             = nginx
daemonize       = /tmp/ceph-dash.log
plugins         = python,logfile
logger          = file:/tmp/myappuwsgi.log

cat /etc/nginx/conf.d/cephdash.conf

upstream uwsgi {
    server unix:///var/run/uwsgi/ceph-dash.sock;
}

server {
    listen 5000;
    server_name <hostname>
    charset     utf-8;

    location / {
        uwsgi_pass  uwsgi;
        include     /etc/nginx/sites-enabled/ceph-dash/contrib/nginx/uwsgi_params; 
    }
}

我已经卸载了通过pip安装的uwsgi。我似乎仍然有一个/sbin/uwsgi(从/usr/sbin链接),看起来是为systemd安装的那个,/usr/bin/uwsgi我不知道是怎么回事。我将.service文件更改为使用/usr/bin并出现相同的错误。但是rpm中的二进制文件没有安装plugsin而/usr/bin中的二进制文件没有。 systemd uwsgi现在以/usr/bin/uwsgi开头,正如你在下面看到的那样,二进制文件加载了所需的插件,但是我得到了相同的内部服务器错误,来自systemd和startup的同一消息记录没有错误,没有失败。只需500。

rpm -ql uwsgi
/etc/uwsgi.d
/etc/uwsgi.ini
/run/uwsgi
/usr/lib/systemd/system/uwsgi.service
/usr/sbin/uwsgi
/usr/share/doc/uwsgi-2.0.13.1
/usr/share/doc/uwsgi-2.0.13.1/CHANGELOG
/usr/share/doc/uwsgi-2.0.13.1/README
/usr/share/doc/uwsgi-2.0.13.1/README.Fedora
/usr/share/licenses/uwsgi-2.0.13.1
/usr/share/licenses/uwsgi-2.0.13.1/LICENSE

python --version
Python 2.7.5
uwsgi --version
2.0.13.1
which uwsgi (POINTING TO THE RIGHT PLACE but systemd is now loading /usr/bin)
/sbin/uwsgi

uwsgi --plugins-list (DOES NOT SHOW THE PLUGINS LOADED)

*** uWSGI loaded generic plugins ***
corerouter

*** uWSGI loaded request plugins ***
100: ping
101: echo
--- end of plugins list ---

*** Starting uWSGI 2.0.13.1 (64bit) on [Thu Sep  8 09:58:40 2016] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-4) on 02 August 2016 21:07:54
os: Linux-3.10.0-327.28.3.el7.x86_64 #1 SMP Thu Aug 18 19:05:49 UTC 2016
nodename: prdceph-mon00
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /tmp
detected binary path: /usr/sbin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7282
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)
The -s/--socket option is missing and stdin is not a socket.


/usr/bin/uwsgi --plugins-list
DOES SHOW THE PLUGINS LOADED
*** uWSGI loaded generic plugins ***
gevent
nagios
rrdtool
carbon
corerouter
fastrouter
http
ugreen
syslog
rsyslog
logsocket
router_uwsgi
router_redirect
router_basicauth
zergpool
redislog
mongodblog
router_rewrite
router_http
logfile
router_cache
rawrouter
router_static
sslrouter
cheaper_busyness
transformation_tofile
transformation_gzip
transformation_chunked
transformation_offload
router_memcached
router_redis
router_hash
router_expires
router_metrics
transformation_template
stats_pusher_socket

*** uWSGI loaded request plugins ***
0: python
17: spooler
18: symcall
100: ping
110: signal
111: cache
173: rpc
--- end of plugins list ---

*** Starting uWSGI 2.0.13.1 (64bit) on [Thu Sep  8 09:58:50 2016] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-4) on 29 August 2016 09:55:26
os: Linux-3.10.0-327.28.3.el7.x86_64 #1 SMP Thu Aug 18 19:05:49 UTC 2016
nodename: prdceph-mon00
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /tmp
detected binary path: /usr/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7282
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)
The -s/--socket option is missing and 

2 个答案:

答案 0 :(得分:0)

由yum和pip安装的uWSGI是不同的。 Systemd可能会使用yum安装的一个。当您自己SSH并运行uWSGI时,系统将使用pip默认安装的一个。

uWSGI版本之间的主要区别在于:yum安装了一个python支持,因为它往往是模块化的。您可以使用yum install uwsgi-python安装它(检查您的分发存储库以获取特定的包名称)。请注意,不同的python版本需要不同的python插件(2.7将需要不同于3.5的插件)并调整相应的软件包名称。

安装python插件后,检查插件名称(uWSGI可见)并调整.ini文件中plugins的值。该名称可能与没有uwsgi-前缀的已安装包名称匹配。

答案 1 :(得分:0)

对我来说,我尝试重新启动Nginx,但是它一直显示错误。我发现问题是在sitesavailable文件夹中有一个额外的.conf文件。