zabbix客户端一键安装脚本

#!/bin/bash

#通过命令行参数指定
if [ ! -z "$1" ];then
ip=$1
echo "手动指定IP:$ip"
else
#根据默认路由获取ip地址
iface=`route 2>/dev/null |grep default |awk '{print $8}'`
iface=${iface:-'bond0'}
ip=`ifconfig $iface 2>/dev/null |grep -oP '(?<=inet addr:)\d*\.\d*\.\d*\.\d*'`
echo "自动获取网卡${iface}的IP为:$ip"
fi

#如果两种方式都没获取到IP,则退出
if [ -z "$ip" ];then
echo 'IP地址为空,程序退出'
exit
fi

yum install -y zabbix-agent-3.0.1-1.el7.x86_64.rpm

if [ -e /etc/zabbix/zabbix_agentd.conf ];then
echo
echo "##########begin modify zabbix_agentd.conf##########"
sed -i 's/^Server=127.0.0.1/Server=10*.4*.12*.34*/g' /etc/zabbix/zabbix_agentd.conf
sed -i 's/^ServerActive=127.0.0.1/ServerActive=10*.4*.12*.34*:21222/g' /etc/zabbix/zabbix_agentd.conf
sed -i "s/Hostname=Zabbix server/Hostname=${ip}/g" /etc/zabbix/zabbix_agentd.conf
sed -i '/ListenPort=10050$/a\ListenPort=21224' /etc/zabbix/zabbix_agentd.conf
sed -i "/ListenIP=0.0.0.0$/a\ListenIP=${ip}" /etc/zabbix/zabbix_agentd.conf
sed -i '/Timeout=3$/a\Timeout=30' /etc/zabbix/zabbix_agentd.conf
grep -v '^#' /etc/zabbix/zabbix_agentd.conf |grep -v '^$'
echo "##########end modify zabbix_agentd.conf##########"
echo
else
echo
echo "##########zabbix_agentd.conf is not exit##########"
echo
exit 2
fi

if [ -d /etc/zabbix/zabbix_agentd.d ];then
cp -r weifeng.conf /etc/zabbix/zabbix_agentd.d
else
echo "##########/etc/zabbix/zabbix_agentd.d is not exist##########"
echo
exit 3
fi

echo "##########begin move scripts to /etc/zabbix/scripts##########"
if [ -d /etc/zabbix/scripts ];then
cp -r scripts/* /etc/zabbix/scripts
chmod +x /etc/zabbix/scripts/*
else
mkdir /etc/zabbix/scripts
cp -r scripts/* /etc/zabbix/scripts
chmod +x /etc/zabbix/scripts/*
fi
echo "##########end move scripts to /etc/zabbix/scripts##########"
echo

echo "##########begin modify /etc/sudoers##########"
sed -i 's/\(Defaults.*requiretty\)/#\1/g' /etc/sudoers
echo '...'
sed -i 's/!visiblepw/visiblepw/g' /etc/sudoers
echo '...'
echo 'zabbix ALL=(ALL) NOPASSWD:/etc/zabbix/scripts/*' >> /etc/sudoers
echo '...'
echo "##########end modify /etc/sudoers##########"
echo
systemctl enable zabbix-agent.service
systemctl restart zabbix-agent.service

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值