2013-02-28 503 views
12

我準備將nginx/uwsgi與燒瓶用於我正在開發的網站,但我遇到了問題。注意網站本身運行良好使用燒瓶的調試:5000端口,但我想現在投入生產。解釋我做了什麼。只能以root身份運行uwsgi

這是一個的Linode的Ubuntu 12.04LTS服務器,我安裝了它這樣的:

# install nginx 
sudo apt-get install python-software-properties 
sudo add-apt-repository ppa:nginx/stable 
sudo apt-get update 
sudo apt-get upgrade --show-upgraded 
sudo apt-get install nginx-full 
# installing uwsgi 
sudo apt-get install build-essential python-dev libxml2-dev 
sudo apt-get install libc6 libexpat1 libgd2-xpm libgeoip1 libpam0g libpcre3 libssl1.0.0 libxml2 libxslt1.1 zlib1g 
sudo pip install uwsgi 
# python basics 
sudo apt-get install python-pip build-essential python-dev 
sudo pip install virtualenv 
sudo pip install virtualenvwrapper 
sudo mkdir -p /srv/www/li/ 
cd /srv/www/li/ 
virtualenv venv 
source /srv/www/li/venv/bin/activate 
pip install flask 

然後我開始配置一切,但我已經運行到與uwsgi麻煩(沒關係NGINX,這將是。下一步

sudo nano /etc/uwsgi/apps-available/li.xml 

    <uwsgi> 
    <plugin>python</plugin> 
    <socket>/run/uwsgi/app/li.socket</socket> 
    <chmod-socket>666</chmod-socket> 
    <chdir>/srv/www/li</chdir> 
    <pythonpath>/srv/www/li</pythonpath> 
    <virtualenv>/srv/www/li/venv</virtualenv> 
    <module>li</module> 
    <wsgi-file>/srv/www/li/li.py</wsgi-file> 
    <callable>app</callable> 
    <master/> 
    <processes>4</processes> 
    <harakiri>60</harakiri> 
    <reload-mercy>8</reload-mercy> 
    <cpu-affinity>1</cpu-affinity> 
    <stats>/tmp/stats.socket</stats> 
    <max-requests>2000</max-requests> 
    <limit-as>512</limit-as> 
    <reload-on-as>256</reload-on-as> 
    <reload-on-rss>192</reload-on-rss> 
    <no-orphans/> 
    <vacuum/> 
</uwsgi> 

sudo ln -s /etc/uwsgi/apps-available/li.xml /etc/uwsgi/apps-enabled/li.xml 

但是,如果我運行它,我得到:

uwsgi --xml /etc/uwsgi/apps-enabled/li.xml 

[uWSGI] parsing config file /etc/uwsgi/apps-enabled/li.xml 
open("./python_plugin.so"): No such file or directory [core/utils.c line 4755] 
!!! UNABLE to load uWSGI plugin: ./python_plugin.so: cannot open shared object file: No such file or directory !!! 
*** Starting uWSGI 1.4.6 (64bit) on [Thu Feb 28 16:30:53 2013] *** 
compiled with version: 4.6.3 on 28 February 2013 12:38:22 
os: Linux-3.7.10-x86_64-linode30 #1 SMP Wed Feb 27 14:29:31 EST 2013 
nodename: demo 
machine: x86_64 
clock source: unix 
detected number of CPU cores: 4 
current working directory: /run/uwsgi/app 
detected binary path: /usr/local/bin/uwsgi 
your processes number limit is 63594 
limiting address space of processes... 
your process address space limit is 536870912 bytes (512 MB) 
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 
uwsgi socket 0 bound to UNIX address /run/uwsgi/app/li.socket fd 3 
Python version: 2.7.3 (default, Aug 1 2012, 05:25:23) [GCC 4.6.3] 
Set PythonHome to /srv/www/li/venv 
*** Python threads support is disabled. You can enable it with --enable-threads *** 
Python main interpreter initialized at 0xa86e20 
your server socket listen backlog is limited to 100 connections 
mapped 362120 bytes (353 KB) for 4 cores 
*** Operational MODE: preforking *** 
added /srv/www/li/ to pythonpath. 
/srv/www/li/venv/local/lib/python2.7/site-packages/mongoengine/fields.py:744: FutureWarning: ReferenceFields will default to using ObjectId strings in 0.8, set DBRef=True if this isn't desired 
    warnings.warn(msg, FutureWarning) 
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0xa86e20 pid: 14934 (default app) 
*** uWSGI is running in multiple interpreter mode *** 
spawned uWSGI master process (pid: 14934) 
spawned uWSGI worker 1 (pid: 14940, cores: 1) 
mapping worker 1 to CPUs: 0 
spawned uWSGI worker 2 (pid: 14941, cores: 1) 
mapping worker 2 to CPUs: 1 
spawned uWSGI worker 3 (pid: 14942, cores: 1) 
mapping worker 3 to CPUs: 2 
spawned uWSGI worker 4 (pid: 14943, cores: 1) 
unlink(): Operation not permitted [core/socket.c line 109] 
bind(): Address already in use [core/socket.c line 141] 
...brutally killing workers... 
mapping worker 4 to CPUs: 3 
VACUUM: unix socket /run/uwsgi/app/li.socket removed. 

,所以我得到不允許取消鏈接操作,並且綁定地址已經在使用錯誤(在python_plugin錯誤旁邊,我也沒有線索如何解決這個錯誤!)。如果我作爲sudo運行,它似乎工作正常 - >

sudo uwsgi --xml /etc/uwsgi/apps-enabled/li.xml 

[uWSGI] parsing config file /etc/uwsgi/apps-enabled/li.xml 
open("./python_plugin.so"): No such file or directory [core/utils.c line 4755] 
!!! UNABLE to load uWSGI plugin: ./python_plugin.so: cannot open shared object file: No such file or directory !!! 
*** Starting uWSGI 1.4.6 (64bit) on [Thu Feb 28 15:47:41 2013] *** 
compiled with version: 4.6.3 on 28 February 2013 12:38:22 
os: Linux-3.7.10-x86_64-linode30 #1 SMP Wed Feb 27 14:29:31 EST 2013 
nodename: demo 
machine: x86_64 
clock source: unix 
detected number of CPU cores: 4 
current working directory: /run/uwsgi 
detected binary path: /usr/local/bin/uwsgi 
uWSGI running as root, you can use --uid/--gid/--chroot options 
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your processes number limit is 63594 
limiting address space of processes... 
your process address space limit is 536870912 bytes (512 MB) 
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 
uwsgi socket 0 bound to UNIX address /run/uwsgi/app/li.socket fd 3 
Python version: 2.7.3 (default, Aug 1 2012, 05:25:23) [GCC 4.6.3] 
Set PythonHome to /srv/www/li/venv 
*** Python threads support is disabled. You can enable it with --enable-threads *** 
Python main interpreter initialized at 0x1fc9d00 
your server socket listen backlog is limited to 100 connections 
mapped 362120 bytes (353 KB) for 4 cores 
*** Operational MODE: preforking *** 
added /srv/www/li/ to pythonpath. 
/srv/www/li/venv/local/lib/python2.7/site-packages/mongoengine/fields.py:744: FutureWarning: ReferenceFields will default to using ObjectId strings in 0.8, set DBRef=True if this isn't desired 
    warnings.warn(msg, FutureWarning) 
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1fc9d00 pid: 14755 (default app) 
*** uWSGI is running in multiple interpreter mode *** 
spawned uWSGI master process (pid: 14755) 
spawned uWSGI worker 1 (pid: 14761, cores: 1) 
mapping worker 1 to CPUs: 0 
spawned uWSGI worker 2 (pid: 14762, cores: 1) 
mapping worker 2 to CPUs: 1 
spawned uWSGI worker 3 (pid: 14763, cores: 1) 
mapping worker 3 to CPUs: 2 
spawned uWSGI worker 4 (pid: 14764, cores: 1) 
*** Stats server enabled on /tmp/stats.socket fd: 16 *** 
mapping worker 4 to CPUs: 3 

任何人都可以請幫助我嗎?由於WWW的數據是www數據組中,他跑了,我嘗試了一些東西:

sudo usermod -a -G www-data $USER 
sudo chown -R $USER:www-data /srv/www/li 
sudo chmod -R g+r+w+x /srv/www/li 
sudo chown -R $USER:www-data /etc/uwsgi/apps-enabled 
sudo chmod -R g+r+w+x /etc/uwsgi/apps-enabled 
sudo chown -R $USER:www-data /run/uwsgi/app 
sudo chmod -R g+r+w+x /run/uwsgi/app 

但真的沒有幫助。我也嘗試了一個tcp端口,而不是unix/run/uwsgi/app/port,這兩個端口沒有任何區別... 這讓我很瘋狂:(我希望有人對這裏發生的事情有一點線索

親切的問候,

岩溶

編輯:

[email protected]:~$ uwsgi --xml /etc/uwsgi/apps-enabled/li.xml 
[uWSGI] parsing config file /etc/uwsgi/apps-enabled/li.xml 
*** Starting uWSGI 1.4.6 (64bit) on [Thu Feb 28 18:47:36 2013] *** 
compiled with version: 4.6.3 on 28 February 2013 12:38:22 
os: Linux-3.7.10-x86_64-linode30 #1 SMP Wed Feb 27 14:29:31 EST 2013 
nodename: demo 
machine: x86_64 
clock source: unix 
detected number of CPU cores: 4 
current working directory: /home/geoadmin 
detected binary path: /usr/local/bin/uwsgi 
your processes number limit is 63594 
limiting address space of processes... 
your process address space limit is 536870912 bytes (512 MB) 
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 
bind(): No such file or directory [core/socket.c line 141] 

回答

6

好,後來編輯後,我檢查的目錄和插座:在服務器重新啓動它仍然給了埃羅但不同的一個後目錄不存在(不再);我瘦k它必須使用原始apt-get安裝與我以後的pip安裝...仍然有問題與python插件,但會檢查是否需要爲nginx或如果它將工作沒有它... 8小時的工作在復位,德哦;)

@bearrito: 在我把插座的tmp目錄結束,以避免人權問題:

<uwsgi> 
     <uid>www-data</uid> 
     <gid>www-data</gid> 
    <plugin>python</plugin> 
    <socket>/tmp/li.socket</socket> 
    <chmod-socket>666</chmod-socket> 
    <chdir>/srv/www/li</chdir> 
    <pythonpath>/srv/www/li</pythonpath> 
    <virtualenv>/srv/www/li/venv</virtualenv> 
    <module>li</module> 
    <wsgi-file>/srv/www/li/li.py</wsgi-file> 
    <callable>app</callable> 
    <master/> 
    <processes>2</processes> 
    <pidfile>/tmp/li.pid</pidfile> 
    <harakiri>120</harakiri> 
    <reload-mercy>8</reload-mercy> 
    <cpu-affinity>1</cpu-affinity> 
    <stats>/tmp/stats.socket</stats> 
    <max-requests>2000</max-requests> 
    <limit-as>2048</limit-as> 
    <reload-on-as>2048</reload-on-as> 
    <reload-on-rss>1024</reload-on-rss> 
    <no-orphans/> 
    <vacuum/> 
</uwsgi> 

我希望這有助於!

+1

後小評:蟒插件(這是在每個一派示例)在新版本中似乎不再需要。所以最終它確實比我以前想象的更容易和開箱即用! – Carst 2013-03-03 21:02:38

+0

你能更清楚地知道你的修補程序需要什麼嗎?我的情況完全相同,但我無法破譯我的案例中可重現的內容。 – bearrito 2013-03-06 05:30:38

+0

用我所做的來編輯它!另外:我的工作者的內存限制是真的,所以不要複製:)(與一個沉重的分析過程有關) – Carst 2013-03-06 19:11:39

