Linux/Python学习论坛-京峰教育

 找回密码
 立即注册

一键登录:

搜索
热搜: 活动 交友 discuz
查看: 1303|回复: 1

Zabbix Agent Shell Auto_ins

[复制链接]

49

主题

96

帖子

919

积分

超级版主

Rank: 8Rank: 8

积分
919
发表于 2015-3-20 21:04:56 | 显示全部楼层 |阅读模式
本帖最后由 oceanszf 于 2015-3-20 22:49 编辑

Welcome to my blog

原创作品谢绝转载  ©Copyright to Jeffery Su
  1. #!/bin/bash
  2. # This is a script of auto install zabbix agent
  3. # Copyright to Jeffery Su
  4. # Written on June 13,2014

  5. # SET VARIABLES
  6. PATH=/bin:/usr/bin:/sbin:/usr/sbin::/usr/local/bin:/usr/local/sbin;
  7. export PATH

  8. IP=`ifconfig |grep 'inet addr:'|awk '{print $2}'|cut -d : -f 2|head -1`

  9. function fping_ins {
  10.    FPING_VER="fping-3.10"
  11.    # Detecting the setup packages exits
  12.    if [ -s ${FPING_VER}.tar.gz ];
  13.    then
  14.        echo "${FPING_VER}.tar.gz [found]"
  15.    else
  16.        echo "Error: ${FPING_VER} not found!!!download now......"
  17.        wget  http://fping.org/dist/${FPING_VER}.tar.gz
  18.    fi

  19.    # Compile the major programmer   
  20.    tar zxf ${FPING_VER}.tar.gz -C /usr/src
  21.    cd /usr/src/$FPING_VER

  22.    ./configure
  23.    
  24.    if [[ $? != 0 ]]; then
  25.          echo "error in the compilation,stop.."
  26.          exit 0
  27.    fi
  28.    make &&  make install
  29.      
  30.    # Add user
  31.    groupadd zabbix
  32.    useradd zabbix -g zabbix
  33.    
  34.    # Grant privileges
  35.    chown root:zabbix /usr/local/sbin/fping
  36.    chmod 4710 /usr/local/sbin/fping
  37.    
  38. }

  39. function agent_ins {
  40.    ZABBIX_VER="zabbix-2.2.3"
  41.    ZABBIX_SER_IP=172.16.xx.xx      #INTENTION: This is zabbix server ip address
  42.    ZABBIX_PRO_HOSTNAME=${IP}  #INTENTION: This is zabbix proxy hostname
  43.    # Prepare work
  44.    yum -y install net-snmp net-snmp-devel libcurl-devel gcc make wget  gcc-c++ autoconf ncurses-devel
  45.    
  46.    # Add user
  47.    groupadd zabbix
  48.    useradd zabbix -g zabbix

  49.    # Detecting the zabbix packages exits
  50.    if [ -s ${ZABBIX_VER}.tar.gz ];
  51.    then
  52.        echo "${ZABBIX_VER}.tar.gz [found]"
  53.    else
  54.        echo "Error: ${ZABBIX_VER} not found!!!download now......"
  55.        wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.3/zabbix-2.2.3.tar.gz
  56.    fi

  57.    # Prepare work
  58.    yum -y install net-snmp net-snmp-devel libcurl-devel gcc make wget  gcc-c++ autoconf ncurses-devel
  59.    #yum install lr* -y


  60.    # Compile the major programmer   
  61.    tar zxf ${ZABBIX_VER}.tar.gz -C /usr/src
  62.    cd /usr/src/$ZABBIX_VER

  63.    ./configure --prefix=/usr/local/zabbix  --enable-agent --with-net-snmp --with-libcurl
  64.    if [[ $? != 0 ]]; then
  65.          echo "error in the compilation,stop.."
  66.          exit 0
  67.    fi
  68.    make install

  69.    if [[ $? != 0 ]]; then
  70.          echo "error in the compilation,stop.."
  71.         exit 0
  72.    else
  73.         echo "compilation finish..."
  74.    fi

  75.     # Add zabbix services port
  76.    /bin/cp /etc/services /etc/services.bak
  77.    cat >> /etc/services <<END
  78. zabbix-agent    10050/tcp   #Zabbix Agent
  79. zabbix-agent    10050/udp   #Zabbix Agent
  80. zabbix-trapper  10051/tcp   #Zabbix Trapper
  81. zabbix-trapper  10051/udp   #Zabbix Trapper
  82. END

  83.     # Create start file
  84.    /bin/cp /usr/src/$ZABBIX_VER/misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/
  85.    sed -i 's#/usr/local#/usr/local/zabbix#' /etc/init.d/zabbix_agentd

  86.    chmod 750 /etc/init.d/zabbix_agentd
  87.    chown zabbix:zabbix /etc/init.d/zabbix_agentd
  88.    sed -i '/^ZABBIX_BIN/aCONF_FILE="/usr/local/zabbix/etc/zabbix_agentd.conf"' /etc/init.d/zabbix_agentd
  89.    sed -i 's/daemon $ZABBIX_BIN/daemon $ZABBIX_BIN -c  $CONF_FILE/' /etc/init.d/zabbix_agentd

  90.    # Configure the zabbix_agent.conf
  91.    sed -i "s#Server=127.0.0.1#Server=$ZABBIX_SER_IP#" /usr/local/zabbix/etc/zabbix_agentd.conf
  92.    sed -i "s#ServerActive=127.0.0.1#ServerActive=$ZABBIX_SER_IP:10051#" /usr/local/zabbix/etc/zabbix_agentd.conf      
  93.    
  94.    sed -i "/Hostname=/s#=.*#"=$ZABBIX_PRO_HOSTNAME#""     /usr/local/zabbix/etc/zabbix_agentd.conf
  95.    sed -i "s#\#Timeout=3#Timeout=30#"          /usr/local/zabbix/etc/zabbix_agentd.conf

  96.    #logfile pidfile

  97.    # Start the zabbix service on boot
  98.    chkconfig --add           zabbix_agentd
  99.    chkconfig zabbix_agentd   on
  100.    /etc/init.d/zabbix_agentd start
  101.    
  102.    # Test agent
  103.    echo "check local zabbix  agent"
  104.    /usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf -t system.uptime      
  105. }

  106.    fping_ins
  107.    agent_ins
复制代码



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|京峰教育,只为有梦想的人 ( 京ICP备15013173号 )

GMT+8, 2019-6-24 17:32 , Processed in 0.043501 second(s), 12 queries , Apc On.

快速回复 返回顶部 返回列表