1、安装postfix软件
[root@server ~]# yum -y install postfix
Last metadata expiration check: 18:30:18 ago on Sun 04 Sep 2022 04:11:22 PM CST.
Dependencies resolved.
===========================================================================================
Package Architecture Version Repository Size
===========================================================================================
Installing:
postfix x86_64 2:3.5.8-2.el8 base 1.5 M
Transaction Summary
===========================================================================================
Install 1 Package
Total download size: 1.5 M
Installed size: 4.3 M
Downloading Packages:
postfix-3.5.8-2.el8.x86_64.rpm 71 kB/s | 1.5 MB 00:22
-------------------------------------------------------------------------------------------
Total 71 kB/s | 1.5 MB 00:22
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: postfix-2:3.5.8-2.el8.x86_64 1/1
Installing : postfix-2:3.5.8-2.el8.x86_64 1/1
Running scriptlet: postfix-2:3.5.8-2.el8.x86_64 1/1
Verifying : postfix-2:3.5.8-2.el8.x86_64 1/1
Installed:
postfix-2:3.5.8-2.el8.x86_64
Complete!
2、修改postfix的主配置文件,并重启服务和设置下次启动生效
[root@server ~]# vim /etc/postfix/main.cf
在该行后面加上$mydomain
mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain
[root@server ~]# systemctl restart postfix.service
[root@server ~]# systemctl enable postfix.service
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
[root@server ~]#
3、安装mailx软件包
[root@server ~]# yum -y install mailx
Waiting for process with pid 4682 to finish.
Last metadata expiration check: 0:03:01 ago on Mon 05 Sep 2022 10:44:56 AM CST.
Dependencies resolved.
===========================================================================================
Package Architecture Version Repository Size
===========================================================================================
Installing:
mailx x86_64 12.5-29.el8 base 257 k
Transaction Summary
===========================================================================================
Install 1 Package
Total download size: 257 k
Installed size: 491 k
Downloading Packages:
mailx-12.5-29.el8.x86_64.rpm 161 kB/s | 257 kB 00:01
-------------------------------------------------------------------------------------------
Total 161 kB/s | 257 kB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : mailx-12.5-29.el8.x86_64 1/1
Running scriptlet: mailx-12.5-29.el8.x86_64 1/1
Verifying : mailx-12.5-29.el8.x86_64 1/1
Installed:
mailx-12.5-29.el8.x86_64
Complete!
进入163邮箱进行查看
配置动作
当连接数少于6个的时候,修复好了,163邮箱会再次收到修复成功的邮件
修改mailx配置文件
[root@server ~]# vim /etc/mail.rc
# Add mail-conf by zhan
set from=m13341394842@163.com
set smtp=smtp.163.com
set smtp-auth-user=m13341394842@163.com
set smtp-auth-password=GWVAZTXQPSOURCYB
set smtp-auth=login
set ssl-verify=ignore
[root@server ~]# chown -R zabbix.zabbix /etc/mail.rc
[root@server ~]#
编写脚本
[root@server ~]# vim /usr/lib/zabbix/alertscripts/mail-send.sh
[root@server ~]# cat /usr/lib/zabbix/alertscripts/mail-send.sh
#!/bin/bash
messages=`echo $3 | tr '\r\n' '\n'`
subject=`echo $2 | tr '\r\n' '\n'`
echo "${messages}" | mailx -s "${subject}" $1
[root@server ~]# chmod +x /usr/lib/zabbix/alertscripts/mail-send.sh
[root@server ~]# chown -R zabbix.zabbix /usr/lib/zabbix/alertscripts/mail-send.sh
测试
[root@server ~]# cd /usr/lib/zabbix/alertscripts/
[root@server alertscripts]# ./mail-send.sh m13341394842@163.com "zhan" "test"
创建报警媒介
配置用户
配置动作
测试
将agent端连接数上升至8进行测试
[root@agent ~]# who | wc -l
8
[root@agent ~]#
```![
\[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MALKLezg-1662379416575)(./1662377985182.png)\]](https://img-blog.csdnimg.cn/fc8d6ada87a9493bb8cd385943ff8291.png)
![\[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-RzupLJ6q-1662379416575)(./1662378076995.png)\]](https://img-blog.csdnimg.cn/5e218293124f4bc58d258ebd640ac472.png)