安装:sudo apt-get install python-tornado

sudo apt-get install nginx

sudo apt-get install supervisor

1. 配置nginx。我安装的nginx的目录为2个配置文件。/etc/nginx/nginx.conf   和  /etc/nginx/conf.d/foo.conf.

实际上是nginx.conf包含了文件foo.conf

所以如果没有特殊需求,就不需要更改nginx.conf了,在conf.d文件夹下新建你的conf文件。

 

foo.conf的内容;

upstream  foo  {
#ip_hash;
#consistent_hash $args;这里就是你需要nginx帮你代理的端口,下面的意思是将访问80端口的请求分配到6900,6901,6902上去。其他的无需更改。如果你不用supervisor,那就需要手工运行你的web程序,监听6900,6901,6902
server 127.0.0.1:6900 weight=1 max_fails=2 fail_timeout=30s;
server 127.0.0.1:6901 weight=1 max_fails=2 fail_timeout=30s;
server 127.0.0.1:6902 weight=1 max_fails=2 fail_timeout=30s; } server {
listen 80;
server_tag off;
index index.html;
charset utf-8; location / {
proxy_read_timeout 100;
proxy_pass_header User-Agent;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_set_header Accept-Encoding 'gzip';
proxy_pass http://foo;
proxy_redirect off;
proxy_store off; } location /stat {
stub_status on;
access_log off;
} proxy_buffering off; }

3. 运行nginx:sudo /usr/sbin/nginx

如果发生这个错误:

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

原因是80已经被占用了,很有可能是被nginx占用了,

找到进程结束掉或者结束掉nginx进程。/usr/sbin/nginx -s stop

4. /etc/supervisor/supervisord.conf内容:()

