Note: This environment only applies to the CENTOS6 version of the system, version 7 does not need to be installed glibc
#!/usr/bin/env python#coding:utf-8import osimport zipfileimport tarfileimport shutilline = Os.linesepscript_path = OS.GETCWD () glibc_package = ' glibc-2.14.zip ' mongo_package = ' mongodb-linux-x86_64-rhel70-3.2.8.tgz ' Mongo_path = '/usr ' /local/mongodb/' def decompression (): Try:z = ZipFile. ZipFile (Glibc_package, ' R ') Z.extractall () z.close () except:print "Zip decompression failed" try:t = TA Rfile.open (Mongo_package, ' R ') T.extractall () t.close () Except:print "Tar decompression failed" Def CreateDirectory ( ): Shutil.move (script_path+ '/mongodb-linux-x86_64-rhel70-3.2.8 ', Mongo_path) Os.mkdir (mongo_path+ ' conf ') Os.makedi RS ('/data/mongodb/logs ') os.mkdir ('/data/mongodb/db ') shutil.move (script_path+ '/mongodb.conf ', mongo_path+ ' conf ') With open ('/etc/profile ', ' a ') as F:f.write ("Export path=/usr/local/mongodb/bin: $PATH%sexport ld_library_path=/usr/ Local/glibc-2.14/lib: $LD _library_path%sexport lc_all=c%s "% (line,line,line)) Os.chdir (script_path+ '/glibc-2.14 ') os.mkdir (' Build ') os.chdir (' Build ') def comPiled (): Try:os.system ("chmod +x%s/glibc- 2.14/* "% Script_path) Os.system (" chmod +x%s/glibc-2.14/scripts/* "% script_path) os.system (' ... /configure--prefix=/usr/locsal/glibc-2.14 ') os.system (' Make-j4 ') os.system (' make install ') except: Print "Compilation failed, please check" Def startservice (): Os.system (' Source/etc/profile ') os.system ('%sbin/mongod-f/usr/local/mongod B/conf/mongodb.conf '% Mongo_path) decompression () CreateDirectory () comPiled () StartService ()
Python deployment MongoDB database