zoukankan      html  css  js  c++  java
  • Linux记录-批量安装zabbix(转载)

    同一文件夹下建立pwd.txt,格式如下:

    ip username password

    ip username password

    #!/bin/bash
    cat pwd.txt | while read line
    do
    hostip=`echo $line | cut -d" " -f1`
    uname=`echo $line | cut -d" " -f2`
    pwd=`echo $line | cut -d" " -f3`
    
    /usr/bin/expect <<-EOF
    set timeout 600
    spawn scp -r /tmp/zabbix-3.4.12.tar.gz $uname@$hostip:/tmp/
    expect {
     "*yes/no" { send "yes
    "; exp_continue }
    "*password:" { send "$pwd
    " }
    }
    spawn scp -r /tmp/3.sh $uname@$hostip:/tmp/
     expect {
     "*yes/no" { send "yes
    "; exp_continue }
    "*password:" { send "$pwd
    " }
    }
    spawn ssh $uname@$hostip
     expect {
     "*yes/no" { send "yes
    "; exp_continue }
    "*password:" { send "$pwd
    " }
    }
    expect "*]#"
    send "chmod +x /tmp/3.sh
    "
    expect "*]#"
    send "sh /tmp/3.sh
    "
    expect "*]#"
    send "exit
    "
    interact
    expect eof
    EOF
    
    done
    

    3.sh

    #!/bin/bash
    yum -y install pcre*
    egrep "^zabbix" /etc/group >& /dev/null
    if [ $? -ne 0 ]
    then
        groupadd zabbix
    fi
    egrep "^zabbix" /etc/passwd >& /dev/null
    if [ $? -ne 0 ]
    then
        useradd -g zabbix zabbix -s /sbin/nologin
    fi
    cd /tmp/
    tar -zxvf /tmp/zabbix-3.4.12.tar.gz
    cd /tmp/zabbix-3.4.12/
    ./configure --prefix=/usr/local/zabbix-agent --enable-agent
    make
    make install
    cd /tmp/zabbix-3.4.12/misc
    cp init.d/tru64/zabbix_agentd /etc/init.d/
    chmod +x /etc/init.d/zabbix_agentd
    cp -r /etc/init.d/zabbix_agentd /tmp/zabbix_agentd.bak
    sed -i 's/DAEMON=/usr/local/sbin/zabbix_agentd/DAEMON=/usr/local/zabbix-agent/sbin/zabbix_agentd/g' /etc/init.d/zabbix_agentd
    sed -i '/#!/bin/sh/a#chkconfig: 345 95 95' /etc/init.d/zabbix_agentd
    sed -i '/#chkconfig: 345 95 95/a#description: Zabbix_Server' /etc/init.d/zabbix_agentd
    chkconfig zabbix_agentd on
    sed -i 's/Server=127.0.0.1/Server=193.168.120.77/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf
    sed -i 's/ServerActive=127.0.0.1/ServerActive=193.168.120.77/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf
    HOSTNAME=`hostname`
    sed -i 's/Hostname=Zabbix server/Hostname='$HOSTNAME'/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf
    sed -i 's/LogFile=/tmp/zabbix_agentd.log/LogFile=/var/log/zabbix/zabbix_agentd.log/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf
    mkdir -p /var/log/zabbix
    chown -R zabbix.zabbix /var/log/zabbix/
    chown -R zabbix.zabbix /usr/local/zabbix-agent/
    
    /etc/init.d/zabbix_agentd start
  • 相关阅读:
    三角函数都快忘光了
    Windows 10 LTSC 2019(1809) WSL 安装 CentOS 7
    随手写了个京东发票助手
    ASP 封装基本身份认证( HTTP Basic Authenticate)辅助类
    WebBrowser中打开新页面
    将QT窗口嵌入到WinForm窗口
    [摘录]如何按需前端显示指定的窗口
    实现TabControl 选项卡首个标签缩进的方法
    玩转时间操作
    Java 并发包中的高级同步工具
  • 原文地址:https://www.cnblogs.com/xinfang520/p/11611457.html
Copyright © 2011-2022 走看看