zoukankan      html  css  js  c++  java
  • zabbix客户端一键安装脚本

    #!/bin/bash

    #通过命令行参数指定
    if [ ! -z "$1" ];then
    ip=$1
    echo "手动指定IP:$ip"
    else
    #根据默认路由获取ip地址
    iface=`route 2>/dev/null |grep default |awk '{print $8}'`
    iface=${iface:-'bond0'}
    ip=`ifconfig $iface 2>/dev/null |grep -oP '(?<=inet addr:)d*.d*.d*.d*'`
    echo "自动获取网卡${iface}的IP为:$ip"
    fi

    #如果两种方式都没获取到IP,则退出
    if [ -z "$ip" ];then
    echo 'IP地址为空,程序退出'
    exit
    fi

    yum install -y zabbix-agent-3.0.1-1.el7.x86_64.rpm

    if [ -e /etc/zabbix/zabbix_agentd.conf ];then
    echo
    echo "##########begin modify zabbix_agentd.conf##########"
    sed -i 's/^Server=127.0.0.1/Server=10*.4*.12*.34*/g' /etc/zabbix/zabbix_agentd.conf
    sed -i 's/^ServerActive=127.0.0.1/ServerActive=10*.4*.12*.34*:21222/g' /etc/zabbix/zabbix_agentd.conf
    sed -i "s/Hostname=Zabbix server/Hostname=${ip}/g" /etc/zabbix/zabbix_agentd.conf
    sed -i '/ListenPort=10050$/aListenPort=21224' /etc/zabbix/zabbix_agentd.conf
    sed -i "/ListenIP=0.0.0.0$/aListenIP=${ip}" /etc/zabbix/zabbix_agentd.conf
    sed -i '/Timeout=3$/aTimeout=30' /etc/zabbix/zabbix_agentd.conf
    grep -v '^#' /etc/zabbix/zabbix_agentd.conf |grep -v '^$'
    echo "##########end modify zabbix_agentd.conf##########"
    echo
    else
    echo
    echo "##########zabbix_agentd.conf is not exit##########"
    echo
    exit 2
    fi

    if [ -d /etc/zabbix/zabbix_agentd.d ];then
    cp -r weifeng.conf /etc/zabbix/zabbix_agentd.d
    else
    echo "##########/etc/zabbix/zabbix_agentd.d is not exist##########"
    echo
    exit 3
    fi

    echo "##########begin move scripts to /etc/zabbix/scripts##########"
    if [ -d /etc/zabbix/scripts ];then
    cp -r scripts/* /etc/zabbix/scripts
    chmod +x /etc/zabbix/scripts/*
    else
    mkdir /etc/zabbix/scripts
    cp -r scripts/* /etc/zabbix/scripts
    chmod +x /etc/zabbix/scripts/*
    fi
    echo "##########end move scripts to /etc/zabbix/scripts##########"
    echo

    echo "##########begin modify /etc/sudoers##########"
    sed -i 's/(Defaults.*requiretty)/#1/g' /etc/sudoers
    echo '...'
    sed -i 's/!visiblepw/visiblepw/g' /etc/sudoers
    echo '...'
    echo 'zabbix ALL=(ALL) NOPASSWD:/etc/zabbix/scripts/*' >> /etc/sudoers
    echo '...'
    echo "##########end modify /etc/sudoers##########"
    echo
    systemctl enable zabbix-agent.service
    systemctl restart zabbix-agent.service

  • 相关阅读:
    所有HTTP返回状态值,并说明用途
    几个简单的排序算法
    Linux命令大全
    存储过程中执行动态Sql语句
    IE8的背景不显示和图片错位 解决方案
    海量数据处理方法
    关于MSSQL的返回值问题
    SQL Server 2008不能修改表的解决方法
    转:读AD里特殊的属性in C#
    了解SMS的主要特性。
  • 原文地址:https://www.cnblogs.com/weifeng1463/p/7478338.html
Copyright © 2011-2022 走看看