简体   繁体   English

在同一服务器上运行多个Python程序(Ubuntu Server 12.04)

[英]Run multiple Python programs on the same server (Ubuntu Server 12.04)

I am creating a webservice in Python and I have a question. 我正在用Python创建Web服务,并且有一个问题。 I want to separate the user login user data. 我要分离用户登录用户数据。 For this I am creating two different Python programs. 为此,我正在创建两个不同的Python程序。

For example: login.py -> localhost: 8080 userData.py -> localhost: 8081 例如:login.py->本地主机:8080 userData.py->本地主机:8081

My question is: how I can run these two programs on the same server? 我的问题是:如何在同一服务器上运行这两个程序? Is there a Python application server that is easy to use? 是否有易于使用的Python应用程序服务器?

Thank you very much! 非常感谢你!

If the webserver is embedded in the application, you may want to use some "watchdog" application to start/stop/restart. 如果Web服务器嵌入在应用程序中,则可能要使用某些“看门狗”应用程序来启动/停止/重新启动。

Ubuntu uses upstart . Ubuntu使用新贵

I like to use supervisord for this as well. 我也喜欢使用supervisor

If the application supports some webserver integration protocol like FCGI or WSGI (python's standard), you may want to deploy it using a webserver. 如果应用程序支持某种Web服务器集成协议,例如FCGI或WSGI(Python的标准),则您可能希望使用Web服务器进行部署。 I've used apache mod_wsgi for a long time, lately I tend to use nginx +uwsgi. 我已经使用apache mod_wsgi很久了,最近我倾向于使用nginx + uwsgi。 Apache is a fine webserver, but nginx+wsgi scale better. Apache是​​一个很好的网络服务器,但是nginx + wsgi的扩展性更好。

[update] [更新]

Applications use Bottle + PyMongo (MongoDB) What do you recommend to be scalable? 应用程序使用Bottle + PyMongo(MongoDB)对扩展性有何建议?

First you should follow the advice on your framework documentation about deployment (bottle is not verbose about this subject , so I understand why you are asking). 首先,您应该遵循框架文档中有关部署的建议(瓶在这个主题上不是很冗长,因此我理解您为什么要问)。

B1 comment is right. B1评论是正确的。 You definitely want to place the database and application on distinct servers. 您绝对希望将数据库和应用程序放置在不同的服务器上。

For maximum scalability with minimum fuzz you may want to look at some PasS provider like heroku , instructions here . 为了以最小的模糊性获得最大的可伸缩性,您可能需要查看一些PasS提供程序,例如heroku此处提供了说明 This makes sense specially if you are a developer and not a system administrator. 如果您是开发人员而不是系统管理员,那么这特别有意义。

Since you are on Ubuntu, using bash: 由于您使用的是Ubuntu,因此请使用bash:

./login.py &
./userData.py &

This will run both scripts in the background. 这将在后台运行两个脚本。

If you want these scripts to keep on running after you close your shell: 如果您希望这些脚本在关闭外壳后继续运行:

at now < ./login.py
at now < ./userData.py

Tornado is a very easy to use application server. 龙卷风是一个非常易于使用的应用服务器。 You can listen on different ports with different request handlers. 您可以使用不同的请求处理程序在不同的端口上侦听。

It is scalable and can handle thousands of connections. 它具有可伸缩性,可以处理数千个连接。 We use it to handle our console server. 我们使用它来处理控制台服务器。 The simple hello world code really tells you all you need to know. 简单的hello world代码确实可以告诉您所有您需要了解的内容。 I've added another HttpServer so that the single ioloop is handling requests on two different ports : 我添加了另一个HttpServer,以便单个ioloop在两个不同的端口上处理请求:

import tornado.ioloop
import tornado.web
from tornado.httpserver import HttpServer

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

class OtherHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Goodbye, world")

application1 = tornado.web.Application([
    (r"/", MainHandler),
])
application2 = tornado.web.Application([
    (r"/", OtherHandler),
])

if __name__ == "__main__":
    HttpServer(application1).listen(8080)
    HttpServer(application1).listen(8081)
    tornado.ioloop.IOLoop.instance().start()

http://www.tornadoweb.org/ http://www.tornadoweb.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM