Uwsgi皇帝没有诸侯。

3

我希望你能够帮助我将nginx与uwsgi配置起来,在Arch Linux上操作。我有/etc/uwsgi/emperor.ini和/etc/uwsgi/vassals/myapp.ini两个文件。我的emperor.ini如下:

[uwsgi]
emperor = /etc/uwsgi/vassals
emperor-pidfile = /run/uwsgi/uwsgi.pid
uid = http
gid = http
logto = /var/log/uwsgi/uwsgi.log

myapp.ini

[uwsgi]
chdir = /srv/http/myapp/src/
wsgi-file = run.py
callable = app
processes = 4
threads = 2
offload-threads = 2
stats =  127.0.0.1:9191
max-requests = 5000
master = True
vacuum = True
socket = 127.0.0.1:3031
enable-threads = true
harakiri = 60
logto = /var/log/uwsgi/myapp.log

uwsgi.service [for systemd]

[Unit]
Description=uWSGI Emperor
After=syslog.target

[Service]
PIDFile=/run/uwsgi/uwsgi.pid
ExecStartPre=/bin/mkdir -p /run/uwsgi
ExecStartPre=/bin/chown http:http /run/uwsgi
ExecStart=/usr/bin/uwsgi --ini /etc/uwsgi/emperor.ini
Restart=always
Type=notify
StandardError=syslog
NotifyAccess=main

[Install]
WantedBy=multi-user.target

当运行uwsgi.service时,我会得到以下信息:
uwsgi.service - uWSGI Emperor
   Loaded: loaded (/etc/systemd/system/uwsgi.service; disabled)
   Active: active (running) since Sun 2014-02-02 04:37:04 PST; 34min ago
  Process: 31537 ExecStartPre=/bin/chown http:http /run/uwsgi (code=exited, status=0/SUCCESS)
  Process: 31535 ExecStartPre=/bin/mkdir -p /run/uwsgi (code=exited, status=0/SUCCESS)
 Main PID: 31540 (uwsgi)
   Status: "The Emperor is governing 0 vassals"
   CGroup: /system.slice/uwsgi.service
           ââ31540 /usr/bin/uwsgi --ini /etc/uwsgi/emperor.ini

Feb 02 04:37:04 MyMachine uwsgi[31540]: [uWSGI] getting INI configuration from /etc/uwsgi/emperor.ini
Feb 02 04:37:04 MyMachine systemd[1]: Started uWSGI Emperor.

那段代码?“皇帝统治0个附属国”的原因是它无法查看vassal目录中的myapp.ini文件。这是我在命令行“日志”中收到的信息:

*** Starting uWSGI 2.0 (64bit) on [Sun Feb  2 05:27:37 2014] ***
compiled with version: 4.8.2 20131219 (prerelease) on 09 January 2014 11:43:55
os: Linux-3.12.7-2-ARCH #1 SMP PREEMPT Sun Jan 12 13:09:09 CET 2014
nodename: MyMachine
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /home/me
detected binary path: /usr/bin/uwsgi
your processes number limit is 26743
your memory page size is 4096 bytes
 *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
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 TCP address 127.0.0.1:3031 fd 3
Python version: 2.7.6 (default, Nov 26 2013, 12:52:49)  [GCC 4.8.2]
Python main interpreter initialized at 0xcfd340
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 415280 bytes (405 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0xcfd340 pid: 32089 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 32089)
spawned uWSGI worker 1 (pid: 32092, cores: 2)
spawned 2 offload threads for uWSGI worker 1
spawned uWSGI worker 2 (pid: 32095, cores: 2)
spawned uWSGI worker 3 (pid: 32097, cores: 2)
spawned 2 offload threads for uWSGI worker 3
spawned uWSGI worker 4 (pid: 32100, cores: 2)
spawned 2 offload threads for uWSGI worker 2
spawned 2 offload threads for uWSGI worker 4

我无论如何都似乎无法让uwsgi运行并看到它的vassals。谢谢。
编辑
好吧,我决定回到命令行,这样我就不必处理日志和pid权限错误,我注意到了一些奇怪的事情。当我写出uwsgi --ini /etc/uwsgi/emperor.ini时,整个过程都可以工作,我可以通过nginx访问网站,非常好,但我在控制台输出中看到了这个:
    *** Starting uWSGI 2.0 (64bit) on [Sun Feb  2 15:19:43 2014] ***
