Tornado+nginx+supervisor 在生產環境上部署

Tornado 

Tornado 是 FriendFeed 使用的可擴展的非阻塞式 web 服務器及其相關工具的開源版本,是屬於facebook的一個開源項目。Tornado 和現在的主流 Web 服務器框架(包括大多數 Python 的框架)有着明顯的區別:它是非阻塞式服務器,而且速度相當快。得利於其 非阻塞的方式和對 epoll 的運用,Tornado 每秒可以處理數以千計的連接,這意味着對於實時 Web 服務來說,Tornado 是一個理想的 Web 框架。我們開發這個 Web 服務器的主要目的就是爲了處理 FriendFeed 的實時功能 ——在 FriendFeed 的應用裏每一個活動用戶都會保持着一個服務器連接。參考文檔http://www.tornadoweb.org/en/stable/    https://github.com/facebook/tornado

 

nginx就不多說了,很著名的web 服務器。

 

supervisor  

supervisor 是一個守護進程管理軟件,是把linux上衆多的守護進行集中在supervisor  進行統一的管理。

 安裝:

  shell> sudo apt-get  install  supervisor# pip/easy_install

或者用pip 或者easy_install 也可以進行安裝。

安裝後配置文件

/usr/bin/supervisord    --supervisor服務守護進程

/usr/bin/supervisorctl  --supervisor服務控制程序,比如:status/start/stop/restartxx

/etc/supervisor/supervisord.conf   --配置文件,定義服務名稱以及接口等等

 

配置一個守護進程:

    我們在/etc/supervisor/conf.d文件添加文件interview.conf,裏面進行配置

[program:interview] #設置守護進程名
command=python /home/www/python/interview/web.py   #設置command 路徑
autorstart=true    #是否自動啓動
stdout_logfile=/home/www/python/interview/interview.log    #設置日誌路徑

 

shell>sudo/etc/init.d/supervisor  start--啓動supervisor服務

shell>sudo supervisorctl  status   interview  --獲取interview  服務的狀態,因爲是autorstart,這裏已經啓動了

interview   RUNNING pid1159,uptime0:20:32

shell>sudo supervisorctl   stop   interview --停止interview  服務

interview  :stopped

shell>sudo supervisorctl stop interview  --再次停止interview  ,會有錯誤信息

interview  :ERROR(notrunning)

shell>sudo supervisorctl  start  interview  --啓動interview  服務interview  :started

 

參考網站http://supervisord.org 

 

 

用nginx代理轉發Tornado 

 

在nginx sites-enabled 文件夾裏面新建 interview文件

 upstream frontends {
        server 192.168.52.128:8080; #supervisor控制的域名
    }
    server {
        listen 8888;  #監聽端口
        location / {
            proxy_read_timeout 1800;
            proxy_pass_header Server;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
            proxy_pass http://frontends;
        }
    }

 

這樣子我們訪問192.168.52.128:8888就會轉發到192.168.52.128:8080 上,就可以實現nginx配置的Tornado 了。

 

問題:據介紹supervisor是可以通過配置進行web訪問查看的,但本人沒有配置成功!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章