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

 找回密码
 立即注册

一键登录:

搜索
热搜: 活动 交友 discuz
查看: 1289|回复: 2

Zabbix Server shell auto_ins

[复制链接]

49

主题

96

帖子

919

积分

超级版主

Rank: 8Rank: 8

积分
919
发表于 2015-3-20 16:23:25 | 显示全部楼层 |阅读模式
本帖最后由 oceanszf 于 2015-3-22 20:52 编辑

welcome to my blog

原创作品谢绝转载  ©Copyright to Jeffery Su


  1. #!/bin/bash
  2. # This is a script of auto install zabbix
  3. # Copyright to jeffery Su
  4. # Written on June 11,2014


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

  8. MYSQL_PWD="jefferySu"

  9. # Check environment
  10. function check_env {
  11.   echo "hello world !"
  12.   sleep 9
  13. }

  14. function lamp_ins {
  15.    
  16.      echo "Install lamp gcc ..."
  17.      sleep  1     

  18.     yum install -y httpd php mysql mysql-server php-mysql httpd-manual
  19. mod_ssl mod_perl mod_auth_mysqlphp-gd php-xml php-mbstring php-ldap
  20. php-pear php-xmlrpc php-bcmath  mysql-connector-odbc mysql-devel
  21. libdbi-dbd-mysql php-gd* libpng freetype libxml2 zlib wget gcc make
  22.      
  23.     if [[ $? != 0 ]]; then
  24.           echo "error in the yum,stop..."
  25.           exit 0
  26.     fi

  27.     echo "configuration after the installation...."
  28.     sleep 1

  29.     /bin/cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak
  30.     sed -i '/DirectoryIndex/s/$/ index.php /' /etc/httpd/conf/httpd.conf
  31.     echo "ServerName localhost:80" >> /etc/httpd/conf/httpd.conf
  32.     /etc/init.d/httpd restart
  33.     /etc/init.d/mysqld restart
  34.     chkconfig httpd on
  35.     chkconfig mysqld on
  36.    
  37.     # Configure mysql password
  38.     mysqladmin -uroot password $MYSQL_PWD

  39. }

  40. function fping_ins {
  41.    FPING_VER="fping-3.10"
  42.    # Detecting the setup packages exits
  43.    if [ -s ${FPING_VER}.tar.gz ];
  44.    then
  45.        echo "${FPING_VER}.tar.gz [found]"
  46.    else
  47.        echo "Error: ${FPING_VER} not found!!!download now......"
  48.        wget  <a target="_blank" href="http://fping.org/dist/">http://fping.org/dist/</a>${FPING_VER}.tar.gz
  49.    fi

  50.    # Compile the major programmer   
  51.    tar zxf ${FPING_VER}.tar.gz -C /usr/local/src
  52.    cd /usr/local/src/$FPING_VER

  53.    ./configure
  54.    
  55.    if [[ $? != 0 ]]; then
  56.          echo "error in the compilation,stop.."
  57.          exit 0
  58.    fi
  59.    make &&  make install
  60.    
  61.    # Add user
  62.    groupadd zabbix
  63.    useradd zabbix -g zabbix
  64.   
  65.    # Grant privileges
  66.    chown root:zabbix /usr/local/sbin/fping
  67.    chmod 4710 /usr/local/sbin/fping
  68.    
  69. }

  70. function zabbix_ins {
  71.    
  72.    ZABBIX_VER="zabbix-2.2.3"
  73.    ZABBIX_PATH=/var/www/html/zabbix
  74.    # Detecting the setup packages exits
  75.    if [ -s ${ZABBIX_VER}.tar.gz ];
  76.    then
  77.        echo "${ZABBIX_VER}.tar.gz [found]"
  78.    else
  79.        echo "Error: ${ZABBIX_VER} not found!!!download now......"

  80.       wget <a target="_blank"
  81. href="http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.3/zabbix-2.2.3.tar.gz">http://jaist.dl.sourceforge.net/
  82. ... zabbix-2.2.3.tar.gz</a>
  83.    fi

  84.    # Prepare work
  85.    yum -y install net-snmp-devel libcurl-devel OpenIPMI-devel openssl-devel
  86.    groupadd zabbix >/dev/null
  87.    useradd zabbix -g zabbix >/dev/null
  88.    #yum install lr* -y

  89.    # Compile the major programmer   
  90.    tar zxf ${ZABBIX_VER}.tar.gz -C /usr/local/src
  91.    cd /usr/local/src/$ZABBIX_VER
  92.    

  93.   ./configure --prefix=/usr/local/zabbix --enable-server  --enable-agent
  94. --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl
  95. --with-libxml2
  96.    if [[ $? != 0 ]]; then
  97.          echo "error in the compilation,stop.."
  98.          exit 0
  99.    fi
  100.     make install
  101.    
  102.    if [[ $? != 0 ]]; then
  103.          echo "error in the compilation,stop.."
  104.          exit 0
  105.    else
  106.         echo "compilation finish..."
  107.    fi

  108.    # Add zabbix services port
  109.    /bin/cp /etc/services /etc/services.bak
  110.    cat >> /etc/services <<END
  111. zabbix-agent    10050/tcp   #Zabbix Agent
  112. zabbix-agent    10050/udp   #Zabbix Agent
  113. zabbix-trapper  10051/tcp   #Zabbix Trapper
  114. zabbix-trapper  10051/udp   #Zabbix Trapper
  115. END
  116.    
  117.    # Repair the zabbix configure file
  118.    ln -s /usr/local/zabbix/etc/ /etc/zabbix
  119.    /bin/cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.bak
  120.    sed -i  's/DBUser=root/DBUser=zabbix/;/DBUser=zabbix/a\DBPassword=jefferySu' /etc/zabbix/zabbix_server.conf
  121.    echo "FpingLocation=/usr/sbin/fping" >> /etc/zabbix/zabbix_server.conf
  122.    /bin/cp /etc/zabbix/zabbix_agent.conf /etc/zabbix/zabbix_agent.conf.bak

  123.    mkdir -p $ZABBIX_PATH
  124.    /bin/cp -r /usr/local/src/$ZABBIX_VER/frontends/php/*  $ZABBIX_PATH
  125.    chown -R zabbix:zabbix $ZABBIX_PATH

  126.    # Create start file
  127.    /bin/cp /usr/local/src/$ZABBIX_VER/misc/init.d/fedora/core5/zabbix_server /etc/init.d/
  128.    /bin/cp /usr/local/src/$ZABBIX_VER/misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/

  129.    sed -i 's#/usr/local#/usr/local/zabbix#' /etc/init.d/zabbix_server
  130.    sed -i 's#/usr/local#/usr/local/zabbix#' /etc/init.d/zabbix_agentd
  131.   

  132.    /etc/init.d/zabbix_server start
  133.    /etc/init.d/zabbix_agentd start
  134.   
  135.    # Start the zabbix service on boot
  136.    chkconfig --add   zabbix_agentd
  137.    chkconfig --add   zabbix_server
  138.    chkconfig zabbix_server on
  139.    chkconfig zabbix_agentd on

  140.    # configure the php
  141.    /bin/cp /etc/php.ini /etc/php.ini.bak

  142.   sed -i 's/;date.timezone =/date.timezone =
  143. Asia\/Shanghai/;s/post_max_size = 8M/post_max_size =
  144. 32M/;s/max_execution_time = 30/max_execution_time =
  145. 300/;s/;mbstring.func_overload = 0/mbstring.func_overload =
  146. 2/;s/max_input_time = 60/max_input_time = 300/' /etc/php.ini
  147.   /etc/init.d/httpd  restart


  148. # Create database import data and grant privileges   
  149.    mysql -uroot -p$MYSQL_PWD -e "create database zabbix character set utf8"
  150.    mysql -uroot -p$MYSQL_PWD -e "grant all privileges on zabbix.* to zabbix@localhost identified by '$MYSQL_PWD'"
  151.    mysql -uroot -p$MYSQL_PWD -e "flush privileges"
  152.    mysql -uroot -p$MYSQL_PWD zabbix < /usr/local/src/$ZABBIX_VER/database/mysql/schema.sql
  153.    mysql -uroot -p$MYSQL_PWD zabbix < /usr/local/src/$ZABBIX_VER/database/mysql/images.sql
  154.    mysql -uroot -p$MYSQL_PWD zabbix < /usr/local/src/$ZABBIX_VER/database/mysql/data.sql
  155.   
  156.   echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  157.         + all thing prepare ok! please do the last step:                      +
  158.         + type $IP/`basename $ZABBIX_PATH` to configure...                    +
  159.         + for example : http://host_IP or domain name/`basename $ZABBIX_PATH` +
  160.         + dbname:zabbix  dbuser=zabbix   dbpwd=jefferySu                       +              
  161.         +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"

  162. }

  163. # Method Call
  164. #check_env
  165. #lamp_ins
  166. fping_ins
  167. zabbix_ins
复制代码


回复

使用道具 举报

0

主题

27

帖子

485

积分

中级会员

Rank: 3Rank: 3

积分
485
发表于 2015-3-20 16:40:24 | 显示全部楼层
好牛B,真牛B
回复 支持 反对

使用道具 举报

49

主题

96

帖子

919

积分

超级版主

Rank: 8Rank: 8

积分
919
 楼主| 发表于 2015-3-24 19:51:18 | 显示全部楼层

  相互学习吧
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2019-1-20 17:26 , Processed in 0.031022 second(s), 18 queries , Apc On.

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