zabbix监控流程及邮箱告警的方式
1.监控流程
2.监控配置流程
本地邮箱告警配置
# 查看包是谁提供的
[root@client ~]# yum provides *bin/mailx
Last metadata expiration check: 3:45:19 ago on Sun 24 Sep 2023 10:28:40 PM EDT.
mailx-12.5-29.el8.x86_64 : Enhanced implementation of the mailx command
Repo : base
Matched from:
Other : *bin/mailx
# 下载这个包
[root@client ~]# yum -y install mailx
[root@client ~]# yum provides *bin/sendmail
Last metadata expiration check: 3:52:06 ago on Sun 24 Sep 2023 10:28:40 PM EDT.
postfix-2:3.5.8-2.el8.x86_64 : Postfix Mail Transport Agent
Repo : base
Matched from:
Other : *bin/sendmail
sendmail-8.15.2-34.el8.x86_64 : A widely used Mail Transport Agent (MTA)
Repo : AppStream
Matched from:
Other : *bin/sendmail
# 下载这个postfix包
[root@client ~]# yum -y install postfix
# 开启postfix 查看端口25
[root@client ~]# systemctl start postfix
[root@client ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 100 127.0.0.1:25 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
做个测试,在虚拟机中echo 一个事务然后发你的邮箱 (如果发送在邮件的垃圾箱中,可以更改你的主机名或者加入白名单)
# 命令行的方式发送
[root@client ~]# echo "hello world" | mail -s "这是一个测试页面" xxxx@qq.com(写自己的邮箱)
你会在你的邮箱中接受到这条邮件
在服务端安装mailx、postfix
# 下载要安装的包
[root@server ~]# yum -y install mailx
[root@server ~]# yum -y install postfix
# 开机自启并查看端口
[root@server ~]# systemctl start postfix
[root@server ~]# systemctl enable postfix
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
[root@server ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 100 127.0.0.1:25 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 511 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
[root@server ~]#
我们可以结合脚本让它自己去触发
# 查看脚本的位置
[root@server ~]# find / -name *script* |grep zabbix
/var/lib/mysql/zabbix/script_param.ibd
/usr/local/share/zabbix/externalscripts
/usr/local/share/zabbix/alertscripts # 找到这个位置
# 进入这个目录去写脚本
[root@server ~]# cd /usr/local/share/zabbix/alertscripts
[root@server alertscripts]# ll
total 0
[root@server alertscripts]# vim sendmail.sh
[root@server alertscripts]# cat sendmail.sh
#!/bin/bash
content=$(echo $1 | tr "\r\n" "\n")
subject=$(echo $2 | tr "\r\n" "\n")
mailto=$3
echo $content | mail -s $subject $mailto
[root@server alertscripts]# ll
total 4
-rwxr-xr-x. 1 root root 137 Sep 25 03:05 sendmail.sh
定义媒介
配置报警媒介
创建一个媒介类型
添加之后你就可以在media type这个页面找到
我们可以点击这个test
测试成功
去添加媒介
配置动作
发送出去
第三方邮箱网页配置告警
配置邮箱以及媒介
配置触发动作
手动测试
[root@client ~]# echo "test jjyy" >> /tmp/jjyy
[root@client ~]#