标签:
1 #!/bin/bash 2 3 # 4 # 1、配置yum源 5 # 6 7 cat /etc/redhat-release |grep -i centos |grep ‘6.[[:digit:]]‘ &>/dev/null 8 9 if [[ $? != 0 ]] 10 then 11 echo -e "不支持的操作系统,该脚本只适用于CentOS 6.x 操作系统" 12 exit 1 13 fi 14 15 os_m=$(uname -m) 16 za_rpm=$(curl -s http://mirrors.aliyun.com/zabbix/zabbix/2.4/rhel/6/$os_m/ |grep release |awk -F ‘>|<‘ ‘{print $3}‘) 17 rpm -i --force http://mirrors.aliyun.com/zabbix/zabbix/2.4/rhel/6/$os_m/$za_rpm 18 19 if [[ $? != 0 ]] 20 then 21 echo -e "yum源配置失败,请检查网络或者其他原因" 22 exit 1 23 fi 24 25 sed -i ‘s@repo.zabbix.com@mirrors.aliyun.com/zabbix@‘ /etc/yum.repos.d/zabbix.repo 26 27 # 28 # 2、使用yum安装Zabbix 29 # 30 31 yum install -y zabbix-agent zabbix-sender 32 chkconfig zabbix-agent on 33 iptables -I INPUT -m state --state NEW -p tcp --dport 10050 -j ACCEPT 34 /etc/init.d/iptables save 35 36 ping -c 1 $1 &>/dev/null 37 38 if [[ $? == 0 ]] 39 then 40 sed -i ‘s/^Server=127.0.0.1/Server=‘$1‘/‘ /etc/zabbix/zabbix_agentd.conf 41 sed -i ‘s/^ServerActive=127.0.0.1/ServerActive=‘$1‘/‘ /etc/zabbix/zabbix_agentd.conf 42 sed -i ‘s/^Hostname=Zabbix server/Hostname=‘$(ip addr show |grep inet |awk ‘{print $2}‘ |awk -F ‘/‘ ‘{print $1}‘ | grep ‘^‘$(echo 119.10.47.200|awk -F ‘.‘ ‘{print $1}‘)‘‘)‘/‘ /etc/zabbix/zabbix_agentd.conf 43 44 /etc/init.d/zabbix-agent start 45 else 46 echo -e "\n\t请手动修改 ‘/etc/zabbix/zabbix_agentd.conf‘ 文件\n\n\t\tServer=Zabbix-Server_IP\n\t\tServerActive=Zabbix-Server_IP\n\t\tHostname=Zabbix-agent_HOSTNAME\n\n\t然后执行 ‘/etc/init.d/zabbix-agent start‘ 启动Zabbix-agent\n" 47 fi
标签:
原文地址:http://www.cnblogs.com/www1707/p/5441160.html