Python deploys the MongoDB database under CENTOS6

Source: Internet
Author: User
Tags mongodb

Note: CENOTS7 system does not need to deploy GLIBC, can directly install the start MongoDB database

The script is as follows

Cat mongodbinstall.py#!/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" Else:print "GL  IBC Decompression succeeded "try:t = Tarfile.open (mongo_package, ' R ') T.extractall () t.close () Except:print "Tar decompression failed" Else:print "MongoDB decompression succeeded" Def CreateDirectory (): Shutil.move (script_path+ '/mongodb-linux-x86_64-rh el70-3.2.8 ', Mongo_path) os.mkdir (mongo_path+ '/conf ') os.makedirs ('/data/mongodb/logs ') os.mkdir ('/data/mongodb/db        ') shutil.copyfile (script_path+ '/mongodb.conf ', mongo_path+ '/conf/mongodb.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 ("yum-y install GCC")        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/local/glibc-2.14 ') os.system (' Make-j4 ') os.system (' make install ') except: Print "Compilation failed, check" Def startservice (): #os. System (' Source/etc/profile ') #os. System ('%s/bin/mongod-f/usr/local/mong Odb/conf/mongodb.conf '% mongo_path) os.system (' sh%s/mongo_start.sh '% script_path) decompression () CreateDirectory () ComPiled () StartService ()

The shell script is as follows

cat mongo_start.sh#!/bin/bashexport PATH=/usr/local/mongodb/bin:$PATHexport LD_LIBRARY_PATH=/usr/local/glibc-2.14/lib:$LD_LIBRARY_PATHexport LC_ALL=C/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb.conf

The configuration file contents are as follows

cat mongodb.confdbpath=/data/mongodb/dblogpath=/data/mongodb/logs/mongodb.logbind_ip=127.0.0.1port=27017fork=truenohttpinterface=trueauth=false

Directory contents are as follows

-rw-r--r-- 1 root root 28208627 Jun  7 03:02 glibc-2.14.zip-rw-r--r-- 1 root root      206 Jun 10 21:07 mongo_start.sh-rw-r--r-- 1 root root 71943658 Dec  4  2017 mongodb-linux-x86_64-rhel70-3.2.8.tgz-rw-r--r-- 1 root root      134 Jun 11  2018 mongodb.conf-rw-r--r-- 1 root root     1853 Jun 10 21:09 mongodbInstall.py-rw-r--r-- 1 root root 97120178 Jun 10 21:09 mongodb_install.tar.gz

Python deploys the MongoDB database under CENTOS6

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.