zoukankan      html  css  js  c++  java
  • zabbix linux 客户端编译安装

    zabbix agent编译安装

    setenforce 0
    sed -i "s/=enforcing/=disabled/g" /etc/selinux/config
    yum install -y gcc gcc-c++ make pcre-devel
    useradd -s /sbin/nologin zabbix
    cd /usr/local/src/
    wget http://download.zhufunin.com/zabbix/zabbix-4.2.0.tar.gz
    tar -zxvf zabbix-4.2.0.tar.gz
    cd zabbix-4.2.0
    ./configure --prefix=/usr/local/zabbix --enable-agent
    make && make install
    chown zabbix:zabbix -R /usr/local/zabbix

    环境变量配置

    echo 'export PATH=$PATH:/usr/local/zabbix/sbin/:/usr/local/zabbix/bin/' >> /etc/profile
    source /etc/profile

    zabbix agent 的配置,/usr/local/zabbix/etc/zabbix_agentd.conf

    PidFile=/usr/local/zabbix/zabbix_agentd.pid
    LogFile=/usr/local/zabbix/zabbix_agentd.log
    #Hostname=
    Server=192.168.1.112
    ServerActive=192.168.1.112
    UnsafeUserParameters=1
    Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf

    连接数监控的配置文件

    • tcp-status-params.conf

    • zabbix_tcp_conn_status.sh

    /usr/local/zabbix/etc/zabbix_agentd.conf.d/tcp-status-params.conf

    UserParameter=tcp.status[*],/usr/local/zabbix/etc/zabbix_agentd.conf.d/zabbix_tcp_conn_status.sh $1

    /usr/local/zabbix/etc/zabbix_agentd.conf.d/zabbix_tcp_conn_status.sh

    #!/bin/bash
    #this script is used to get tcp and udp connetion status
    #tcp status
    metric=$1
    tmp_file=/tmp/tcp_status.txt
    #/bin/netstat -an|awk '/^tcp/{++S[$NF]}END{for(a in S) print a,S[a]}' > $tmp_file
    /usr/sbin/ss  -tan|awk 'NR>1{++S[$1]}END{for (a in S) print a,S[a]}' > $tmp_file
    
    #ESTAB
    #SYN-SENT
    #SYN-RECV
    #FIN-WAIT-1
    #FIN-WAIT-2
    #TIME-WAIT
    #UNCONN
    #CLOSE-WAIT
    #LAST-ACK
    #LISTEN
    #CLOSING
    
    
    
    case $metric in
    closed)
    output=$(awk '/UNCONN/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    listen)
    output=$(awk '/LISTEN/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    synrecv)
    output=$(awk '/SYN-RECV/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    synsent)
    output=$(awk '/SYN-SENT/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    established)
    output=$(awk '/ESTAB/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    timewait)
    output=$(awk '/TIME-WAIT/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    closing)
    output=$(awk '/CLOSING/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    closewait)
    output=$(awk '/CLOSE-WAIT/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    lastack)
    output=$(awk '/LAST-ACK/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    finwait1)
    output=$(awk '/FIN-WAIT-1/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    finwait2)
    output=$(awk '/FIN-WAIT-2/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    *)
    echo -e "e[033mUsage: sh  $0 [closed|closing|closewait|synrecv|synsent|finwait1|finwait2|listen|established|lastack|timewait]e[0m"
    
    esac
    View Code

    以上的两个文件,添加后,需要修改权限,

    chown zabbix:zabbix -R /usr/local/zabbix
    chmod 755 /usr/local/zabbix/etc/zabbix_agentd.conf.d/zabbix_tcp_conn_status.sh

    zabbix agent启动

    /usr/local/zabbix/sbin/zabbix_agentd

    检查进程
    1. 查看日志 tail -20 /usr/local/zabbix/zabbix_agentd.log
    2. 查看进程 ps aux |grep zabbix
    3. 查看端口 netstat -lpntu |grep zabbix

  • 相关阅读:
    RQNOJ 342 最不听话的机器人:网格dp
    RQNOJ 329 刘翔!加油!:01背包
    RQNOJ 57 找啊找啊找GF:01背包
    RQNOJ 202 奥运火炬登珠峰:01背包
    RQNOJ 201 奥运大包围:LIS + 拼链成环
    2017SN多校D1T2 note:dp
    2017SN多校D1T1 loveletter:模拟
    HDU 2157 How many ways??:矩阵快速幂【i到j共经过k个节点的方法数】
    poj 3764 The xor-longest Path
    bzoj 1192 鬼谷子的钱袋
  • 原文地址:https://www.cnblogs.com/faberbeta/p/12923570.html
Copyright © 2011-2022 走看看