如何使用HAProxy配置PostFix集群?

Load balancing

1 基础知识

1.1 软件的介绍

– HAProxy是一款开源免费、快速、可靠的解决方案
– HAProxy是基于TCP和HTTP协议提供高可用、负载均衡和代理服务

1.2 软件的功能

– 负载均衡
– 高可用
– 代理服务

2 最佳实践

2.1 准备安装环境

2.1.1 系统的基本配置

负载均衡器,
HostName = haproxy01.cmdschool.org
OS = Oracle Linux 9.x x86_64
IPAddress = 192.168.0.98

多节点邮件投递代理,
HostName = postfix0[1-2].cmdschool.org
OS = Oracle Linux 9.x x86_64
IPAddress = 192.168.0.8[8-9]

邮件客户端,
HostName = postfixclient.cmdschool.org
OS = Oracle Linux 9.x x86_64
IP Addr = any
DNS = any

2.1.2 准备HAProxy负载均衡器环境

如何安装部署HAProxy?


由于非本章重点,前端的HAProxy高可用和负载均衡个人建议使用任播(基于三层动态路由技术)实现。

如何部署任播负载均衡ospf动态路由节点?

2.1.3 准备PostFix邮件传输代理环境

如何设置Postfix直出因特网中继?

2.2 配置HAProxy负载均衡器前端

In haproxy01,

2.2.1 修改代理配置

vim /etc/haproxy/conf.d/postfix.cfg

修改如下配置,

frontend ft_smtp
    bind 0.0.0.0:25
    mode tcp
    timeout client 1m
    log global
    default_backend bk_postfix
backend bk_postfix
    mode tcp
    log global
    timeout server 1m
    timeout connect 5s
    #server postfix01 192.168.0.88:25 send-proxy check
    #server postfix02 192.168.0.89:25 send-proxy check
    server postfix01 192.168.0.88:25 send-proxy
    server postfix02 192.168.0.89:25 send-proxy

然后,你需要使用如下命令测试配置恩建,

haproxy -c -f /etc/haproxy/haproxy.cfg

2.2.2 重载服务使配置生效

systemctl reload haproxy

2.2.3 开放应用所需的服务端口

firewall-cmd --permanent --add-service smtp
firewall-cmd --reload
firewall-cmd --list-all

2.3 配置PostFix邮件投递代理后端

In postfix0[1-2],

2.3.1 修改代理配置

vim /etc/postfix/main.cf

加入如下配置,

smtpd_upstream_proxy_protocol = haproxy
proxy_interfaces = 192.168.0.98

2.3.2 重载服务使配置生效

systemctl reload postfix

2.4 使用PostFix客户端测试

In postfixclient,

2.4.1 修改代理配置

vim /etc/postfix/main.cf

修改中继客户端的地址为HAProxy负载均衡器地址,

relayhost = 192.168.0.98

2.4.2 重载服务使配置生效

systemctl reload postfix

2.4.3 测试邮件发送

echo "test" | s-nail -s "test" -r seradmin@cmeschool.org will@cmeschool.org

参阅文档
===================

参考配置文档
————–
http://www.postfix.org/BASIC_CONFIGURATION_README.html
http://www.postfix.org/STANDARD_CONFIGURATION_README.html
https://www.postfix.org/postconf.5.html

集群的话题
————-
https://groups.google.com/g/mailing.postfix.users/c/n4W0i5t6mVk
https://linux-cluster.redhat.narkive.com/rmKOhgkv/postfix-active-active-mail-cluster

负载均衡的实现
—————
https://discourse.haproxy.org/t/how-to-send-email-via-haproxy/3952/2
https://www.haproxy.com/blog/efficient-smtp-relay-infrastructure-with-postfix-and-load-balancers

没有评论

发表回复

Load balancing
如何用HAProxy代理sftp?

1 前言 一个问题,一篇文章,一出故事。 笔者今天需要实现HAProxy代理sftp,因此整理此文。 …

Load balancing
如何熟悉Avi Vantage Platform?

1 基本概念 1.1 ServiceMesh 1.1.1 众多微服务产生的问题 – 服务 …

Load balancing
如何在RHEL8部署MariaDB Galera集群?

1 基础知识 1.1 技术简介 – MariaDB Galera集群是一个同步多主集群 …