python安装lap_一个python脚本解决安装mq的依赖问题

该博客介绍了一个Python脚本,用于解决安装MQ时的依赖问题。脚本包含了解压缩文件、检查版本、安装rpm包、修改系统配置等步骤,确保MQ的顺利安装。
摘要由CSDN通过智能技术生成

import tarfile

import sys,os

from _utils.patrol2 import run_cmd

import zipfile

def get_version(filename):

cmd="rpm -U {}".format(filename)

code,res=run_cmd(cmd,cwd=pkg_unzip_path)

if 'is already installed' in res or '已安装' in res:

return True

else:

return False

def install_pkg(filename):

cmd = "yum -y localinstall {}".format(filename)

code,res=run_cmd(cmd,cwd=pkg_unzip_path)

if code:

print res

sys.exit(1)

if get_version(filename):

return True

else:

return False

def extract(tar_path, target_path):

try:

tar = tarfile.open(tar_path, "r:gz")

file_names = tar.getnames()

for file_name in file_names:

tar.extract(file_name, target_path)

tar.close()

except Exception, e:

print Exception, e

sys.exit(1)

def search(path, word):

for filename in os.listdir(path):

fp = os.path.join(path, filename)

if os.path.isfile(fp) and word in filename:

return filename

elif os.path.isdir(fp):

search(fp, word)

return False

def unpack_zip(filename, destpath, fix_path=None):

zf_obj = zipfile.ZipFile(filename)

if destpath.endswith(':'):

destpath = destpath + os.sep

zf_obj.extractall(path=destpath)

zf_obj.close()

if fix_path:

destpath = os.path.join(destpath, fix_path)

return destpath

if pkg_file.endswith('.gz'):

extract(pkg_file, pkg_unzip_path)

elif pkg_file.endswith('.zip'):

pkg_name=pkg_name.split('.zip')[0]

pkg_unzip_path=unpack_zip(pkg_file, pkg_unzip_path,fix_path=pkg_name)

print '-->解压成功'

code,res=run_cmd('chmod 755 ./lap/jre/jre/bin/java', cwd=pkg_unzip_path)

if code:

print 'java执行权限赋权失败',res

sys.exit(1)

else:

print 'java执行权限赋权成功'

#接受授权认证

cmd = "sh mqlicense.sh<

code,res = run_cmd(cmd,cwd=pkg_unzip_path)

if code:

print res

sys.exit(1)

else:

print res

print '-->权限认证成功'

#1、安装系统依赖包

print '开始安装rpm包,请等待'

names=["MQSeriesRuntime","MQSeriesSDK","MQSeriesJava","MQSeriesClient","MQSeriesSamples","MQSeriesServer"]

for name in names:

filename=search(pkg_unzip_path, name)

if not filename:

print '{}相关的包不存在'.format(name)

sys.exit(1)

elif get_version(filename):

print '{}已安装'.format(filename)

elif filename and not get_version(filename):

res=install_pkg(filename)

if res:

print '安装{}成功'.format(filename)

else:

print '安装{}失败'.format(filename)

sys.exit(1)

print '-->依赖包安装成功'

#2、修改系统limits参数

with open('/etc/security/limits.conf','a') as f:

f.write("mqm soft nofile 10240\nmqm hard nofile 10240\nmqm soft nproc 4096\n")

print '-->修改系统limits参数成功'

#3、修改系统核心参数

with open('/etc/sysctl.conf','a') as f:

f.write("kernel.sem = 500 256000 250 1024\nfs.file-max = 524288\nnet.ipv4.tcp_keepalive_time = 300\n")

cmd = "sysctl -p"

code,res=run_cmd(cmd,cwd=pkg_unzip_path)

if 'kernel.sem = 500 256000 250 1024\nfs.file-max = 524288\nnet.ipv4.tcp_keepalive_time = 300' in res:

print '-->修改系统核心参数成功'

else:

print '-->修改系统核心参数失败'

sys.exit(1)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值