2009-06-29 67 views
-1

我需要管理几台服务器,网络服务,appalication服务器(Apache,Tomcat)并管理它们(开始停止,安装软件)。Mule vs ActiveMQ for Python

我想使用Python,因为C++似乎复杂和事物的任务生产力较低。我不确定要使用哪个中间件。虽然用Java编写,但ActiveMQ和Mule似乎是一个不错的选择。我更了解ActiveMQ,而且我对ESB知之甚少。

有什么建议吗? Python的任何选项?

我看到有魔豆,但过于简单,不易伸缩。我需要一个消息系统来协调,另外还有一种方法可以将tar.gz文件发送到服务器(软件包)。

我在那里有一个原生在Python中的消息传递解决方案。

+0

首先,你的目标,即说明,管理服务器,你问,即邮件系统,有什么似乎并不匹配得非常好。已经有用于启动和停止和安装软件的系统。不明白为什么要写一个,更不用说为什么你需要一个消息传递系统。其次,你没有真正解释你的消息系统的需求,所以任何人都很难指导你这个话题。 – 2009-06-29 15:47:47

+0

请澄清你的目标。真的说出你想要完成的事情。 – gahooa 2009-06-29 16:10:16

回答

1

一个例子蟒蛇“脚本”对多个远程服务器管理各种服务:

下面是砍死在一起的脚本,它可以被用来对你有SSH访问服务器管理各种服务。

你会非常想有一个SSH代理运行,否则你会打字您的密码了很多次。

对于需要在远程机器上提升权限的命令,你可以看到,“命令”之称。这意味着你需要修改你的sudoers的每个远程机器上的文件,并添加条目就像这样(假设你的用户名== deploy):

Defaults:deploy !requiretty 
Defaults:deploy !authenticate 

deploy ALL=\ 
    /sbin/service httpd status,\ 
    /sbin/service httpd configtest,\ 
    /sbin/service httpd graceful 

前两行允许deploy用户运行sudo而无需tty或重新输入密码 - 这意味着它可以直接通过ssh运行,而无需进一步输入。下面是一个例子Python的命令采取遥控器上的优势sudo

CommandResult = subprocess.call(('ssh', UH, 'sudo /sbin/service httpd graceful')) 

无论如何,这是不是“直线”回答你的问题,而是你如何轻松使用Python的说明和一对夫妇的其他技术来创建一个系统管理工具,该工具可以根据您的特定需求量身定制。

顺便说一下,下面的脚本并“告诉你嘹亮”如果任何命令返回的退出状态> 0,这样你就可以分析自己的输出。

当我正在使用的项目开始使用负载平衡器并且不再公平地在每台服务器上运行所有命令时,它们一起被黑掉。您可以修改或扩展此功能以使用rsync来部署文件,甚至可以将更新部署到您在远程服务器上托管的脚本以“完成任务”。

#!/usr/bin/python 


from optparse import OptionParser 
import subprocess 
import sys 

def die(sMessage): 
     print 
     print sMessage 
     print 
     sys.exit(2) 


################################################################################################### 
# Settings 

# The [email protected]: for the SourceURLs (NO TRAILING SLASH) 
RemoteUsers = [ 
     "[email protected]", 
     "[email protected]", 
     ] 

################################################################################################### 
# Global Variables 

# optparse.Parser instance 
Parser       = None 

# optparse.Values instance full of command line options 
Opt        = None 

# List of command line arguments 
Arg          = None 

################################################################################################### 
Parser = OptionParser(usage="%prog [options] [Command[, Subcommand]]") 


Parser.add_option("--interactive", 
     dest = "Interactive", 
     action = "store_true", 
     default = False, 
     help = "Ask before doing each operation." 
     ) 

# Parse command line 
Opt, Arg = Parser.parse_args() 

def HelpAndExit(): 
     print "This command is used to run commands on the application servers." 
     print 
     print "Usage:" 
     print " deploy-control [--interactive] Command" 
     print 
     print "Options:" 
     print " --interactive :: will ask before executing each operation" 
     print 
     print "Servers:" 
     for s in RemoteUsers: print " " + s 
     print 
     print "Web Server Commands:" 
     print " deploy-control httpd status" 
     print " deploy-control httpd configtest" 
     print " deploy-control httpd graceful" 
     print " deploy-control loadbalancer in" 
     print " deploy-control loadbalancer out" 
     print 
     print "App Server Commands:" 
     print " deploy-control 6x6server status" 
     print " deploy-control 6x6server stop" 
     print " deploy-control 6x6server start" 
     print " deploy-control 6x6server status" 
     print " deploy-control wb4server stop" 
     print " deploy-control wb4server start" 
     print " deploy-control wb4server restart" 
     print " deploy-control wb4server restart" 
     print 
     print "System Commands:" 
     print " deploy-control disk usage" 
     print " deploy-control uptime" 
     print 
     sys.exit(2) 

def YesNo(sPrompt): 
     while True: 
       s = raw_input(sPrompt) 
       if s in ('y', 'yes'): 
         return True 
       elif s in ('n', 'no'): 
         return False 
       else: 
         print "Invalid input!" 


# Implicitly verified below in if/else 
Command = tuple(Arg) 

if Command in (('help',),()): 
     HelpAndExit() 


ResultList = [] 
################################################################################################### 
for UH in RemoteUsers: 
     print "-"*80 
     print "Running %s command on: %s" % (Command, UH) 

     if Opt.Interactive and not YesNo("Do you want to run this command? "): 
       print "Skipping!" 
       print 
       continue 

     #---------------------------------------------------------------------------------------------- 
     if Command == ('httpd', 'configtest'): 
       CommandResult = subprocess.call(('ssh', UH, 'sudo /sbin/service httpd configtest')) 

     #---------------------------------------------------------------------------------------------- 
     elif Command == ('httpd', 'graceful'): 
       CommandResult = subprocess.call(('ssh', UH, 'sudo /sbin/service httpd graceful')) 

     #---------------------------------------------------------------------------------------------- 
     elif Command == ('httpd', 'status'): 
       CommandResult = subprocess.call(('ssh', UH, 'sudo /sbin/service httpd status')) 

     #---------------------------------------------------------------------------------------------- 
     elif Command == ('loadbalancer', 'in'): 
       CommandResult = subprocess.call(('ssh', UH, 'bin-slave/loadbalancer-in')) 

     #---------------------------------------------------------------------------------------------- 
     elif Command == ('loadbalancer', 'out'): 
       CommandResult = subprocess.call(('ssh', UH, 'bin-slave/loadbalancer-out')) 

     #---------------------------------------------------------------------------------------------- 
     elif Command == ('disk', 'usage'): 
       CommandResult = subprocess.call(('ssh', UH, 'df -h')) 

     #---------------------------------------------------------------------------------------------- 
     elif Command == ('uptime',): 
       CommandResult = subprocess.call(('ssh', UH, 'uptime')) 

     #---------------------------------------------------------------------------------------------- 
     elif Command == ('6x6server', 'status'): 
       CommandResult = subprocess.call(('ssh', UH, 'bin-slave/6x6server-status')) 
       if CommandResult > 0: 
         print "Servers not running!!!" 

     #---------------------------------------------------------------------------------------------- 
     elif Command == ('6x6server', 'stop'): 
       CommandResult = subprocess.call(('ssh', UH, 'bin-slave/6x6server-stop')) 

     #---------------------------------------------------------------------------------------------- 
     elif Command == ('6x6server', 'start'): 
       CommandResult = subprocess.call(('ssh', UH, 'bin-slave/6x6server-start')) 

     #---------------------------------------------------------------------------------------------- 
     elif Command == ('6x6server', 'restart'): 
       CommandResult = subprocess.call(('ssh', UH, 'bin-slave/6x6server-restart')) 

     #---------------------------------------------------------------------------------------------- 
     elif Command == ('wb4server', 'status'): 
       CommandResult = subprocess.call(('ssh', UH, 'bin-slave/wb4server-status')) 
       if CommandResult > 0: 
         print "Servers not running!!!" 

     #---------------------------------------------------------------------------------------------- 
     elif Command == ('wb4server', 'stop'): 
       CommandResult = subprocess.call(('ssh', UH, 'bin-slave/wb4server-stop')) 

     #---------------------------------------------------------------------------------------------- 
     elif Command == ('wb4server', 'start'): 
       CommandResult = subprocess.call(('ssh', UH, 'bin-slave/wb4server-start')) 

     #---------------------------------------------------------------------------------------------- 
     elif Command == ('wb4server', 'restart'): 
       CommandResult = subprocess.call(('ssh', UH, 'bin-slave/wb4server-restart')) 

     #---------------------------------------------------------------------------------------------- 
     else: 
       print 
       print "#"*80 
       print 
       print "Error: invalid command" 
       print 
       HelpAndExit() 

     #---------------------------------------------------------------------------------------------- 
     ResultList.append(CommandResult) 
     print 


################################################################################################### 
if any(ResultList): 
     print "#"*80 
     print "#"*80 
     print "#"*80 
     print 
     print "ERRORS FOUND. SEE ABOVE" 
     print 
     sys.exit(0) 

else: 
     print "-"*80 
     print 
     print "Looks OK!" 
     print 
     sys.exit(1)