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
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#!/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
以上的两个文件,添加后,需要修改权限,
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