【问题标题】:SMTP alert not working for keepalivedSMTP 警报不适用于 keepalived
【发布时间】:2011-09-22 06:34:30
【问题描述】:

我一直在从事一个项目,该项目将建立一组高度可用的负载平衡器。负载平衡和高可用性软件似乎工作得很好(我使用 Crossroads 进行负载平衡,并使用 Keepalived 使负载平衡服务器具有高可用性,并使用 Conntrackd 对负载平衡器进行健康检查)但我在设置配置时遇到问题状态转换发生时 Keepalived 发送电子邮件的文件(master->backup/backup->master)。我已按照手册页 (man keepalived.conf) 上的说明告诉我如何设置电子邮件通知,但我未能在预期时间收到电子邮件。我很容易出现拼写检查和简单的错误,但是在查看了这个问题近 10 个小时之后,我似乎找不到任何东西,而且我已经没有东西可以尝试了。

我正在使用的其中一个服务器(我将其命名为 loadbalance1)有时会在发生更改时使用 smtp_alert 发送电子邮件,但它只会在它从备份转换到主服务器(而不是主服务器到备份)时通知我)。当它不起作用时,日志文件(/var/log/messages 和 /var/log/syslog)会通知我出现 SMTP 错误状态 550。我理解这些问题与配置文件中指定的错误电子邮件地址有关,但据我所知,它们是正确的。我唯一认为keepalived或我的配置文件有误的事情是系统管理员通过电子邮件向人们发送有关“{”是不正确的邮件收件人的消息。我在计算机上打开了 smtp 端口。发生的另一件奇怪的事情是,当keepalived 尝试联系邮件服务器时,它想在本地机器不存在时查看它。我将邮件服务器指定为在其他地方,但出于某种原因它想在本地查看。

另一台服务器 loadbalance2 永远不会发送 smtp_alert 来发送电子邮件,无论它进行什么状态转换。我可以在 keepalived 的日志文件(/var/log/messages 和 /var/log/syslog)中看到备份服务器 loadbalance2 确实转换到 MASTER 状态,但它从不发送电子邮件。它给出了与 loadbalance1 相同的错误,但它永远不会在这里工作。它与 loadbalance1 具有相同的配置文件。

下面是配置文件keepalived.conf

    global_defs 
    {
        notification_email 
        {
    fakeemail@example.com
        }
       notification_email_from sysamin@example.com
        ##Mail server below##
       smtp_server www.xxx.yyy.zzz
       smtp_connect_timeout 30
       lvs_id NLB_MASTER
    vrrp_sync_group
    {
        group
        {
            loadbalance1
            loadbalance2
        }
        ##The following scripts don't seem to work properly either##
        ##The scripts are not executed at expected times        ##
        notify_master "/path/to/script.sh master"
        notify_backup "/path/to/script.sh backup"
        notify_fault  "/path/to/script.sh fault"
        notify  "/path/to/script.sh"
        smtp_alert
    }
    vrrp_instance loadbalance1
    {
        state MASTER
        interface eth0
        virtual_router_id 20
        priority 100
        #In some examples online smtp_alert is here
        virtual_ipaddress
        {
            www.xxx.yyy.zzz/24 brd www.xxx.yyy.255 dev eth0
        }
        ##Not entirely sure if this is correct##
        notify_master "/path/to/script.sh master"
        notify_backup "/path/to/script.sh backup"
        notify_fault  "/path/to/script.sh fault"
        notify  "/path/to/script.sh"
        smtp_alert
    }
    vrrp_instance loadbalance2
    {
        state MASTER
        interface eth0
        virtual_router_id 30
        priority 100
        #In some examples online smpt_alert is here
        virtual_ipaddress
        {
            www.xxx.yyy.zzz/24 brd www.xxx.yyy.255 dev eth1
        }
        ##Not entirely sure if this is correct##
        notify_master "/path/to/script.sh master"
        notify_backup "/path/to/script.sh backup"
        notify_fault  "/path/to/script.sh fault"
        notify  "/path/to/script.sh"
        smtp_alert
      }

如果配置文件中存在一些不一致之处,我深表歉意。任何建议,帮助或意见表示赞赏。如果您需要更多信息,我很乐意提供帮助。

【问题讨论】:

  • 电子邮件发送与不发送的任何模式?

标签: linux smtp load-balancing keep-alive


【解决方案1】:

我能够解决我在 keepalived.log 中看到的类似问题:

SMTP connection ERROR to [0.0.0.0]:25

我的 keepalived.conf 的样子:

global_defs {
  notification_email {
    ....
  }
  notification_email_from somplace@somewhere.com
  smtp_server smtp.somehwere.com
  smtp_connect_timeout 30
  ...
}

我更新了我的 smtp 配置以使用 IP 地址而不是我的 smtp 服务器的主机名:

smtp_server xxx.xxx.xxx.xxx

重新启动keepalived后产生新的输出和成功的电子邮件通知:

Remote SMTP server [xxx.xxx.xxx.xxx]:25 connected.

【讨论】:

    【解决方案2】:

    对于那些可能面临同样问题的人,我设法解决了问题。我不确定这是否是解决方案,但它可能有所贡献。

    -我不得不将机器的日期和时间更改为当前时间(其中一台机器由于是克隆而关闭了几年)。电子邮件服务器可能因为系统时间的差距而阻止了后端服务器的电子邮件?

    -日期-s hh:mm:ss

    -日期-s年月日

    -必须解决两台机器上的主机名相同的问题。正如我所说,它是另一个的克隆,我从来没有意外改变它。我可能一直收到来自后端服务器的通知,但从未区分这两者,因为我收到来自相同主机名的电子邮件

    -对配置文件做了一个应该可以忽略不计的小改动

        global_defs
        {
              notification_email {
                  user@domain.com
              }
        }
    

    不确定这是否有所作为,但哦,好吧……现在可以了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-14
      • 2022-01-16
      • 1970-01-01
      相关资源
      最近更新 更多