compiled with version: 4.8.2 20131219 (prerelease) on 09 January 2014 11:43:55
os: Linux-3.12.9-2-ARCH #1 SMP PREEMPT Fri Jan 31 10:22:54 CET 2014
nodename: MyMachine
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /home/me
detected binary path: /usr/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 26743
your memory page size is 4096 bytes
detected max file descriptor number: 1024
*** starting uWSGI Emperor ***
*** has_emperor mode detected (fd: 5) ***
[uWSGI] getting INI configuration from /etc/uwsgi/emperor.ini
*** Starting uWSGI 2.0 (64bit) on [Sun Feb  2 15:19:43 2014] ***
compiled with version: 4.8.2 20131219 (prerelease) on 09 January 2014 11:43:55
os: Linux-3.12.9-2-ARCH #1 SMP PREEMPT Fri Jan 31 10:22:54 CET 2014
nodename: MyMachine
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /home/me
detected binary path: /usr/bin/uwsgi
your processes number limit is 26743
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)
*** starting uWSGI sub-Emperor ***
Python version: 2.7.6 (default, Nov 26 2013, 12:52:49)  [GCC 4.8.2]
*** has_emperor mode detected (fd: 7) ***
[uWSGI] getting INI configuration from myapp.ini
*** Starting uWSGI 2.0 (64bit) on [Sun Feb  2 15:19:43 2014] ***
compiled with version: 4.8.2 20131219 (prerelease) on 09 January 2014 11:43:55
os: Linux-3.12.9-2-ARCH #1 SMP PREEMPT Fri Jan 31 10:22:54 CET 2014
nodename: MyMachine
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /etc/uwsgi/vassals
detected binary path: /usr/bin/uwsgi
your processes number limit is 26743
your memory page size is 4096 bytes
 *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
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 TCP address 127.0.0.1:3031 fd 3
Python version: 2.7.6 (default, Nov 26 2013, 12:52:49)  [GCC 4.8.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x2403ab0
your mercy for graceful operations on workers is 60 seconds
*** Operational MODE: no-workers ***
spawned uWSGI master process (pid: 1640)
Sun Feb  2 15:19:43 2014 - [emperor] vassal /etc/uwsgi/emperor.ini has been spawned
Python main interpreter initialized at 0x17682a0
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 415280 bytes (405 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x17682a0 pid: 1642 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1642)
Sun Feb  2 15:19:45 2014 - [emperor] vassal myapp.ini has been spawned
spawned uWSGI worker 1 (pid: 1645, cores: 2)
spawned 2 offload threads for uWSGI worker 1
spawned uWSGI worker 2 (pid: 1648, cores: 2)
Sun Feb  2 15:19:45 2014 - [emperor] vassal myapp.ini is ready to accept requests
spawned 2 offload threads for uWSGI worker 2
spawned uWSGI worker 3 (pid: 1651, cores: 2)
spawned 2 offload threads for uWSGI worker 3
spawned uWSGI worker 4 (pid: 1657, cores: 2)
*** Stats server enabled on 127.0.0.1:9191 fd: 16 ***
spawned 2 offload threads for uWSGI worker 4
[pid: 1648|app: 0|req: 1/1] 192.168.1.156 () {40 vars in 795 bytes} [Sun Feb  2 15:20:40 2014] GET /articles => generated 2943 bytes in 164 msecs (HTTP/1.1 200) 3 headers in 283 bytes (1 switches on core 0)
announcing my loyalty to the Emperor...
Sun Feb  2 15:20:40 2014 - [emperor] vassal myapp.ini is now loyal
[pid: 1657|app: 0|req: 1/2] 192.168.1.156 () {40 vars in 792 bytes} [Sun Feb  2 15:20:41 2014] GET /index => generated 3216 bytes in 184 msecs (HTTP/1.1 200) 3 headers in 283 bytes (1 switches on core 0)
announcing my loyalty to the Emperor...
Sun Feb  2 15:20:42 2014 - [emperor] vassal myapp.ini is now loyal

我开始注意到输出中出现了一些奇怪的行为。最终,我找到了这个配置,让我能够看到我的网站。
emperor.ini
[uwsgi]
emperor = /etc/uwsgi/vassals
master = true
#gid = http
#uid = http

我注释掉了gid和uid,因为如果它们存在,当我尝试连接到我的网站时会得到一个错误的网关响应,并且日志中会警告我uWSGI以root身份运行,您可以使用--uid/--gid/--chroot选项,但我不确定该怎么做。

myapp.ini

[uwsgi]
chdir = /srv/http/myapp/src/
wsgi-file = run.py
callable = app
processes = 4
threads = 2
offload-threads = 2
stats =  127.0.0.1:9191
max-requests = 5000
master = true
vacuum = true
socket = 127.0.0.1:3031
harakiri = 60

uwsgi.service

[Unit]
Description=uWSGI Emperor
After=syslog.target

[Service]
ExecStart=/usr/bin/uwsgi --ini /etc/uwsgi/emperor.ini --enable-threads
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=main

[Install]
WantedBy=multi-user.target

不知道该怎么办,才能让它不以root权限运行。


从你的日志中可以明显看出应用程序已经启动并正在运行。你的问题是什么?那个systemd消息是在启动时设置(显然为零),并且在添加或删除vassals时更新。 - roberto
如何添加/删除附属国? - user747944
1个回答

0

/etc/uwsgi/vassals/中创建一个vassals


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接