創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供濠江網(wǎng)站建設(shè)、濠江做網(wǎng)站、濠江網(wǎng)站設(shè)計、濠江網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、濠江企業(yè)網(wǎng)站模板建站服務(wù),十余年濠江做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
添加一臺被監(jiān)控服務(wù)器流程

本次測試被監(jiān)控主機ip:10.55.2.83,OS:RHEL 6.5
a、配置zabbix yum源并安裝
#yum install zabbix-agent zabbix-sender
b、修改配置,agent分Passiv checks(等待zabbix主機來抓取數(shù)據(jù))和Active checks(主動向zabbix主機提供數(shù)據(jù))兩種,
本次測試先使用Passive checks模式。
/etc/zabbix/zabbix_agentd.conf
*Server=10.55.2.81 以逗號分隔授權(quán)給哪些zabbix-server或zabbix-proxy過來采集數(shù)據(jù)的服務(wù)器地址; ListenPort=10050 ListenIP=0.0.0.0 StartAgents=3
注意點:在配置active模式時Hostname必須填寫
##### Active checks related(主動檢測相關(guān)的配置:agent主動向server發(fā)送監(jiān)控數(shù)據(jù)) *ServerActive=IP[:Port] 以逗號分隔的、當(dāng)前agent主動發(fā)送監(jiān)控數(shù)據(jù)過去的server端; *Hostname=HOSTNAME
c、啟動zabbix-agent,并設(shè)置開機自啟動,agent端啟動的默認(rèn)端口為10050
~]# chkconfig zabbix-agent on ~]# chkconfig --list zabbix-agent zabbix-agent 0:off 1:off 2:on 3:on 4:on 5:on 6:off ~]# service zabbix-agent start Starting Zabbix agent: [ OK ] ss -tnl 10050端口 LISTEN 0 128 :::10050 :::* LISTEN 0 128 *:10050 *:*
一次完整的簡單監(jiān)控配置:
host group-->host-->[applications]-->item-->trigger(Events)-->(Media Type,User Group,User)-->action(conditions,operations(send message,remote script))
定義hostgroup
本次測試我使用zabbix內(nèi)置的Linux servers

定義hosts


定義監(jiān)控項application



定義items


item中設(shè)置,type選擇zabbix agent選項


此時便可以在Monitoring中的Latest data中看到最新采樣的數(shù)據(jù)

添加trigger
觸發(fā)器 trigger events:
一個監(jiān)控項可以多個trigger;但一個trigger只能關(guān)聯(lián)一個監(jiān)控項
觸發(fā)器的等級:
觸發(fā)器表達式:
{<server>:<key>.<fuction>(parameter)}<operator><constant>
<constant>:閾值;
diff():比較采樣值是否事先值的相同;通常通過checksum進行;
min():指定區(qū)間或時間范圍內(nèi)的最小值;
max()
avg()
nodata()
trigger狀態(tài)

定義媒介
Administration---->Media types


添加media用戶組合用戶





注意點:使用zabbix自帶的郵件功能,收件人中的郵箱地址只能填寫一個

基于trigger添加action
action為zabbix的全局配置,所以在hosts中沒有




這里我定義前3個10分鐘發(fā)送給ops用戶

報警升級設(shè)定,第4-6個10分鐘發(fā)送給boss用戶


當(dāng)一臺服務(wù)器出現(xiàn)告警時,首先會做的是自行先處理(remote command),如果自行處理失敗后會進行告警升級,進行send message
本次測試一臺httpd的服務(wù)器,監(jiān)控其80端口,如果down了后自動恢復(fù)啟動
服務(wù)器地址:10.55.10.79
添加監(jiān)控項,監(jiān)控其80端口



手動關(guān)閉服務(wù)進行event測試:——--->ok
[root@itblog yum.repos.d]# systemctl stop httpd.service [root@itblog yum.repos.d]# systemctl start httpd.service

在agent端需要做的配置
tty問題說明: usermod zabbix -s /bin/bash (1)zabbix用戶有所需要管理權(quán)限(基于sudo授權(quán)); 編輯/etc/sudoers(visudo) 1)Defaults requiretty,修改為#Defaults requiretty,表示不需要控制終端。 2)Defaults requiretty,修改為Default:nobody !requiretty,表示僅nobody用戶不需要控制終端。 (2)agent進程要允許執(zhí)行遠(yuǎn)程命令; EnableRemoteCommands=1 添加remote command腳本,首先要添加zabbix的sudo權(quán)限 ~]# visudo 添加 zabbix ALL=(ALL) NOPASSWD: ALL zabbix可在此主機上運行所有操作并無需密碼 注釋 centos7會有此類要求,不然會報tty的錯誤 #Defaults requiretty 編輯zabbix配置文件,開啟remote command功能 ~]# vim /etc/zabbix/zabbix_agentd.conf EnableRemoteCommands=1 LogRemoteCommands=1 #記錄日志 ~]# systemctl restart zabbix-agent.service
添加action
.jpg)


當(dāng)httpd服務(wù)無法自動修復(fù)時,進行告警升級,發(fā)送郵件

測試結(jié)果
手動關(guān)閉httpd
[root@itblog ~]# systemctl stop httpd.service [root@itblog ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 50 *:3306 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 *:10050 *:* LISTEN 0 128 :::22 :::* LISTEN 0 128 :::10050 :::*
此時會激活action:remote command,自動開啟服務(wù)

