Chinaunix首页 | 论坛 | 博客
  • 博客访问: 244431
  • 博文数量: 32
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 414
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-22 11:22
个人简介

.....

文章分类

全部博文(32)

文章存档

2016年(1)

2015年(12)

2014年(19)

我的朋友

分类: 系统运维

2014-09-01 10:53:39


点击(此处)折叠或打开

  1. #!/bin/bash
  2. #Name Zabbix_agentd_autoInstall_for_Linux.sh
  3. #DATA 2014-9-13
  4. #Author Kingsh2012
  5. ##########################################################################
  6. # Var
  7. conf="/usr/local/zabbix_agentd/conf/zabbix_agentd.conf"
  8. localip=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
  9. group=`cat /etc/group |grep zabbix |awk -F':' '{print $1}'`
  10. user=`cat /etc/passwd |grep zabbix |awk -F':' '{print $1}'`
  11. log="/tmp/zabbix_agentd.log"
  12. uname=`uname -i`
  13. cut="-----------------------------------------------------------------------------"
  14. ##########################################################################
  15. # Zabbix Client
  16. x64=''
  17. x64_agentd='zabbix_agents_2.2.5.linux2_6.amd64.tar.gz'
  18. x86=''
  19. x86_agentd='zabbix_agents_2.2.5.linux2_6.i386.tar.gz'
  20. ##########################################################################

  21. # Work Catalog
  22. cd /opt/

  23. read -p "Enter You Zabbix Server IP:" Server
  24. read -p "Enter You Zabbix Hostname :" host
  25. echo $cut
  26. echo "This is you Input Zabbix Server IP: " $Server
  27. echo "This is You Input Zabbix Hostname : " $host
  28. echo "This is You Local Host IP : " $localip
  29. echo "This is You Log File Default Site : " $log
  30. echo "This is You Systam Version : " $uname
  31. echo $cut
  32. echo "input Y confirm this IP or input N afresh enter IP."
  33. read -p "Y or N:" YorN

  34. if [ $YorN = "Y" -o $YorN = "y" ];then
  35.    echo $cut
  36. elif [ $YorN = "N" -o $YorN = "n" ];then
  37.     read -p "Input You Local Host IP:" localip
  38. else
  39.     echo "Input ERROR!"
  40.     exit 0
  41. fi

  42. # Group Add Check
  43. if [ "$group" = "zabbix" ];then
  44.     echo "zabbix Group YES"
  45. else
  46.     groupadd zabbix
  47.     echo "zabbix Group Creat Success"
  48. fi


  49. # User Add Check
  50. if [ "$user" = "zabbix" ];then
  51.     echo "zabbix User YES"
  52. else
  53.     useradd -g zabbix -s /sbin/nologin zabbix
  54.     echo "zabbix User Create Success"
  55. fi

  56. echo $cut

  57. # Create Zabbix_agentd folder
  58. mkdir zabbix_agentd

  59. # Download zabbix agentd
  60. if [ $uname = "x86_64" ];then
  61.     wget $x64
  62.     tar -zxvf $x64_agentd -C ./zabbix_agentd
  63. else
  64.     wget $x86
  65.     tar -zxvf $x86_agentd -C ./zabbix_agentd
  66. fi

  67. # move zabbix agentd folder
  68. if [ -d "/opt/zabbix_agentd/" ];then
  69.     if [ -d "/usr/local/zabbix_agentd/" ];then
  70.         rm -rf /usr/local/zabbix_agentd/
  71.     fi
  72.     mv /opt/zabbix_agentd/ /usr/local/
  73. fi

  74. # Edit Server Hostname HostIP Log
  75. sed -i "s/Server=127.0.0.1/Server=$Server/g" `grep Server= -rl $conf`
  76. sed -i "s/Hostname=Zabbix server/Hostname=$host/g" `grep Hostname=Zabbix -rl $conf`
  77. sed -i "s/# SourceIP=/SourceIP=$localip/g" `grep SourceIP= -rl $conf`
  78. #sed -i "s/LogFile=\/tmp\/zabbix_agentd.log/LogFile=$log/g" `grep LogFile= -rl $conf`

  79. # Add Services
  80. echo "zabbix-agent 10050/tcp #Zabbix Agent" >> /etc/services
  81. echo "zabbix-agent 10050/udp #Zabbix Agent" >> /etc/services
  82. echo "zabbix-trapper 10051/tcp #Zabbix Trapper" >> /etc/services
  83. echo "zabbix-trapper 10051/udp #Zabbix Trapper" >> /etc/services

  84. echo $cut

  85. # Runing Zabbix agentd
  86. /usr/local/zabbix_agentd/sbin/zabbix_agentd -c /usr/local/zabbix_agentd/conf/zabbix_agentd.conf
  87. ps -ef | grep zabbix | grep -v grep | awk '{print $2}' | xargs kill -s 9
  88. /usr/local/zabbix_agentd/sbin/zabbix_agentd -c /usr/local/zabbix_agentd/conf/zabbix_agentd.conf

  89. # Check Zabbix agentd Starting Status
  90. c=`/bin/netstat -apn |grep zabbix |grep -v grep |wc -l`
  91. if [ $c = "1" ];then
  92.     echo "Zabbix agentd Starting Success!"
  93. else
  94.     echo $cut
  95.     echo "Zabbix agentd Starting ERROR!"
  96.     echo "Zabbix agentd Starting ERROR!"
  97.     echo "Zabbix agentd Starting ERROR!"
  98.     echo "Zabbix agentd Starting ERROR!"
  99. fi
  100. echo $cut

  101. # Check Iptables Status
  102. iptables=`/etc/init.d/iptables status`
  103. if [ $? = 0 ];then
  104.     echo "iptables Runing!"
  105.     echo "Close iptables or To open up 10051 TCP port!"
  106. else
  107.     echo "iptables NOT Runing!"
  108. fi
  109. echo $cut
  110. echo "Zabbix $uname agentd Install Success!"
  111. echo "Zabbix $uname agentd Install Success!"
  112. echo "Install Site /usr/local/zabbix_agentd/"
  113. exit 0


阅读(2457) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~