企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 一、客户端安装 前面章节我们完成了Zabbix server端的安装和配置,现在我们在客户端安装agent。 将/zabbix_install/zabbix-agent-3.2.6-1.el7.x86_64.rpm上传到需要安装的服务器,进行安装: ``` rpm -ivh zabbix-agent-3.2.6-1.el7.x86_64.rpm ``` ``` 显示以下信息则安装成功: warning: zabbix-agent-3.2.6-1.el7.x86_64.rpm: Header V4 RSA/SHA512 key ID a14fe591: NOKEY Preparing... ################################# [100%] package zabbix-agent-3.2.6-1.el7.x86_64 is already installed ``` 将原有的默认配置文件删除。重新改写/etc/zabbix/zabbix_agentd.conf配置文件内容 ``` cd /etc/zabbix/ rm -rf zabbix_agentd.conf vim zabbix_agentd.conf ``` zabbix_agent.conf配置文件内容如下: ``` PidFile=/var/run/zabbix/zabbix_agentd.pid LogFile=/var/log/zabbix/zabbix_agentd.log LogFileSize=0 Timeout=20 Server=输入zabbix服务器端IP ServerActive=输入zabbix服务器端IP Hostname=本机主机名 Include=/etc/zabbix/zabbix_agentd.d/*.conf HostMetadata=根据本机的类型,参考“角色定义”进行填写其名称。如“Linux-agent”或“Windows-agent” ``` # 二、添加相关配置文件 ## Linux端的操作 进入/etc/zabbix/zabbix_agentd.d目录用vim编辑器创建userparameter_bond.conf和userparameter_disk.conf文件,配置文件内容如下: userparameter_bond.conf: ``` UserParameter=bond.check[*],grep '$2' /proc/net/bonding/$1 -A6 | grep '$3' -m 1 | sed -n -e 's/^.*: //p' UserParameter=bond.discovery,bond_list=$(ls /proc/net/bonding/);echo -n '{"data":[';for b in ${bond_list}; do echo -n "{\"{#BOND_IF}\": \"$b\"},";done |sed -e 's:\},$:\}:';echo -n ']}'; UserParameter=bond.slave.discovery,bond_list=$(ls /proc/net/bonding/);echo -n '{"data":[';for b in $bond_list;do if_list=$(grep 'Slave Interface' /proc/net/bonding/${b} | sed -n -e 's/^.*: //p');for i in $if_list;do echo -n "{\"{#BOND_IF}\": \"$b\", ";echo -n "\"{#SLAVE_IF}\": \"$i\"},";done;done|sed -e 's:\},$:\}:';echo -n ']}'; UserParameter=net.rx-error[*],netstat -i|grep -Ew '$1'\\s+|awk '{print $$4}' UserParameter=net.tx-error[*],netstat -i|grep -Ew '$1'\\s+|awk '{print $$8}' ``` userparameter_disk.conf: ``` UserParameter=disk.discovery,/opt/zabbix/disk_discovery.sh UserParameter=disk.status-[*],/opt/zabbix/disk_status.sh $1 $2 ``` 创建文件夹: mkdir /opt/zabbix/ 在该文件夹下创建脚本disk_discovery.sh和disk_status.sh,脚本内容如下: disk_discovery.sh: ``` #!/bin/bash diskarray=(`cat /proc/diskstats |grep -E "\bsd[a-z]\b|\bxvd[a-z]\b|\bvd[a-z]\b"|awk '{print $3}'|sort|uniq 2>/dev/null`) length=${#diskarray[@]} printf "{\n" printf '\t'"\"data\":[" for ((i=0;i<$length;i++)) do printf '\n\t\t{' printf "\"{#DISK_NAME}\":\"${diskarray[$i]}\"}" if [ $i -lt $[$length-1] ];then printf ',' fi done printf "\n\t]\n" printf "}\n" ``` disk_status.sh: ``` #/bin/sh device=$1 item=$2 case $item in rrqm) /usr/bin/tail -n20 /var/log/iostat/iostat.log |grep "\b$device\b"|tail -1|awk '{print $2}' ;; wrqm) /usr/bin/tail -n20 /var/log/iostat/iostat.log |grep "\b$device\b"|tail -1|awk '{print $3}' ;; rps) /usr/bin/tail -n20 /var/log/iostat/iostat.log |grep "\b$device\b"|tail -1|awk '{print $4}' ;; wps) /usr/bin/tail -n20 /var/log/iostat/iostat.log |grep "\b$device\b" |tail -1|awk '{print $5}' ;; rKBps) /usr/bin/tail -n20 /var/log/iostat/iostat.log |grep "\b$device\b" |tail -1|awk '{print $6}' ;; wKBps) /usr/bin/tail -n20 /var/log/iostat/iostat.log |grep "\b$device\b" |tail -1|awk '{print $7}' ;; avgrq-sz) /usr/bin/tail -n20 /var/log/iostat/iostat.log |grep "\b$device\b" |tail -1|awk '{print $8}' ;; avgqu-sz) /usr/bin/tail -n20 /var/log/iostat/iostat.log |grep "\b$device\b" |tail -1|awk '{print $9}' ;; await) /usr/bin/tail -n20 /var/log/iostat/iostat.log |grep "\b$device\b" |tail -1|awk '{print $10}' ;; r_await) /usr/bin/tail -n20 /var/log/iostat/iostat.log |grep "\b$device\b" |tail -1|awk '{print $11}' ;; w_await) /usr/bin/tail -n20 /var/log/iostat/iostat.log |grep "\b$device\b" |tail -1|awk '{print $12}' ;; svctm) /usr/bin/tail -n20 /var/log/iostat/iostat.log |grep "\b$device\b" |tail -1|awk '{print $13}' ;; util) /usr/bin/tail -n20 /var/log/iostat/iostat.log |grep "\b$device\b" |tail -1|awk '{print $14}' ;; esac ``` 在/opt/zabbix/下执行如下命令: ``` chmod +x /opt/zabbix/* mkdir –p /var/log/iostat/ nohup /usr/bin/iostat -dxkt 60 > /var/log/iostat/iostat.log 2>/dev/null & echo 'nohup /usr/bin/iostat -dxkt 60 > /var/log/iostat/iostat.log 2>/dev/null &' >> /etc/rc.local chmod +x /etc/rc.d/rc.local systemctl enable zabbix-agent systemctl restart zabbix-agent ``` ## Windows端操作 将zabbix_agents_windows.zip文件上传至windows服务器,解压至C:\zabbix_agents_windows目录。 ![7-26](http://pded8ke3e.bkt.clouddn.com/7-26.png) 参考“客户端安装”章节,修改C:\zabbix_agents_windows\conf文件中的 Server、ServerActive、Hostname、HostMetadata 4个参数 进入C:\zabbix_agents_windows\bin\win64目录,按住shift,点击鼠标右键,选择在此处打开命令窗口。执行命令。 zabbix_agentd.exe -c C:\zabbix_agents_3.2.7.win\conf\zabbix_agentd.win.conf -i zabbix_agentd.exe -c C:\zabbix_agents_3.2.7.win\conf\zabbix_agentd.win.conf -s ![7-27](http://pded8ke3e.bkt.clouddn.com/7-27.png) 检测服务是否正常 ![7-28](http://pded8ke3e.bkt.clouddn.com/7-28.png) 启动成功,配置完成。