温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python安装mongodb

发布时间:2020-04-22 22:39:48 来源:网络 阅读:579 作者:yht_1990 栏目:编程语言
#!/usr/bin/env python
#coding:utf-8

import os
import tarfile
import shutil

mongo_package = 'mongodb-linux-x86_64-rhel70-3.2.8.tgz'
mongo_path = '/usr/local/mongodb'
script_path = os.getcwd()
line = os.linesep

t = tarfile.open(mongo_package,'r')
t.extractall()
t.close()
shutil.move(script_path+'/mongodb-linux-x86_64-rhel70-3.2.8',mongo_path)
mongo_dir = [mongo_path+'/conf','/data/mongodb/logs','/data/mongodb/db']
for dirs in mongo_dir:
    os.makedirs(dirs)
shutil.copyfile(script_path+'/mongodb.conf',mongo_path+'/conf/mongodb.conf')
shutil.copyfile(script_path+'/mongod','/etc/init.d/mongod')
with open('/etc/profile','a')as f:
        f.write("export PATH=/usr/local/mongodb/bin:$PATH%sexport LC_ALL=C%s" % (line,line))
list = ['chmod +x /etc/init.d/mongod','service mongod start','source /etc/profile']
for i in list:
    os.system(i)
~                 
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI