部署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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章