zabbix-agent脚本安装2
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix-agent脚本安装2相关的知识,希望对你有一定的参考价值。
#!/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 $2}‘|awk ‘{print $1}‘`
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 $3}‘|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 $2}‘`)
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 $1
UserParameter=io.rMBps[*],cat /proc/diskstats | grep $1 | head -1 | awk ‘{print $$4}‘
UserParameter=io.wMBps[*],cat /proc/diskstats | grep $1 | head -1 | awk ‘{print $$11}‘
UserParameter=io.active[*],cat /proc/diskstats | grep $1 | head -1 | awk ‘{print $$12}‘
UserParameter=io.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk ‘{print $$13}‘
UserParameter=cpu.numors[*],/usr/local/zabbix/share/zabbix/externalscripts/cpunum.sh $1
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脚本安装2的主要内容,如果未能解决你的问题,请参考以下文章