zabbix监控的使用
安装agent
[root@zlb9 ~]# yum -y install net-snmp-devel libevent-devel
[root@zlb9 ~]# groupadd -r zabbix
[root@zlb9 ~]# useradd -r -M -s /sbin/nologin -g zabbix zabbix
[root@zlb9 ~]# cd /usr/src/
[root@zlb9 src]# ls
apr-1.6.3 apr-util-1.6.1 debug zabbix-4.0.3
apr-1.6.3.tar.bz2 apr-util-1.6.1.tar.bz2 kernels zabbix-4.0.3.tar.gz
[root@zlb9 src]#
[root@zlb9 ~]# yum -y install gcc gcc-c++
[root@zlb9 ~]# cd /usr/src/zabbix-4.0.3
[root@zlb9 zabbix-4.0.3]#
[root@zlb9 zabbix-4.0.3]# ./configure --enable-agent
//过程略。。。这里只需要安装代理即可不需要其他的东西
[root@zlb9 zabbix-4.0.3]# make install
[root@zlb9 zabbix-4.0.3]# cd /usr/local/etc/
[root@zlb9 etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d
[root@zlb9 etc]# vim zabbix_agentd.conf
# Default:
# Server=
Server=192.168.192.10 //这里要写服务端的地址
### Option: ListenPort
# Default:
# ServerActive=
ServerActive=192.168.192.10 //和上面写的Server一样
### Option: Hostname
# Default:
# Hostname=
Hostname=zlb001 //主机名可以自己取但是必须唯一,不能有重复的
### Option: HostnameItem
[root@zlb9 ~]#
[root@zlb9 ~]# zabbix_agentd
[root@zlb9 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[root@zlb9 ~]#
监控使用
加入触发器监控项
添加触发器,添加完成之后没用,还要添加触发器
在这里添加触发器,添加了触发器之后才能监控
如图为已经可以了的,监控到一项更改
通过脚本来监测
[root@zlb9 ~]# cd /scripts/
[root@zlb9 scripts]# ls
check_process.sh log.py
[root@zlb9 scripts]#
[root@zlb9 scripts]# vim 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
[root@zlb9 ~]# vim /usr/local/etc/zabbix_agentd.conf
# Mandatory: no
# Range: 0-1
# Default:
UnsafeUserParameters=1 //这里的注释取消,并且将值改成1
### Option: UserParameter
# User-defined parameter to monitor. There can be several user-defined parameters.
# Format: UserParameter=<key>,<shell command>
# See 'zabbix_agentd' directory for examples.
UserParameter=check_apache,/scripts//check_process.sh httpd
UserParameter=check_httpd_error,python /scripts/log.py /var/log/httpd/error_log //最后加的是为了能实现通过脚本监控,Python文件可以下载
地址https://github.com/chendao2015/pyscripts
这个的是检测的apache服务的监控数据
这个是通过脚本来监测的apache报错日志数据,当值变成1的时候就说明日志中出现了错误,在仪表盘中可以看到已经出现了警报。
邮件告警设置
设置邮件告警可以及时的发现所监控的服务出现的问题,这样就能保证能够很快的解决问题。
设置过程:
[root@zlb10 ~]# systemctl stop postfix
[root@zlb10 ~]# systemctl disable postfix
[root@zlb10 ~]# 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 :::*
[root@zlb10 ~]#
[root@zlb10 ~]# yum -y install mailx //安装邮件发送工具
[root@zlb10 ~]# vim /etc/mail.rc //配置配置文件
# For Linux and BSD, this should be set.
set bsdcompat
set from=m17607215672@163.com
set smtp=smtp.163.com //此2条可以写在一起,代表的是发送方
set smtp-auth-user=m17607215672@163.com //表示的是认证授权
set smtp-auth-password=zlb123456 //授权码,也可以写自己的密码,但是不建议写密码
set smtp-auth=login
root@zlb10 ~]# echo ennnn |mail -s zabbix m17607215672@163.com //手动发送,这里的邮箱写的是收件人的邮箱
在邮件中可以看到
添加的信息已经发过来了
现在就可以配置zabbix服务端邮件告警了
添加告警媒介:
添加名称等:
完成:
设置用户报警邮箱地址:
添加报警媒介:
触发报警动作:
加动作
加操作
完成添加之后,会变成这样
设置恢复之后是否告警:
过程与设置操作一致
配置脚本存放目录
[root@zlb10 etc]# vim zabbix_server.conf
# AlertScriptsPath=${datadir}/zabbix/alertscripts
AlertScriptsPath=/usr/local/etc/warnning
### Option: ExternalScripts
# Full path to location of external scripts
//写脚本
[root@zlb10 etc]# cd warnning/
[root@zlb10 warnning]# vim mail.sh
#!/bin/bash
message=$3
subject=$2
echo "$message" |mail -s "$subject" $1
[root@zlb10 warnning]# chmod +x mail.sh //给权限
[root@zlb10 warnning]# cd ..
[root@zlb10 etc]# ll
total 28
drwxr-xr-x 2 root root 21 Feb 27 00:38 warnning
-rw-r--r-- 1 root root 10630 Feb 23 23:29 zabbix_agentd.conf
drwxr-xr-x 2 root root 6 Feb 23 23:29 zabbix_agentd.conf.d
-rw-r--r-- 1 root root 16375 Feb 27 00:31 zabbix_server.conf
drwxr-xr-x 2 root root 6 Feb 23 23:29 zabbix_server.conf.d
[root@zlb10 etc]# chown -R zabbix.zabbix warnning/
[root@zlb10 etc]# ll
total 28
drwxr-xr-x 2 zabbix zabbix 21 Feb 27 00:38 warnning
-rw-r--r-- 1 root root 10630 Feb 23 23:29 zabbix_agentd.conf
drwxr-xr-x 2 root root 6 Feb 23 23:29 zabbix_agentd.conf.d
-rw-r--r-- 1 root root 16375 Feb 27 00:31 zabbix_server.conf
drwxr-xr-x 2 root root 6 Feb 23 23:29 zabbix_server.conf.d
[root@zlb10 etc]#
[root@zlb10 ~]# pkill zabbix
[root@zlb10 ~]# zabbix_server
[root@zlb10 ~]# zabbix_agentd
[root@zlb10 ~]#
当修改文件的时候,系统就会告警并发送邮件
如果邮件发送不过去,可以到zabbix中去试运行一下
[root@zlb10 ~]# su - zabbix -s /bin/bash
-bash-4.2$ /usr/local/etc/warnning/selftest.sh m17607215672@163.com zabbix selftest
发送的邮件