LAMP一鍵安裝包(Python版)

去年有出一個 python整的LAMP自動安裝,不過比較傻,直接調用的yum 去安裝了XXX...不過此次同樣有用shell..我也想如何不調用shell 來弄一個LAMP自動安裝部署啥啥的..不過尼瑪智商有限,沒搞定,暫且分享一下

  先說說目前的缺陷php

    這個腳本整體來講是調用一個字典,組成這個字典是最花費時間的,實際代碼到是沒幾行,原本想把Nginx 的部署也加進去,什麼memcached phpmyadmin apc 這樣的經常使用組件做爲功能加進去,尼瑪,時間不夠,只能打打醬油,包括最後我也只能用一行行if來讓腳本能run起來,好吧,我想時間充足了必定要改進下,若是你看到此代碼,若是仔細看看啊,對...日誌記錄這塊,由於我沒有判斷異常,函數執行失敗,腳本不會寫日誌,有時間改一下,不過近期不太會改。

注:
     廢話也很少說,這個腳本沒有多少實用性,僅做分享學習之意吧,注(這類腳本仍是用shell簡單粗暴),有時間我也會改進它,也歡迎各位大牛來一塊兒XXX

  軟件版本:html

###怎麼是這麼奇葩的組合###
##等Nginx 加入的時候再改好了,只因此這麼用是公司內部有套系統PHP版本要求高..因此直接用這個測試了..跑的也還行###
[root@ipython ~]# ls source/*.bz2 | sort
source/apr-1.5.1.tar.bz2
source/apr-util-1.5.3.tar.bz2
source/curl-7.36.0.tar.bz2
source/freetype-2.5.2.tar.bz2
source/httpd-2.4.9.tar.bz2
source/jpegsrc.v9a.tar.bz2
source/libmcrypt-2.5.8.tar.bz2
source/libpng-1.6.8.tar.bz2
source/libxml2-2.8.0.tar.bz2
source/mysql-5.1.58.tar.bz2
source/ncurses-5.9.tar.bz2
source/pcre-8.35.tar.bz2
source/php-5.5.12.tar.bz2
source/xcache-3.1.0.tar.bz2
source/zlib-1.2.8.tar.bz2

  部分代碼以下(具體看附件吧):python

#!/usr/bin/python
##coding:utf-8##
#-------------------------------------------------------------------------------
# Name:        LAMP-Auto-Install.py
#
# Author:      LiuSha
#
# Created:     9/07/2014
# Copyright:   (c) http://www.ipython.me/ 2014
#-------------------------------------------------------------------------------
import os
import sys
import time
import getopt
import logging
import commands
from Dict import Global
from platform import machine

#Define Log Output#
logging.basicConfig(filename = os.path.join(os.getcwd(), 'log.txt'),
                    filemode = 'w',
                    level = logging.DEBUG,
                    format = '%(asctime)s %(filename)s %(levelname)s %(message)s',
                    datefmt = '%a,%d %b %Y %H:%M',)

#Define Main Funtion Class#
class funcTion():
    def main(self):
        """define global main config. get global build param"""
        try:
            longargs = ["prefix=","debug=","webservice=","jobdir=","add-vhost=","add-func=","howto="]
            opts,args = getopt.getopt(sys.argv[1:],"h",longargs)
            Global.Mainargs = dict(opts)

        except getopt.GetoptError,err:
            print str(err)
            sys.exit(2)

    def echo(self,output,color = '32'):
        """define calor Output funtion"""
        return '\033[1;{1};40m{0}\033[0m'.format(output,color)
        
    def exec_commands(self,cmd,cmdAlias,istName = ''):
        """define commands exec function"""
        status,output = commands.getstatusoutput("{0}".format(cmd))
        if int(status) == 0:
            logging.info('{0} execution successful -->\n ####---{1}---####'.format(cmdAlias,istName))
        else:
            logging.debug('{0} execution exception -->\n ####---{1}---####\n\n{2}\n\n'.format(cmdAlias,istName,output))

    def Unpack(self,istName,jobdir,tarname,tardir):
        """define unpack function"""
        print self.echo("%s Starting Install".ljust(80)%istName)
        if tarname[-3:] == 'bz2':
            os.chdir("%s"%jobdir)
            os.system("tar jxf %s"%tarname)
            os.chdir("%s"%tardir)
        else:
            print self.echo('[Error1]:Unpark format Error','31')
            
    def command_Check(self,command,istCommand):
        """define Command check via Yum"""
        if os.path.exists("/usr/bin/%s"%command) == False:
            self.exec_commands("yum -y install {0} {1}".format(istCommand,Global.workMode['OutPut']),"yum install {0}".format(command),"command_Check[function]")
        else:
            pass

  如何使用:mysql

##解包##
[root@ipython ~]# unzip LAMP-Auto-Install.zip 
Archive:  LAMP-Auto-Install.zip
   creating: source/
  inflating: source/apr-1.5.1.tar.bz2  
  inflating: source/apr-util-1.5.3.tar.bz2  
   creating: source/conf/
  inflating: source/conf/httpd       
  inflating: source/conf/httpd.conf  
  inflating: source/conf/iptables    
  inflating: source/conf/limits.conf  
  inflating: source/conf/my.cnf      
  inflating: source/conf/mysqld      
  inflating: source/conf/php.ini     
  inflating: source/conf/sysctl.conf  
  inflating: source/curl-7.36.0.tar.bz2  
  inflating: source/freetype-2.5.2.tar.bz2  
  inflating: source/httpd-2.4.9.tar.bz2  
  inflating: source/jpegsrc.v9a.tar.bz2  
  inflating: source/libmcrypt-2.5.8.tar.bz2  
  inflating: source/libpng-1.6.8.tar.bz2  
  inflating: source/libxml2-2.8.0.tar.bz2  
  inflating: source/mysql-5.1.58.tar.bz2  
  inflating: source/ncurses-5.9.tar.bz2  
  inflating: source/pcre-8.35.tar.bz2  
  inflating: source/php-5.5.12.tar.bz2  
  inflating: source/xcache-3.1.0.tar.bz2  
  inflating: source/zlib-1.2.8.tar.bz2  
  inflating: Dict.py                 
  inflating: Main.py

  我也象徵性的整了個Help:nginx

[root@ipython ~]# python Main.py --howto=enable
Usage:
               --prefix [=PATH]:
                        install path
               --jobdir [=PATH]:
                        source code path
               --debug  [enable|disable]:
                        whether friendly output
               --add-vhost [=Domain(www.ipython.com)]:
                        add virtual host
               --add-func  [=xcache]:
                        add function
               --webservice [apache|nginx]:
                        nginx or apache
               
               example:
                   python Main.py --prefix=/software --jobdir=`pwd`/source --webservice=apache --add-func=xcache
                   python Main.py --prefix=/software --jobdir=`pwd`/source --webservice=apache --debug=disable

  run起來:web

 

   有定義logging,會記錄日誌,爲當前目錄中的log.txtsql

  

   服務必須能夠啓動shell

[root@ipython ~]# service mysqld start
Starting MySQL SUCCESS! 
[root@ipython ~]# service httpd start
Starting Apache web server: 

» 轉載保留版權: IT辰逸 »  《LAMP一鍵安裝(Python版)》
» 本文版權採起:  BY-NC-SA 協議進行受權,轉載註明出處。除特別標註,本站全部文章均爲原創。
» 若是喜歡能夠:  點此訂閱本站
相關文章
相關標籤/搜索