#!/usr/bin/env python # -*- coding: utf-8 -*- import os ZABBIX_SERVER_IP=‘10.171.100.28‘ is_running = os.popen("ps -ef | grep zabbix_agentd | grep -v grep | wc -l") is_installed = os.popen("find /usr/local -name ‘zabbix_*‘ | wc -l") if int(is_running.read().strip()) or int(is_installed.read().strip()): print """ **************************************************************** * zabbix_agentd已安装,若要重装,请删除/usr/local/zabbix-agent/ * ****************************************************************""" os._exit(0) print ‘选择被监控机的类型:1-WEB,2-ORACLE,3-MYSQL,4-REDIS,Q-QUIT‘ choice = raw_input() result = ‘‘ if choice == ‘1‘: result = ‘WEB_‘ elif choice == ‘2‘: result = ‘ORACLE_‘ elif choice == ‘3‘: result = ‘MYSQL_‘ elif choice == ‘4‘: result = ‘REDIS_‘ else: os._exit(0) print ‘...创建zabbix用户‘ g = os.system(‘cat /etc/group | grep zabbix‘) if g != 0 : os.system(‘groupadd zabbix‘) else: print ‘...zabbix组已存在‘ u = os.system(‘cat /etc/passwd | grep zabbix‘) if u != 0 : os.system(‘useradd -g zabbix zabbix -s /sbin/nologin‘) print ‘...zabbix用户创建成功‘ else: print ‘...zabbix用户已存在‘ print ‘...下载zabbix安装包‘ os.chdir(‘/tmp‘) os.system(‘wget http://10.171.100.28/download/zabbix-3.2.7.tar.gz‘) print ‘...下载完毕,开始解压‘ os.system(‘tar -zxvf zabbix-3.2.7.tar.gz‘) print ‘...解压完毕,开始安装‘ os.chdir(‘/tmp/zabbix-3.2.7‘) os.system(‘./configure --prefix=/usr/local/zabbix-agent --enable-agent‘) os.system(‘make install‘) print ‘...获取本机ip‘ myip = os.popen("ip add show | grep inet | grep eth0 | awk ‘{print $2}‘ | awk -F/ ‘{ print $1}‘ | head -n 1") myip = myip.read().strip() print(‘...配置zabbix_agentd.conf‘) hostname=result+myip f = open(‘/usr/local/zabbix-agent/etc/zabbix_agentd.conf‘, ‘w‘) f.write("""LogFile=/var/log/zabbix/zabbix_agentd.log Server=%s Hostname=%s """ % (ZABBIX_SERVER_IP,hostname)) f.close print(‘...配置zabbix_agentd.conf完毕‘) os.system(‘mkdir /var/log/zabbix‘) os.system(‘touch /var/log/zabbix/zabbix_agentd.log‘) os.system(‘chown zabbix:zabbix /var/log/zabbix/zabbix_agentd.log‘) os.system(‘rm -rf /tmp/zabbix*‘) print """ *********************************************************** * The zabbix_agentd is installed * * * * Now run * * /usr/local/zabbix-agent/sbin/zabbix_agentd * ***********************************************************"""
注:
使用
‘wget http://10.171.100.28/download/zabbix-3.2.7.tar.gz‘ 下载文件的话,需要在nginx中如下配置
并且 将 zabbix-3.2.7.tar.gz 安装包拷入相应目录。
时间: 2024-10-08 20:50:23