部署zabbix_agent脚本

#/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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值