简易python2创建nginx:
import os
def nginx(dst):
if (os.path.exists(dst)) == False:
os.makedirs(dst)
cmd_yilai = 'yum install -y gcc-c++ \ yum install -y pcre pcre-devel \ yum install -y zlib zlib-devel \ yum install -y openssl openssl-devel'
os.system(cmd_yilai)
cmd_wget = 'wget -P /cj/shell https://nginx.org/download/nginx-1.12.0.tar.gz'
tar = (cmd_wget.split('/')[-1])
name = (cmd_wget.split('/')[-1]).split('.tar.gz')[0]
cmd_tar = 'tar -zxvf ' + dst + '/' + tar + ' -C ' + dst
os.system(cmd_wget)
os.chdir(dst)
os.system(cmd_tar)
os.chdir(dst + '/' + name)
os.remove(dst + os.sep + tar)
bianyi = os.system('./configure')
if bianyi == 0:
os.chdir(dst + '/' + name)
make = 'make && make install'
os.system(make)
os.chdir('/usr/local/nginx/sbin')
test = os.system('./nginx -t')
if test == 0:
os.chdir('/usr/local/nginx/sbin')
finish = os.system('./nginx')
if finish == 0:
os.system('echo successful!')
if __name__ == '__main__':
dst = '/cj/shell'
nginx(dst)