17

這一直是我在google上的第一個結果,而且這個頁面對我來說相對沒有幫助,所以我會添加我的答案,即使它在回顧過程中顯而易見。

我的問題是我的統計套接字的權限問題。如果您更改了uWSGI配置的uid或gid參數,請確保您或者chmod或rm所有舊套接字/ pid,以及它們的父文件夾

+0

嗨,很抱歉聽到它沒有幫助你。這就是我的意思是「最終我把套接字放在tmp目錄中以避免版權問題」的評論,但你說得對,它可能會少一點隱密。這個問題也是由於我同時有兩個問題,另一個問題造成的:http://stackoverflow.com/questions/15936413/pip-installed-uwsgi-python-plugin-so-error – Carst 2013-10-04 08:15:40

+3

對不起,並不意味着攻擊你的答案,只是在下一次我加入到這個頁面時才加入它。恕我直言,來自uWSGI的日誌消息在處理這個問題上完全沒有幫助。 – pnovotnak 2013-10-04 15:21:33

+1

別擔心,沒有看到它那樣。我會編輯答案,以幫助人們更好。基本上問題是,你可以同時有兩個單獨的問題(python插件問題+權利套接字問題),這也給我一個頭痛的原因,因此上面的原始答案如此廣泛 – Carst 2013-10-07 10:32:15

0

對我來說,解決辦法是刪除/var/run/uwsgi/.sock和

chmod 775 /var/run/uwsgi 
chmod 777 /var/log/uwsgi 

或任何你uwsgi文件。

7

在我來說,我是想放置.sock文件中/vagrant目錄,這是虛框的一臺機器安裝文件夾,不利於遠遠超過讀取和寫入。

放置.sock文件的virtualbox以外掛載點優選在/tmpFHS說:/var/run

價: https://stackoverflow.com/a/7580524/1695680

+0

這對我來說真的很有用。 – cjauvin 2016-10-10 18:57:24

+0

這裏的權利應該是答案 – Jeremy 2016-12-01 19:54:01

相關問題