企业级监控软件Zabbix搭建部署之使用mutt+msmtp配置Zabbix邮件报警
[root@Zabbix-Server ~]# wget
[root@Zabbix-Server ~]# tar xf msmtp-1.4.17.tar.bz2
[root@Zabbix-Server ~]# cd msmtp-1.4.17
[root@Zabbix-Server msmtp-1.4.17]# mkdir /usr/local/msmtp
[root@Zabbix-Server msmtp-1.4.17]# yum -y install gnutls-devel gnutls
[root@Zabbix-Server msmtp-1.4.17]# ./configure --prefix=/usr/local/msmtp
[root@Zabbix-Server msmtp-1.4.17]# make
[root@Zabbix-Server msmtp-1.4.17]# make install
[root@Zabbix-Server msmtp-1.4.17]# cd /usr/local/msmtp/
[root@Zabbix-Server msmtp]# ls
bin share
[root@Zabbix-Server msmtp]# mkdir etc 创建目录
[root@Zabbix-Server msmtp]# cd etc/
[root@Zabbix-Server etc]# ls
[root@Zabbix-Server etc]# vim msmtprc 创建配置文件
配置文件如下:
account default
host smtp.ym.163.com #发送邮件服务器
port 25 #发送端口
from noreply@youlongteng.com #发送的邮箱
auth login
tls off #这里如果使用on的话会报 "msmtp: cannot use a secure authenti cation method"错误
user noreply@youlongteng.com #邮箱用户
password 123.com. #邮箱的密码,明文保存的需要注意,可以设置权限
logfile /var/log/mmlog #日志的路径
[root@Zabbix-Server etc]# ll /usr/local/msmtp/etc/msmtprc
-rwxr-xr-x 1 zabbix root 195 Oct 11 23:52 /usr/local/msmtp/etc/msmtprc
[root@Zabbix-Server etc]#
保存
测试
[root@Zabbix-Server etc]# /usr/local/msmtp/bin/msmtp xxoo@xxxx.com
This is my mail
[root@Zabbix-Server etc]#
ctrl+d写完就可以退出,然后服务器查看是否收到
[root@Zabbix-Server log]# cat mmlog
Dec 31 10:10:12 host=smtp.ym.163.com tls=off auth=on user=xxoo@xxxx.com from=xxoo@xxxx.com recipients=xxoo@xxxx.com mailsize=406 smtpstatus=250 smtpmsg='250 2.0.0 Ok: queued as EDBC41101988' exitcode=EX_OK
Dec 31 10:10:12 host=smtp.ym.163.com tls=off auth=on user=xxoo@xxxx.com from=xxoo@xxxx.com recipients=xxoo@xxxx.com mailsize=397 smtpstatus=250 smtpmsg='250 2.0.0 Ok: queued as 1E8911101684' exitcode=EX_OK
Dec 31 10:10:12 host=smtp.ym.163.com tls=off auth=on user=xxoo@xxxx.com from=xxoo@xxxx.com recipients=sxxoo@xxxx.com mailsize=396 smtpstatus=250 smtpmsg='250 2.0.0 Ok: queued as 7801E11011F0' exitcode=EX_OK
[root@Zabbix-Server log]#
安装mutt
[root@Zabbix-Server etc]# yum -y install mutt
修改配置文件
vim /etc/Muttrc.local
# Local configuration for Mutt.
set sendmail="/usr/local/msmtp/bin/msmtp"
set use_from=yes
set realname="xxoo@xxxx.com" 你的发送邮箱地址
set editor="vim"
[root@Zabbix-Server log]# ll /etc/Muttrc.local
-rw-r--r-- 1 root root 151 Oct 10 18:28 /etc/Muttrc.local
[root@Zabbix-Server log]#
测试安装是否成功
错误提示:如下图是提示添加附件错误。。。。。。
[root@Zabbix-Server msmtp]# echo "testmail" | mutt -s "test" -a /tmp/file xxoo@xxxx.com
Can't stat zhangkeyuan@youlongteng.com: No such file or directory
zhangkeyuan@youlongteng.com: unable to attach file.
正确方法如下:
[root@Zabbix-Server msmtp]# echo "This is a test mail " >> /tmp/file
需要注意的是,在CentOS6下面,我们需要按照如下的方法去下,添加附件应该放置到最后面,这样才能成功,如果-a放到邮件地址前面会报错
如果有多个邮件地址,就写多个即可
[root@Zabbix-Server msmtp]# echo "testmail" | mutt -s "test" xxoo@xxxx.com -a /tmp/file
[root@Zabbix-Server msmtp]# echo "testmail" | mutt -s "test" xxoo@xxxx.com 431054426@qq.com -a /tmp/file
这样就测试成功查看日志记录
[root@Zabbix-Server msmtp]# tail /var/log/mmlog -n 2
Oct 05 16:40:03 host=smtp.ym.163.com tls=off auth=on user=xxoo@xxxx.com from=xxoo@xxxx.com recipients=xxoo@xxxx.com mailsize=598 smtpstatus=250 smtpmsg='250 2.0.0 Ok: queued as AB0F11480DCF' exitcode=EX_OK
Oct 05 16:51:30 host=smtp.ym.163.com tls=off auth=on user=xxoo@xxxx.com from=xxoo@xxxx.com recipients=xxoo@xxxx.com mailsize=734 smtpstatus=250 smtpmsg='250 2.0.0 Ok: queued as 29FC51481F38' exitcode=EX_OK
[root@Zabbix-Server msmtp]#
企业级监控软件Zabbix搭建部署之使用mutt+msmtp配置
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/e11a694d304a994e30e8d1eb20f4d4a2.html