标签:python return import status
#!/usr/bin/env python #coding=utf-8 #2015-5-13 #安装zabbix Server import sys import commands import MySQLdb as mdb zabbix_config="/etc/zabbix/zabbix_server.conf" zabbix_php = "/etc/httpd/conf.d/zabbix.conf" def get_local_ip(ifname): import socket, fcntl, struct s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) inet = fcntl.ioctl(s.fileno(), 0x8915, struct.pack(‘256s‘, ifname[:15])) ret = socket.inet_ntoa(inet[20:24]) return ret ip=get_local_ip("eth0") def Judge(status,info,arg): if status == 0: print "%s %s is ok" %(info,arg) else: print "%s %s is fail" %(info,arg) sys.exit() def mysql_connect(): try: con=mdb.connect(‘localhost‘,‘root‘,‘123456‘,) cur=con.cursor() cur.execute(‘create database zabbix character set utf8‘) cur.execute("grant all privileges on zabbix.* to zabbix@localhost identified by ‘zabbix‘") cur.close() con.close() except mdb.Error,e: print "Mysql Error %d: %s" % (e.args[0], e.args[1]) print "Installation environment required depend on the package" cmd="yum -y install gcc-c++ autoconf httpd php mysql mysql-server php-mysql httpd-manual mod_ssl mod_perl mod_auth_mysql php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-bcmath mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp-devel curl-devel" status,result=commands.getstatusoutput("%s"%cmd) Judge(status,‘Install is‘,‘pacakge‘) status,result=commands.getstatusoutput("service httpd start && service mysqld start && chkconfig httpd on && chkconfig mysqld on") Judge(status,‘httpd,mysql‘,‘Install‘) print "Install zabbix yum" print cmd = "rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm" status,result = commands.getstatusoutput("%s"%cmd) print result Judge(status,‘Install‘,‘Zabbix Yum‘) print "Install Zabbix Server" status,result = commands.getstatusoutput("yum -y install zabbix-server-mysql zabbix-web-mysql") print result Judge(status,‘Install‘,‘Zbbix Server‘) status,result = commands.getstatusoutput("mysqladmin -u root password 123456") print print "Create zabbix database" mysql_connect() print "Import the zabbix database" status,result =commands.getstatusoutput("cd /usr/share/doc/zabbix-server-mysql-2.4.5/create && mysql -uzabbix -pzabbix zabbix < schema.sql && mysql -uzabbix -pzabbix zabbix <images.sql && mysql -uzabbix -pzabbix zabbix <data.sql") print result Judge(status,‘Import‘,‘zabbix databse‘) print "zabbix file config" sed="sed -i -e ‘s/DBUser\=root/DBUser\=zabbix/g‘ -i -e ‘/# DBPassword=/aDBPassword=zabbix\n‘ %s" %zabbix_config status,result = commands.getstatusoutput("%s" %sed) print "start Zabbix Server" status,result = commands.getstatusoutput("service zabbix-server start && chkconfig zabbix-server on") Judge(status,‘Start‘,‘Zabbix Server‘) status,result=commands.getstatusoutput("sed -i ‘17a php_value date.timezone Asia\/Shanghai‘ %s"%zabbix_php) print "restart httpd" status,result=commands.getstatusoutput(‘service httpd restart‘) Judge(status,‘Running‘,‘httpd‘ ) print "请使用http://%s/zabbix 进行安装" %ip
本文出自 “服务器” 博客,请务必保留此出处http://zhangfang2012.blog.51cto.com/6380212/1651017
标签:python return import status
原文地址:http://zhangfang2012.blog.51cto.com/6380212/1651017