zabbix action无法连接sendmail问题

sendmail介绍:
http://qingwang.blog.51cto.com/505009/909329
http://blog.csdn.net/imfinger/article/details/6407469
http://blog.chinaunix.net/uid-1900122-id-2797838.html
zabbix email 报警设置: http://bbs.linuxtone.org/thread-9401-1-1.html
上面的连接可以不看,直接看下面的
问题:
cannot connect to SMTP server [zabbix.server.com]: cannot connect to [[zabbix.server.com]:25]: [111] Connection refused
查看sendmail是否开启
[root@zabbix mail]# sudo service sendmail status
Redirecting to /bin/systemctl status  sendmail.service
● sendmail.service - Sendmail Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/sendmail.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2016-08-09 18:00:08 CST; 6min ago
  Process: 4665 ExecStart=/usr/sbin/sendmail -bd $SENDMAIL_OPTS $SENDMAIL_OPTARG (code=exited, status=0/SUCCESS)
  Process: 4653 ExecStartPre=/etc/mail/make aliases (code=exited, status=0/SUCCESS)
  Process: 4650 ExecStartPre=/etc/mail/make (code=exited, status=0/SUCCESS)
从上可以看出sendmail服务以开启
查看是否有防火墙:
[zabbix@zabbix server]$ sudo cat /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 10051 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
没有问题
查看端口:
[zabbix@zabbixServer server]$ netstat -ntlp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      -                  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -                  
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -                  
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      -                  
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      4184/./zabbix_serve
tcp6       0      0 :::3306                 :::*                    LISTEN      -                  
tcp6       0      0 :::80                   :::*                    LISTEN      -                  
tcp6       0      0 :::22                   :::*                    LISTEN      -                  
tcp6       0      0 ::1:631                 :::*                    LISTEN      -
我们可以看到sendmail只在127.0.0.1上监听,所以无法连上,修改/etc/mail/sendmail.cf
先备份sudo cp etc/mail/sendmail.cf etc/mail/sendmail_bak.cf
sudo vim etc/mail/sendmail.cf
# SMTP daemon options
#注释掉这行,重启服务即可
#O DaemonPortOptions=Port=smtp,Addr=127.0.0.1, Name=MTA

# SMTP client options
#O ClientPortOptions=Family=inet, Address=0.0.0.0

:wq
重启服务
sudo service sendmail restart
再次查看端口:

[root@zabbix mail]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2551/dnsmasq       
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1226/sshd          
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      3390/cupsd         
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      4691/sendmail: acce
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      4049/./zabbix_serve
tcp6       0      0 :::3306                 :::*                    LISTEN      2410/mysqld        
tcp6       0      0 :::80                   :::*                    LISTEN      4133/httpd         
tcp6       0      0 :::22                   :::*                    LISTEN      1226/sshd          
tcp6       0      0 ::1:631                 :::*                    LISTEN      3390/cupsd         
telnet 访问25端口
没有telnet,安装sudo yum install telnet
[root@zabbix mail]# telnet zabbix.server.com 25
Trying 192.168.126.128...
Connected to zabbix.server.com.
Escape character is '^]'.
220 zabbix.server.com ESMTP Sendmail 8.14.7/8.14.7; Tue, 9 Aug 2016 18:00:37 +0800
^Cquit
quit
Connection closed by foreign host.
-----------------------------------------
OK

猜你喜欢

转载自donald-draper.iteye.com/blog/2316453