#/bin/bash
name=`hostname`
#判断是否安装sudo命令,没有则安装
sudo ls &> /dev/null
if [ $? -eq 127 ]
then
while [[ 1 ]]
do
if read -n1 -p "sudo command not exists,choose [Y/N] to install:"
then
case $REPLY in
Y|y)
apt-get install sudo
#echo "\n you choosed Y,install right now"
if [ $? !=0 ]
then
echo "sudo command can't install correctly,please install it manually!"
exit 1
fi
break
;;
N|n)
echo "\n you choosed N,will quit!"
exit 1
;;
*)
echo "\n only Y/N permitted"
continue
esac
fi
done
fi
#sudo命令安装不成功,退出
sudo ls &> /dev/null
if [ $?!=0 ]
then
echo "sudo command didn't install correctly,please install it manually!"
exit 1
fi
#add zabbix statement
#是否存在zabbix,不存在则安装
grep zabbix /etc/passwd &>/dev/null
if [ $? -eq 1 ]
then
#adduser zabbix
#echo "add user zabbix"
while [[ 1 ]]
do
if read -n1 -p "user zabbix is not exits,add the user?[Y/N]"
then
case $REPLY in
Y|y)
adduser zabbix
if [ $? !=0 ]
then
echo "user zabbix can't add correctly,please add it manually "
exit 1
fi
#echo "\n you choosed y,add user zabbix"
break
;;
N|n)
echo "\n you choosed n,will quit"
exit 1
;;
*)
echo "\n only Y/N is permitted"
continue
esac
fi
done
fi
#创建zabbix用户不成功,退出
grep zabbix /etc/passwd &>/dev/null
if [ $?!=0 ]
then
echo "user zabbix didn't add correctly,please add it manually "
exit 1
fi
#sudo permit给zabbix用户sudo权限
grep zabbix /etc/sudoers &>/dev/null
if [ $? !=0 ]
then
chmod u+w /etc/sudoers
sed -i '/root\tALL/azabbix\tALL=(ALL:ALL) NOPASSWD:ALL' /etc/sudoers
chmod u-w /etc/sudoers
fi
cd /home/zabbix
if [ -f zabbix_agents_2.4.4.linux2_6.amd64.tar.gz ]
then
rm -rf zabbix_agents_2.4.4.linux2_6.amd64.tar.gz
fi
#下载安装客户端,并修改配置文件
wget http://www.zabbix.com/downloads/2.4.4/zabbix_agents_2.4.4.linux2_6.amd64.tar.gz
tar -xvf zabbix_agents_2.4.4.linux2_6.amd64.tar.gz
cp "/home/zabbix/conf/zabbix_agentd.conf" /usr/local/etc/
cp "/home/zabbix/conf/zabbix_agent.conf" /usr/local/etc/
sed -i "s/Server=127.0.0.1/Server=10.0.0.4/g" /usr/local/etc/zabbix_agentd.conf
sed -i "s/Hostname=Zabbix server/Hostname=$name/g" /usr/local/etc/zabbix_agentd.conf
su zabbix -c /home/zabbix/sbin/zabbix_agentd
部署zabbix_agent脚本
最新推荐文章于 2023-02-11 15:40:28 发布