[unix_http_server]
file=/var/run//supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700) [supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP) ; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl]
serverurl=unix:///var/run//supervisor.sock ; use a unix:// URL  for a unix socket ; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves. [include]
files = /etc/supervisor/conf.d/*.conf##这里就是include了具体的配置文件,你需要在/etc/supervisor/conf.d/文件夹下新建conf文件。

比如你在conf.d文件夹下新建的tornado.conf的文件

[program:tornado-80]
command=python /var/www/starter.py 6901 #这里就是运行web,如果跟nginx结合,还需要监听6902,6900端口
directory=/var/www/
user=www-data
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/tornado.log
loglevel=info

启动supervisor:

Usage: /etc/init.d/supervisord {start|stop|restart|force-reload|status|force-stop}
进入supervisor命令行:

sudo supervisorctl

5. 守护supervisor进程:

#!/bin/sh

pywebn=`ps aux | grep supervisord | grep -v "grep" | wc -l`; #wc -l  的意思是输出文件的行数,如果不等于1,则说明没有运行了,需要再启动下

if [ "$pywebn" != "" ]; then
sleep 1;
/usr/bin/python /usr/local/bin/supervisord -c /etc/supervisord.conf; else
break;
fi

6. 排错

INFO gave up: tornado entered FATAL state, too many start retries too quickly

这个网上有很多个情况,基本上是因为你的程序执行了就退出了,然后又执行,又退出,导致的

要看看你的程序是否有问题,我的情况是python web.py 80 的时候就有问题,换成python web.py 8888 就没问题了。

直接在shell中执行python  web.py 80  就没有问题

如果supervisor有问题,除了需要看/var/log/supervisor/supervisord.log还要看你配置的log,如/var/log/tornado.log

tornado nginx supervisor的更多相关文章

  1. centos 6.7 搭建tornado + nginx + supervisor的方法(已经实践)

    首先,本来不想写这篇博客了,但是我测试了很多网上的例子包括简书的,全不行,我总结原因是自己太笨,搞了俩个晚上,后来决定,自己还是写一篇记录下来,保证自己以后使用 环境: centos6.7 64 py ...

  2. Django 部署 uwsgi + nginx + supervisor

    Django 部署 uwsgi + nginx + supervisor https://hacpai.com/article/1460607620615?p=1&m=0 zonghua • ...

  3. django+nginx+supervisor+gunicorn+gevent 网站部署

    django+nginx+supervisor+gunicorn+gevent 网站部署 django,nginx,supervisor,gunicorn,gevent这几个都是在本领域大名鼎鼎的软件 ...

  4. asp.net core 二 Nginx Supervisor 负载,监听

           ASP.NET Core负载均衡集群搭建(CentOS7+Nginx+Supervisor+Kestrel)          asp.net core在linux运行下,一但命令行退出 ...

  5. [原创]Centos7 安装配置ASP.NET Core+Nginx+Supervisor

    序言 此教程安装的都是最新版本的. 一键安装 有了这个神器,下面的教程就不用做了!只需运行几行代码,直接打开浏览器就可以访问! cd /home/ wget https://files.cnblogs ...

  6. Linux+Nginx+Supervisor部署ASP.NET Core实操手册

    一.课程介绍 在上一节课程<ASP.NET Core托管和部署Linux实操演练手册>中我们学过net core的部署方式多样性和灵活性.我们通过远程工具输入dotnet 程序集名称.dl ...

  7. DigitalOcean上使用Tornado+MongoDB+Nginx+Supervisor+DnsPod快速搭建个人博客

    DigitalOcean 之前买了个便宜的VPS并且在上面搭建了我自己写的博客程序,后来VPS里运行MongoDB经常自己挂掉就索性没理了.直到现在VPS已经过期,服务器被强制关掉了.周末在家索性想着 ...

  8. ubutu tornado python3.7.5 nginx supervisor 部署web api

    环境: 1.Ubuntu 服务器 2.python3.7.5 安装 1.python3.7.5 安装的话还是比较简单,流程大致是./configure ->make && mak ...

  9. tornado + nginx + supervisord 环境部署

    学习tornado有一周多了,自己按着demo中的例子手动搬代码,收获还是有的,加深了理解.demo: http://demo.pythoner.com/itt2zh/ch8.html 大概明白了它怎 ...

随机推荐

  1. 百度的domain命令到底有用吗?

    曾几何时,站长和seoer们在百度输入domain:xxxxxxxx的时候弹出的结果数量让多少人兴奋和失落,为什么我们对百度的domain命令如此着迷呢?因为我们都认为百度的domain命令是查询网站 ...

  2. js定时器 特定时间执行某段程序的例子

    定时器想必大家并不陌生吧,在本文为大家详细介绍下js中是如何实现定时器的,具体原理及代码如下. 例子: $(function(){ var handler = function(){ //www.jb ...

  3. 2013-07-23 IT 要闻速记快想

    ### ========================= ###苹果的新动向今天华尔街日报称,苹果正在测试13英寸的大号iPad,以及更大屏幕的iPhone.而早在五月份,韩国资讯网站 ET New ...

  4. Win7开始菜单之【附件】不全解决方案

    Win7开始菜单之[附件]不全解决方案 1:打开你的[开始]菜单,转到附件,如果你发现你的附件里的“附件”不是那么全的话,如下图:来吧,我告诉你如何恢复它到最初的模样……哦,或许如果你不急于恢复的话, ...

  5. Lambda(2)

    Lambda表达式是匿名方法的超集,处理匿名方法有的功能外,还有其他的功能: 1.能够推测出参数的类型,无需显示声明 2.支持语句块和表达式作为方法体 Lambda表达式的书写方式: Lambda表达 ...

  6. openerp模块收藏 移除下拉选择列表中的“创建并编辑”链接(转载)

    移除下拉选择列表中的“创建并编辑”链接 原文:http://shine-it.net/index.php/topic,5990.0.html 有时希望下拉列表中列出的项是与主表某个字段关联的,用户只能 ...

  7. 1066. Root of AVL Tree (25)

    An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child sub ...

  8. MySQL SHOW 语句大全

    常用的mysql show命令如下: 1.show databases;        显示mysql中所有数据库 2.show tables [from databases] ;     显示当前数 ...

  9. RDD的转换操作---RDD转换过程

    1) union(otherRDD)RDD-->UnionRDD2) groupByKey(numPartitions)RDD-->ShuffledRDD-->MapPartitio ...

  10. 1833: [ZJOI2010]count 数字计数 - BZOJ

    Description给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次.Input输入文件中仅包含一行两个整数a.b,含义如上所述.Output输出文件中包含一 ...