#! /bin/sh
Groupadd-r Zabbix
Useradd-r zabbix-s/sbin/nologin-g Zabbix
CD ~/temp
wget http://abc.com/zabbix-2.4.7.tar.gz
Tar XF zabbix-2.4.7.tar.gz
MV zabbix-2.4.7 Zabbix
CD Zabbix
./configure--prefix=/usr/local/zabbix--enable-agent
Make
Make install
#edit Configure
Sed-i ' s/^server=.*$/server=127.0.0.1/g '/usr/local/zabbix/etc/zabbix_agentd.conf
Sed-i ' s/^serveractive=.*$/serveractive=61.164.58.234:10051/g '/usr/local/zabbix/etc/zabbix_agentd.conf
ip= ' Ifconfig | grep ' inet ' | Sed-n ' 1p ' |awk-f: ' {print $ {} ' |awk ' {print '} '
Sed-i "s/^hostname=.*$/hostname= $ip/g"/usr/local/zabbix/etc/zabbix_agentd.conf
Mkdir-p/usr/local/zabbix/share/zabbix/externalscripts
Cat >/usr/local/zabbix/share/zabbix/externalscripts/disk.sh $1<< "EOF"
#!/bin/bash
Diskarray= (' Cat/proc/diskstats |grep-e ' \bsd[a-d][0-9]\b|\bsd[a-z]\b|\bxvd[a-d][0-9]\b|\bxvd[a-d]\b|\bvd[a-d][ 0-9]\b|\bvd[a-b]\b "|awk ' {print $} ' |sort|uniq 2>/dev/null ')
length=${#diskarray [@]}
printf "{\ n"
printf ' \ t ' "\" data\ ": ["
For ((i=0;i< $length; i++))
Do
printf ' \n\t\t{'
printf "\" {#DISK_NAME}\ ": \" ${diskarray[$i]}\ "}"
If [$i-lt $[$length-1]];then
printf ', '
Fi
Done
printf "\n\t]\n"
printf "}\n"
Eof
Cat >/usr/local/zabbix/share/zabbix/externalscripts/cpunum.sh << "EOF"
#!/bin/bash
diskarray= (' cat/proc/cpuinfo | grep ' process ' |awk-f: ' {print $} ')
length=${#diskarray [@]}
printf "{\ n"
printf ' \ t ' "\" data\ ": ["
For ((i=0;i< $length; i++))
Do
printf ' \n\t\t{'
printf "\" {#CPU_NUM}\ ": \" ${diskarray[$i]}\ "}"
If [$i-lt $[$length-1]];then
printf ', '
Fi
Done
printf "\n\t]\n"
printf "}\n"
Eof
Cat >>/usr/local/zabbix/etc/zabbix_agentd.conf<< "EOF"
Userparameter=io.scandisk[*],/usr/local/zabbix/share/zabbix/externalscripts/disk.sh $
Userparameter=io.rmbps[*],cat/proc/diskstats | grep $ | head-1 | awk ' {print $$4} '
Userparameter=io.wmbps[*],cat/proc/diskstats | grep $ | head-1 | awk ' {print $$11} '
Userparameter=io.active[*],cat/proc/diskstats | grep $ | head-1 | awk ' {print $$12} '
Userparameter=io.ms[*],cat/proc/diskstats | grep $ | head-1 | awk ' {print $$13} '
Userparameter=cpu.numors[*],/usr/local/zabbix/share/zabbix/externalscripts/cpunum.sh $
userparameter=memory.free,/usr/bin/free-m | grep ' ^mem ' |awk ' {print $4+$6+$7} '
Eof
chmod +x/usr/local/zabbix/share/zabbix/externalscripts/disk.sh
chmod +x/usr/local/zabbix/share/zabbix/externalscripts/cpunum.sh
Pkill Zabbix
/usr/local/zabbix/sbin/zabbix_agentd
echo "/usr/local/zabbix/sbin/zabbix_agentd" >>/etc/rc.d/rc.local
Zabbix-agent Script Installation 2