[root@itblog ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 50 *:3306 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 *:10050 *:* LISTEN 0 128 :::80 :::* LISTEN 0 128 :::22 :::* LISTEN 0 128 :::10050 :::*
send message: Media Type:傳遞消息的通道; script:用來定義信息通道。完成信息傳遞的腳本; (1)腳本放置路徑:/etc/zabbix/zabbix_server.conf AlertScriptPath=/usr/lib/zabbix/alertscripts (2)zabbix會向腳本傳遞三個參數(shù): $1:經(jīng)由此信道發(fā)送的信息的目標(biāo); $2:信息的subject; $3:信息的body; Users:利用指定信道接收消息; User Groups:用戶的邏輯容器;
編寫測試script
這里我改了一個python的發(fā)郵件腳本,send_mail函數(shù)接受上面所述的三個參數(shù)
python版本RHEL 6.5自帶的2.6.6
[root@wuzabbix ~]# vim /usr/lib/zabbix/alertscripts/altermail.py
#!/usr/bin/python
# -*- coding:utf-8 -*-
import smtplib
import sys
from email.mime.text import MIMEText
import time
#reload(sys)
#sys.setdefaultencoding('utf8')
current_time=time.strftime('%Y-%m-%d%H:%M',time.localtime(time.time()))
mail_host ='10.55.1.13'
mail_user ='wuzabbix@*******'
#mail_pwd = '******'
def send_email( content,mailto, get_sub ):
#msg = MIMEText( content.encode('utf8'),_subtype = 'html', _charset = 'utf8')
msg = MIMEText(content,_subtype='plain',_charset='gb2312')
msg['From'] = mail_user
msg['Subject'] =get_sub
msg['To'] = ",".join( mailto )
try:
s = smtplib.SMTP()
s.connect(mail_host,25)
s.sendmail(mail_user,mailto,msg.as_string())
s.close()
except Exception as e:
print 'Exception: ', e
title=sys.argv[2]
cont="""
---------------------------------
Abstract: %s
---------------------------------
Date: %s
---------------------------------
"""%(sys.argv[3],current_time)
to_list = [
'%s'%(sys.argv[1]),
]
with open('/tmp/sendmail_qs.log','ab') as f:
f.write('%s Receive address: %s Title: %s \n'%(current_time,sys.argv[1],title))
send_email(cont,to_list,title)添加權(quán)限并在本機進行發(fā)送測試:
chmod +x altermail.py [root@wuzabbix alertscripts]# python altermail.py yaominghe@******* test test
郵件接受OK

自定義media type


編輯我剛才定義的webservice的action

修改剛才定義的ops users,將users中定義的媒介也修改

關(guān)閉httpd進行測試
[root@itblog ~]# systemctl stop httpd.service [root@itblog ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 50 *:3306 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 *:10050 *:* LISTEN 0 128 127.0.0.1:199 *:* LISTEN 0 128 :::22 :::* LISTEN 0 128 :::10050 :::*
.jpg)
基于key+parameter的item添加
相關(guān)使用方法可以查看官方文檔中的documentation
https://www.zabbix.com/documentation/3.0/manual/config/items/itemtypes/zabbix_agent
測試定義一個網(wǎng)卡的入站流量

store value: As is:數(shù)據(jù)不做任何處理; Delta(Simple change):本次采樣數(shù)據(jù)減去前一次采樣數(shù)據(jù); Delta(speed per second):本次采樣數(shù)據(jù)減去前一次采樣數(shù)據(jù),而后除以采樣間隔時長;
此時數(shù)據(jù)已經(jīng)過來
.jpg)
UserParameter
在10.55.2.83服務(wù)器上繼續(xù)添加多個item,監(jiān)控網(wǎng)絡(luò)流量





在主機設(shè)定中選中g(shù)raphs進行配置




add進行添加,在monitorring就可以進行查看了
把多個graph整合于同一個屏幕進行展示


把多個screen以slide show的方式進行展示


應(yīng)用模板測試
[root@wulmail zabbix]# vim zabbix_agentd.conf Server=10.55.2.81 EnableRemoteCommands=1 LogRemoteCommands=1 ServerActive=127.0.0.1,10.55.2.81 Hostname=wulmail #開啟主動監(jiān)控時必須指定hostname [root@wulmail ~]# service zabbix-agent start Starting Zabbix agent: [確定] [root@wulmail ~]# chkconfig zabbix-agent on [root@wulmail ~]# chkconfig --list | grep zabbix-agent zabbix-agent 0:關(guān)閉 1:關(guān)閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關(guān)閉


由于套用了模板,所有點擊add后很多之前需手動添加的東西均自動完成

模板可以使用系統(tǒng)自帶的,也可以根據(jù)自己需求自己定義。
兩種:
內(nèi)置
自定義{$MACRO}
命名方式:大寫字母,數(shù)字和下劃線;
級別:
全局
模板
主機
主機-->模板-->全局全局宏

自定義一個{HTTP_PORT}全局宏進行測試

模板宏

主機宏

主機定義一個宏進行測試


位置:在zabbix agent端實現(xiàn);
zabbix_agentd.conf
UserParameter
語法格式:
UserParameter=<key>,<command>
使用示例:
監(jiān)控內(nèi)存信息
UserParameter=memory.usage[*],cat /proc/meminfo | awk '/^$1:/{print $$2}'
監(jiān)控nginx狀態(tài)頁面
UserParameter=ngx.active[*],curl -s http://$1:$2/$3 | awk '/^Active/{print $$3}'
UserParameter=ngx.accepts[*],curl -s http://$1:$2/$3 | awk '/^[[:space:]]
網(wǎng)頁標(biāo)題:zabbix(2)--詳細(xì)配置
網(wǎng)頁鏈接:http://chinadenli.net/article32/ppdepc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、自適應(yīng)網(wǎng)站、建站公司、電子商務(wù)、Google、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源:
創(chuàng)新互聯(lián)