Zabbix一键升级Shell脚本

作者: 聂扬帆博客 | 来源:发表于2017-01-18 11:37 被阅读76次

    最近升级了下zabbix,发现每次升级都是重复几个步骤,如果写成脚本方式的不是方便很多。

    #!/bin/bash
    
    #################参数设置,根据自己环境修改########################
    DBName=zabbix
    DBUser=root
    DBPassword=123456
    DBDIR_BAK=/tmp
    TODAY=`date +%Y-%m-%d`
    
    MYSQLDUMP=$(which mysqldump)
    WGET=$(which wget)
    CHOWN=$(which chown)
    TAR=$(which tar)
    CP=$(which cp)
    MV=$(which mv)
     
    ZABBIX='zabbix-3.2.3'
    ZABBIX_URL='http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.2.3/zabbix-3.2.3.tar.gz/download'
    ZABBIX_DIR=/home/wwwroot/default
    ZABBIX_VERSION=/usr/local/zabbix/sbin/zabbix_server --version | grep zabbix_server
    #################################################################
    
    #停止服务
    /etc/init.d/zabbix_server stop
    /etc/init.d/zabbix_agentd stop
     
    #备份数据库
    $MYSQLDUMP -u $DBUser -p$DBPassword --opt --skip-lock-tables --flush-logs --database $DBName > $DBDIR_BAK/zabbix.$TODAY.sql
    if [ $? -eq 0 ]; then 
    echo
    "MysqlDump success!"
    else
    echo
    "MysqlDump failed!"
    exit 1
    fi
    
    #备份网站
    $MV $ZABBIX_DIR/zabbix $ZABBIX_DIR/zabbix_$TODAY
    if [ $? -eq 0 ]; then
    echo
    "Zabbix backup success!"
    else 
    echo
    "Zabbix backup failed!"
    exit 1
    fi
    
    #下载新版zabbix
    echo "Start download $ZABBIX ,Please wait..."
    $WGET -O $ZABBIX.tar.gz -c "$ZABBIX_URL" &>/dev/null
    test -f $ZABBIX.tar.gz || (echo "Zabbix download failed!" && exit 2)
     
    #解压zabbix
    $TAR zxvf $ZABBIX.tar.gz
     
    #编译zabbix
    cd $ZABBIX
    ./configure --prefix=/usr/local/zabbix --enable-server --with-mysql --with-net-snmp --with-libxml2 --with-libcurl --with-openipmi --enable-proxy --enable-agent && make install
    
    #拷贝新版文件到网站目录
    $CP -r frontends/php $ZABBIX_DIR/zabbix
    
    #拷贝配置文件
    $CP $ZABBIX_DIR/zabbix_$TODAY/conf/zabbix.conf.php $ZABBIX_DIR/zabbix/conf/zabbix.conf.php
    
    #修改权限
    $CHOWN -R www:www $ZABBIX_DIR/zabbix
    
    #删除zabbix安装包
    cd ..
    rm $ZABBIX.tar.gz -rf
    rm $ZABBIX -rf
     
    #启动服务
    /etc/init.d/zabbix_server start
    /etc/init.d/zabbix_agentd start
    
    echo "Zabbix update success! The zabbix version is $ZABBIX_VERSION"
    

    博客地址:http://yangfannie.com

    相关文章

      网友评论

        本文标题:Zabbix一键升级Shell脚本

        本文链接:https://www.haomeiwen.com/subject/kfnvbttx.html