zabbix_agentd安装脚本共享

时间:2024-01-06 21:28:38
#!/bin/bash
wget -P /expect_zabbix/ http://10.107.2.44/zabbix_agent/check.sh
. /expect_zabbix/check.sh
groupadd zabbix
/usr/sbin/useradd -g zabbix -s /sbin/nologin zabbix
pkill ntp && ntpdate 10.107.2.44
wget -P /expect_zabbix http://10.107.2.44/zabbix_agent/zabbix-2.2.2.tar.gz
tar xf /expect_zabbix/zabbix-2.2.2.tar.gz -C / && cd /zabbix-2.2.2
./configure --prefix=/usr/local/zabbix --sysconfdir=/etc/zabbix --enable-agent
make && make install
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
[ ! -d /etc/zabbix ] && mkdir /etc/zabbix && echo "create zabbix folder OK"
[ ! -f /etc/zabbix/zabbix_agentd.conf ] && cp /zabbix-2.2.2/conf/zabbix_agentd.conf /etc/zabbix/
/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:" | grep "10." >/ip.txt && echo "create ip.txt OK..."
sed -i 's/^Server=127.0.0.1/Server=10.140.86.236/g' /etc/zabbix/zabbix_agentd.conf && echo "Server OK.."
sed -in "s#^Hostname=Zabbix server#Hostname=$(cat /ip.txt)#g" /etc/zabbix/zabbix_agentd.conf && echo "Hostname OK..."
sed -i 's/^ServerActive=127.0.0.1/ServerActive=10.140.86.236:10051/g' /etc/zabbix/zabbix_agentd.conf && echo "ServerActive OK..."
##start option
[ ! -f /etc/init.d/zabbix_agentd ] && cp /zabbix-2.2.2/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd && echo "cp zabbix_agentd OK..."
sed -i "s:BASEDIR=/usr/local:BASEDIR=/usr/local/zabbix:g" /etc/rc.d/init.d/zabbix_agentd
chmod +x /etc/rc.d/init.d/zabbix_agentd
chkconfig --add zabbix_agentd
chkconfig zabbix_agentd on
pkill zabbix_agentd
/usr/local/zabbix/sbin/zabbix_agentd start || /usr/local/zabbix/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agent.conf
ps -aux | grep zabbix_agentd >> /$(cat /ip.txt).log
netstat -an | grep 10050 >> /$(cat /ip.txt).log
cat /etc/services | grep "zabbix*" &>/dev/null || echo "zabbix_agent 10050/tcp" >> /etc/services
cat /etc/services | grep "zabbix*" &>/dev/null || echo "zabbix_agent 10050/udp" >> /etc/services
service iptables stop || systemctl stop iptables.service
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT
service zabbix_agentd restart || /usr/local/zabbix/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agent.conf
cat /$(cat /ip.txt).log
rm -rf /root/zabbix_install.sh
rm -rf /expect_zabbix
rm -rf /ip.txt
rm -rf /yumupdate.sh