51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Zabbix4.0邮件报警设置(一)

当前系统环境centos7.x,邮件端口使用465

1、关闭默认25端口安装mailx(云上基本都封掉了25端口)
systemctl stop postfix yum install mailx

|-----|------------------------------------------| | 1 2 | systemctl stop postfix yum install mailx |

2、开启smtp

首先在邮箱设置中开启smtp,开启后会得到一个授权码,这个授权码就代替了密码。

并不是所有邮箱都是用授权码的,比如阿里邮箱企业版就是使用密码的。

3、请求数字证书(这里以qq邮箱为例)
mkdir -p /home/zabbix/.certs echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /home/zabbix/.certs/qq.crt

|-----|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 | mkdir -p /home/zabbix/.certs echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /home/zabbix/.certs/qq.crt |


depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA verify return:1 depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = GeoTrust RSA CA 2018 verify return:1 depth=0 C = CN, ST = Guangdong, L = Shenzhen, O = Tencent Technology (Shenzhen) Company Limited, OU = R&D, CN = pop.qq.com verify return:1 DONE

|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 | depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA verify return:1 depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = GeoTrust RSA CA 2018 verify return:1 depth=0 C = CN, ST = Guangdong, L = Shenzhen, O = Tencent Technology (Shenzhen) Company Limited, OU = R&D, CN = pop.qq.com verify return:1 DONE |


certutil -A -n "GeoTrust SSL CA" -t "C,," -d /home/zabbix/.certs -i /home/zabbix/.certs/qq.crt certutil -A -n "GeoTrust Global CA" -t "C,," -d /home/zabbix/.certs -i /home/zabbix/.certs/qq.crt cd /home/zabbix/.certs/ certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt

|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 | certutil -A -n "GeoTrust SSL CA" -t "C,," -d /home/zabbix/.certs -i /home/zabbix/.certs/qq.crt certutil -A -n "GeoTrust Global CA" -t "C,," -d /home/zabbix/.certs -i /home/zabbix/.certs/qq.crt cd /home/zabbix/.certs/ certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt |


Notice: Trust flag u is set automatically if the private key is present. certutil -L -d /home/zabbix/.certs Certificate Nickname Trust Attributes SSL,S/MIME,JAR/XPI GeoTrust SSL CA P,P,P

|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 | Notice: Trust flag u is set automatically if the private key is present. certutil -L -d /home/zabbix/.certs Certificate Nickname Trust Attributes SSL,S/MIME,JAR/XPI GeoTrust SSL CA P,P,P |


chown -R zabbix.zabbix /home/zabbix/

|---|--------------------------------------| | 1 | chown -R zabbix.zabbix /home/zabbix/ |

4、配置/etc/mail.rc
vi /etc/mail.rc

|---|-----------------| | 1 | vi /etc/mail.rc |


set from=xxx@qq.com #发送邮件的帐号即qq号 set smtp=smtps://smtp.qq.com:465 #邮件服务器 set smtp-auth-user=xxx@qq.com #发送邮件的帐号即qq号 set smtp-auth-password=xxxx #授权码 set smtp-auth=login #默认login即可 set ssl-verify=ignore #ssl认证方式 set nss-config-dir=/home/zabbix/.certs #证书所在目录

|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 | set from=xxx@qq.com #发送邮件的帐号即qq号 set smtp=smtps://smtp.qq.com:465 #邮件服务器 set smtp-auth-user=xxx@qq.com #发送邮件的帐号即qq号 set smtp-auth-password=xxxx #授权码 set smtp-auth=login #默认login即可 set ssl-verify=ignore #ssl认证方式 set nss-config-dir=/home/zabbix/.certs #证书所在目录 |

5、发送邮件测试
sudo -u zabbix echo "这是邮件正文" | mail -s "这是邮件主题" xxx@126.com

|---|--------------------------------------------------------------| | 1 | sudo -u zabbix echo "这是邮件正文" | mail -s "这是邮件主题" xxx@126.com |

测试zabbix用户是否可以正常发送邮件,zabbix用户不需要给/bin/bash权限,邮件测试是关键,一定要确定好测试邮件能否送达!!!

赞(0)
未经允许不得转载:工具盒子 » Zabbix4.0邮件报警设置(一)