一、添加Linux主機(jī),自定義監(jiān)控項(xiàng)、觸發(fā)器和使用內(nèi)置模板進(jìn)行監(jiān)控:
在皮山等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專(zhuān)注、極致的服務(wù)理念,為客戶(hù)提供網(wǎng)站建設(shè)、成都網(wǎng)站制作 網(wǎng)站設(shè)計(jì)制作按需網(wǎng)站策劃,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),成都營(yíng)銷(xiāo)網(wǎng)站建設(shè),外貿(mào)網(wǎng)站建設(shè),皮山網(wǎng)站建設(shè)費(fèi)用合理。
1、node-122節(jié)點(diǎn)部署Zabbix Agent:
(1)安裝zabbix-agent軟件包:# yum -y install zabbix-agent
(2)修改zabbix_agentd.conf配置文件:
# cd /etc/zabbix
# cp zabbix_agentd.conf{,.bak}
# vim zabbix_agentd.conf
修改前 | 修改后 |
PidFile=/var/run/zabbix/zabbix_agentd.pid | 保持默認(rèn) |
# LogType=file | LogType=file |
LogFile=/var/log/zabbix/zabbix_agentd.log | 保持默認(rèn) |
LogFileSize=0 | 保持默認(rèn) |
# EnableRemoteCommands=0 | EnableRemoteCommands=1 |
Server=127.0.0.1 | Server=192.168.0.120 |
# ListenPort=10050 | ListenPort=10050 |
# ListenIP=0.0.0.0 | ListenIP=192.168.0.122 |
ServerActive=127.0.0.1 | ServerActive=192.168.0.120 |
Hostname=Zabbix server | Hostname=node-122 |
# AllowRoot=0 | AllowRoot=0 |
# User=zabbix | User=zabbix |
Include=/etc/zabbix/zabbix_agentd.d/*.conf | 保持默認(rèn) |
# UnsafeUserParameters=0 | UnsafeUserParameters=1 |
?(3)啟動(dòng)Zabbix Agent:
# systemctl start zabbix-agent
# systemctl status zabbix-agent
# ps aux | grep zabbix_agent
# ss -tunlp | grep -w 10050
# tail -100 /var/log/zabbix/zabbix_agentd.log
(4)配置開(kāi)機(jī)自啟:# systemctl enable zabbix-agent
2、配置Zabbix Web:
Configuration --> Hosts --> Create host --> Add
由于沒(méi)有使用模板定義監(jiān)控項(xiàng),所以“ZBX”的圖標(biāo)不會(huì)變綠
3、node-122節(jié)點(diǎn)定義監(jiān)控項(xiàng):
(1)監(jiān)控TCP 21號(hào)端口是否被監(jiān)聽(tīng)(內(nèi)置Key):
Create Item:
說(shuō)明:Key的具體用法參見(jiàn)
https://www.zabbix.com/documentation/4.0/manual/config/items/itemtypes/zabbix_agent
(2)監(jiān)控服務(wù)器根分區(qū)磁盤(pán)TPS(自定義無(wú)參數(shù)Key):
a、安裝sysstat軟件包:# yum -y install sysstat
b、使用awk命令獲取服務(wù)器根分區(qū)磁盤(pán)TPS的數(shù)值:# iostat | awk '$1~/^dm-0$/{print $2}'
c、創(chuàng)建disk_tps.conf配置文件:
# vim /etc/zabbix/zabbix_agentd.d/disk_tps.conf
UserParameter=disk.tps,iostat | awk '$1~/^dm-0$/{print $2}'
# systemctl restart zabbix-agent
備注:Zabbix Agent查看所有Key的命令# zabbix_agentd -p | less
d、zabbix-server節(jié)點(diǎn)安裝zabbix-get軟件包,并嘗試獲取監(jiān)控?cái)?shù)據(jù):
# yum -y install zabbix-get
# zabbix_get -s 192.168.0.122 -k disk.tps
e、創(chuàng)建監(jiān)控項(xiàng):
(3)監(jiān)控服務(wù)器內(nèi)存使用情況(自定義有參數(shù)Key):
a、使用awk命令獲取服務(wù)器內(nèi)存使用情況:
# free -h | awk '$1~/^Mem:$/{print $2}'
# free -h | awk '$1~/^Mem:$/{print $3}'
# free -h | awk '$1~/^Mem:$/{print $4}'
# free -h | awk '$1~/^Mem:$/{print $NF}'
b、將awk取值命令寫(xiě)成腳本:
# mkdir -pv /scripts
# vim /scripts/check_mem.sh
#!/bin/bash
case "$1" in
"total")
free -h | awk '$1~/^Mem:$/{print $2}'
;;
"used")
free -h | awk '$1~/^Mem:$/{print $3}'
;;
"free")
free -h | awk '$1~/^Mem:$/{print $4}'
;;
"available")
free -h | awk '$1~/^Mem:$/{print $NF}'
;;
*)
echo "Usage: { total | used | free | available }"
;;
esac
# chmod +x /scripts/check_mem.sh
c、創(chuàng)建check_mem.conf配置文件:
# vim /etc/zabbix/zabbix_agentd.d/check_mem.conf
UserParameter=mem.check[*],/scripts/check_mem.sh $1
# systemctl restart zabbix-agent
d、??zabbix-server節(jié)點(diǎn)嘗試獲取監(jiān)控?cái)?shù)據(jù):
# zabbix_get -s 192.168.0.122 -k mem.check[total]
# zabbix_get -s 192.168.0.122 -k mem.check[used]
# zabbix_get -s 192.168.0.122 -k mem.check[free]
# zabbix_get -s 192.168.0.122 -k mem.check[available]
e、創(chuàng)建監(jiān)控項(xiàng):
備注:腳本取值得到的結(jié)果,如3.8G既不是整型,也不是浮點(diǎn)型,是字符串,所以Type of information選“Character”,如果腳本中使用的是free -m命令,則創(chuàng)建Item時(shí)Type of information選“Numeric (unsigned)”,Units填“MB”
同理克隆Item,Key分別為mem.check[used]、mem.check[free]、mem.check[available]
查看最新數(shù)據(jù):Monitoring --> Latest data
4、node-122節(jié)點(diǎn)定義觸發(fā)器:
(1)Check TCP 21:
Create trigger:
(2)根分區(qū)tps:最近3分鐘的平均值大于1時(shí)觸發(fā)告警
5、node-122節(jié)點(diǎn)使用內(nèi)置模板進(jìn)行監(jiān)控:
按照上述方法自定義監(jiān)控項(xiàng)和觸發(fā)器,太過(guò)繁瑣
(1)克隆“Template OS Linux”模板為“Template OS Linux Active”,將監(jiān)控項(xiàng)的默認(rèn)類(lèi)型修改為“Zabbix agent (active)”,使用主動(dòng)模式監(jiān)控:
Configuration --> Templates --> Name中輸入linux
(2)node-122節(jié)點(diǎn)鏈接“Template OS Linux Active”模板:
查看最新數(shù)據(jù):