Cacti-Autoinstall

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:
  1. #!/usr/bin/python  
  2. #  
  3. import os,shutil,urllib,MySQLdb,sys,subprocess  
  4.  
  5. cacti = ['cacti-0.8.7g.tar.gz','cacti-plugin-0.8.7g-PA-v2.8.tar.gz','rrdtool-1.4.4.tar.gz']  
  6. change = ''.join(cacti[:1])  
  7. rrd = ''.join(cacti[2])  
  8. pl = ''.join(cacti[1])  
  9. #If install files not exists,downloading now.  
  10. for path in cacti:  
  11.     if not os.path.exists(path):  
  12.         web = 'http://xxx.xxx.com/shell/'+path   
  13.     print '"%s" Downloading ......'%(path)  
  14.         web_file = urllib.urlopen(web)  
  15.         local = open(path,'wb').write(web_file.read())  
  16.         web_file.close()  
  17.  
  18. www = '/var/www/cacti'#Cacti directory  
  19. command = 'tar -zxf %s' 
  20.  
  21. #Decompress files  
  22. for path in cacti:  
  23.     os.system(command % path)  
  24.  
  25. #Configure "Catci"  
  26. if  os.path.exists(www):  
  27.     shutil.rmtree(www)  
  28.     print 'Delete %s directiory'%(www)  
  29. if not os.path.exists(www):  
  30.     shutil.move(change[0:12],www)  
  31.     os.system('chmod -R 775 %s'%www)  
  32.     print 'Create %s directiory'%(www)  
  33.  
  34. #Mysql datebase  
  35. try:  
  36.     conn = MySQLdb.connect(host='localhost',user='root',passwd='')  
  37. except Exception,e:  
  38.     print e  
  39.     sys.exit()  
  40.  
  41. cursor = conn.cursor()   
  42. if os.path.isdir('/var/lib/mysql/cacti'):  
  43.     sql = "drop database cacti;create database cacti;grant all on cacti.* to cacti@localhost identified by '123456';flush privileges;" 
  44.     cursor.execute(sql)  
  45. else:  
  46.     sql = "create database cacti;grant all on cacti.* to cacti@localhost identified by '123456';flush privileges;" 
  47.     cursor.execute(sql)  
  48. cursor.close()  
  49. conn.close()  
  50.  
  51. #Command  
  52. com = "./configure --prefix='/usr/local/rrdtool' 1>/dev/null;make -j10 1>/dev/null;make install 1>/dev/null" 
  53. #RRDTOOL  
  54. if not os.path.isdir('/usr/local/rrdtool'):  
  55.     os.chdir(rrd[:13])  
  56.     os.system(com)  
  57. #cacti-plugin  
  58. #if not os.path.isfile(www + os.sep + 'pa.sql'):  
  59. if not os.path.isdir(pl[:13]+'arch'):  
  60.     os.chdir('../' + pl[:13] + 'arch')   
  61.     shutil.copy('pa.sql',www)  
  62.     shutil.copy('cacti-plugin-0.8.7g-PA-v2.8.diff',www)  
  63.     os.chdir(www)  
  64.     os.system("patch -p1 -N <cacti-plugin-0.8.7g-PA-v2.8.diff;mysql -uroot -p cacti<pa.sql")   
  65.     os.system("mysql -uroot -p cacti<cacti.sql")   
  66. else:  
  67.     os.chdir(pl[:13] + 'arch')  
  68.     shutil.copy('pa.sql',www)  
  69.     shutil.copy('cacti-plugin-0.8.7g-PA-v2.8.diff',www)  
  70.     os.chdir(www)  
  71.     os.system("patch -p1 -N <cacti-plugin-0.8.7g-PA-v2.8.diff;mysql -uroot -p cacti<pa.sql")   
  72.     os.system("mysql -uroot -p cacti<cacti.sql")   
  73. #net-snmp  
  74. if not os.path.isfile('/usr/sbin/snmpd'):  
  75.     os.system('yum install -y install net-snmp*')  
  76.     os.system('chkconfig --level 35 snmpd on')  
  77.     os.system('service snmpd start')  
  78. if not os.path.isfile('/usr/local/bin/rrdtool'):  
  79.     os.system('ln -sf /usr/local/rrdtool/bin/rrdtool /usr/local/bin/rrdtool')  
  80. if not os.path.isfile('/usr/bin/php'):  
  81.     os.system('ln -sf /usr/local/php/bin/php /usr/bin/php')  
  82. #Crontab   
  83. cron = '/etc/crontab' 
  84. file = open(cron,'rw+')  
  85. phpcron = '*/5 * * * * root php /var/www/cacti/poller.php > /dev/null 2>&1\n' 
  86. for list in file:  
  87.     if list == phpcron:  
  88.         sys.exit()  
  89. file.write(phpcron)  
  90. file.close  
  91.  









本文转自 ibelieveme 51CTO博客,原文链接:http://blog.51cto.com/skyson/438595,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
JavaScript 关系型数据库 MySQL
|
关系型数据库 PHP Ubuntu
|
关系型数据库 PHP Ubuntu
|
Web App开发 监控 关系型数据库
|
Ubuntu 关系型数据库 PHP