这里是普通文章模块栏目内容页
nagios高级配置之sendmail发送邮件
我配置sendmail成功的过程以及需要的linux命令和知识:

 1、检查commands.cfg
# 'notify-host-by-email' command definition
define command{
command_name    notify-host-by-email
command_line    /usr/bin/printf "%b" "***** Nagios *****nnNotification
 Type: $NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress: $HOSTA
DDRESS$nInfo: $HOSTOUTPUT$nnDate/Time: $LONGDATETIME$n" | /bin/mail -s "** $
NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }
# 'notify-service-by-email' command definition
define command{
command_name    notify-service-by-email
command_line    /usr/bin/printf "%b" "***** Nagios *****nnNotification
 Type: $NOTIFICATIONTYPE$nnService: $SERVICEDESC$nHost: $HOSTALIAS$nAddress:
 $HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditional
 Info:nn$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert:
$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
这是正确的命令配置,其中最重要的就是/bin/mail后边的命令配置

2、mqueue
[root@localhost mqueue]# pwd
/var/spool/mqueue
[root@localhost mqueue]# ll
total 8
-rw------- 1 root smmsp   8 Nov 18 20:54 dfmAICsFQj009878
-rw------- 1 root smmsp 901 Nov 18 21:56 qfmAICsFQj009878
[root@localhost mqueue]#
这个目录存储的是邮件发送队列,如果这个里边满了不但会影响程序的运行,而且sendmail容易死掉,所以必要的时候要删除。

3、修改access
[root@localhost mail]# pwd
/etc/mail
[root@localhost mail]# vi access
# Check the /usr/share/doc/sendmail/README.cf file for a description
# of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc
# package.
#
# by default we allow relaying from localhost...
Connect:localhost.localdomain           RELAY
Connect:localhost                       RELAY
Connect:127.0.0.1                       RELAY
Connect:192.168.0                       RELAY
Connect:http://www.163.com              RELAY
Connect:1.1.1                           RELAY
Connect:nagios@localhost.localdomain    RELAY
Connect:root@localhost                   RELAY 然后执行makemap hash access < access
或者是makemap -v hash /etc/mail/access.db < /etc/mail/access

4、[root@localhost spool]# pwd
/var/spool
chmod 777 mqueue
我的邮箱是163.com。

5、. 检查所传送的电子邮件是否送出,或滞留在邮件服务器中
语法:/usr/lib/sendmail -bp
若屏幕显示为“Mail queue is empty” 的信息,表示mail 已送出。

6检查邮件发送过程
在Sendmail邮件服务器上执行下面的命令.
# echo testing | /usr/sbin/sendmail -v someone@somedomain.com

7、sendmail日志
[root@localhost log]# pwd
/var/log
vi maillog就可以看了,出现任何错误都可以看到。