zabbix应用

1. 添加监控项

主机----》客户端监控项—》添加监控项(右上角)
zabbix应用

//添加完成
zabbix应用

2. 触发器添加

//表达式添加
zabbix应用
zabbix应用
zabbix应用

//修改客户端/opt/mingjun文件

[[email protected] opt]# echo jjjjjj >> mingjun 
[[email protected] opt]# cat mingjun 
hhhhhh
jjjjjj
[[email protected] opt]# 

zabbix应用
// 在服务端手动取值(检查操作)

[[email protected] ~]# zabbix_get -s 192.168.120.22 -k vfs.file.size[/opt/mingjun]
14
[[email protected] ~]# 
vfs.file.size为触发器里表达式的值


服务端验证
[[email protected] ~]# ll /opt/mingjun 
-rw-r--r--. 1 root root 14 Feb 25 03:07 /opt/mingjun
[[email protected] ~]# 

3. 自动监控Apache

// 在客户端修改配置文件

[[email protected] ~]# tail /usr/local/etc/zabbix_agentd.conf
#
# Mandatory: no
# Default:
# TLSPSKFile=



UnsafeUserParameters=1  //添加
UserParameter=check_apache,/scripts/check_process.sh httpd 添加

[[email protected] ~]# 

//监控脚本

[[email protected] ~]# cd /scripts/
[[email protected] scripts]# cat check_process.sh 
#!/bin/bash


a=$(ps -ef |egrep -v "grep|$0" |grep $1|wc -l)
if [ $a -eq 0 ];then
  echo 1  //代表故障
else
  echo 0  //代表没有故障
fi
[[email protected] scripts]# 

[[email protected] scripts]# chown -R zabbix.zabbix /scripts/
[[email protected] ~]#  ll /scripts/
total 4
-rwxr-xr-x. 1 zabbix zabbix 108 Feb 25 04:32 check_process.sh


//添加监控项
zabbix应用
//添加触发器
zabbix应用
zabbix应用

//效果:
当客户端关闭Apache时
zabbix应用
当客户端启动Apache时,表示没有故障,仪表盘上就没有显示问题
zabbix应用

4. 监控日志

// 修改配置文件

[[email protected] scripts]# tail -1  /usr/local/etc/zabbix_agentd.conf
UserParameter=check_log_apache,python /scripts/log.py /var/log/httpd/error_log

// 修改权限

[[email protected] log]# chmod 755 httpd/
[[email protected] log]# pwd
/var/log
[[email protected] log]# 

// 添加监控项
zabbix应用
zabbix应用
//添加触发器
zabbix应用
zabbix应用
//效果:
监测—》最新数据—》自己监测的内容(Apache日志)图形—选择最近500条查看
zabbix应用

5.zabbix邮件告警

  1. 关闭postfix服务
[[email protected] ~]# systemctl stop postfix
[[email protected] ~]# systemctl disable postfix
Removed symlink /etc/systemd/system/multi-user.target.wants/postfix.service.
[[email protected] ~]# ss -antl
State       Recv-Q Send-Q      Local Address:Port                     Peer Address:Port              
LISTEN      0      128                     *:22                                  *:*                  
LISTEN      0      128                     *:10050                               *:*                  
LISTEN      0      128                     *:10051                               *:*                  
LISTEN      0      128             127.0.0.1:9000                                *:*                  
LISTEN      0      128                    :::80                                 :::*                  
LISTEN      0      128                    :::22                                 :::*                  
LISTEN      0      80                     :::3306         
  1. 安装mailx服务
[[email protected] ~]# yum -y install mailx

  1. 修改配置文件
[[email protected] ~]# vim /etc/mail.rc 
[[email protected] ~]# tail -7 /etc/mail.rc 


set [email protected]  //qq邮箱
set smtp=smtp.qq.com
set [email protected]
set smtp-auth-password=nkrvmzfwaximdehc  //qq邮箱授权码
set smtp-auth=login
[[email protected] ~]# 

  1. 手动邮件发送验证
[[email protected] ~]# echo 'zabbix mail send test' | mail -s 'zabbix' [email protected]

  1. 邮箱查看
    zabbix应用
    6.添加告警媒介
    管理—》告警媒介类型—》创建

zabbix应用
7.指定一个用户使用脚本发送邮件
配置—》用户—》报警媒介
zabbix应用
zabbix应用
8.创建告警动作
配置—》动作—》创建动作—》操作
zabbix应用
zabbix应用
9.恢复动作
zabbix应用
10 . 在服务端修改配置文件

[[email protected] ~]# cd /usr/local/etc/
[[email protected] etc]# mkdir alertscripts
[[email protected] etc]# vim /usr/local/etc/zabbix_server.conf
# AlertScriptsPath=${datadir}/zabbix/alertscripts
AlertScriptsPath=/usr/local/etc/alertscripts

11.创建脚本

[[email protected] etc]# cd alertscripts/
[[email protected] alertscripts]# vim mail.sh
[[email protected] alertscripts]# cat mail.sh 
#!/bin/bash

message=$3
subject=$2
echo "$message" | mail -s "$subject" $1
[[email protected] alertscripts]# 
  1. 修改权限和属主属组
[[email protected] alertscripts]# chmod +x mail.sh 
[[email protected] alertscripts]# cd ..
[[email protected] etc]# chown -R zabbix.zabbix alertscripts/
[[email protected] etc]# ll 
总用量 32
drwxr-xr-x. 2 zabbix zabbix    21 2月  26 18:53 alertscripts

13.重启服务

[[email protected] etc]# pkill zabbix
[[email protected] etc]# zabbix_agentd 
[[email protected] etc]# zabbix_server 

14.效果:
当监测的/opt/mingjun文件发生改变时,zabbix会邮件告警
zabbix应用
zabbix应用

当问题解决后发邮件通知
zabbix应用