HAProxy is a absolutely price less open source high availability and load balancing solution for application layer protocols such as HTTP, SMTP, MYSQL etc…. HAProxy provides fast, reliable,
stable high availability and load balacing solution for small, medium and enterprises organizations. It is very useful for high volume traffic applications. Haproxy is available in both form open source edition and enterprises edition. It’s widely used in IT world to improve performance, stability, reliability in server and multiple application environment. Haproxy generally reduce the over load from single host by distributing across multiple nodes
In previous post we have setup apache load balancing so this post we are going to setup postfix mail server with high availability load balancing for outbound mails using HaProxy load-balancer.
How to setup postfix with multiple instances.
How to configure mx-gateway (mail gateway) on postfix
Here we are using the following scanario for Postfix load balancing and High Availability with HaProxy.
HaProxy Load-Balancer :: 192.173.123.1
Postfix Host 1 :: 192.173.123.2
Postfix Host 2 :: 192.173.123.3
Postfix Host 3 :: 192.173.123.4
Haproxy Load-Balancer
To install haproxy load-balancer execute the following command from root user on linux command prompt.
Resolving Dependencies
–> Running transaction check
—> Package haproxy.x86_64 0:1.5.2-2.el6 will be installed
–> Finished Dependency Resolution
Dependencies Resolved======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Installing:
haproxy x86_64 1.5.2-2.el6 base 790 k
Transaction Summary
======================================================================================================================================
Install 1 Package(s)
Total download size: 790 k
Installed size: 2.4 M
Is this ok [y/N]: y
Downloading Packages:
haproxy-1.5.2-2.el6.x86_64.rpm | 790 kB 00:00
Installed:
haproxy.x86_64 0:1.5.2-2.el6
Complete!
Once installation process get completed open the haproxy configuration /etc/haproxy/haproxy.cfg file and appent the following lines.
frontend ft_smtp
bind 192.173.123.1:25
mode tcp
no option http-server-close
timeout client 1m
log global
option tcplog
maxconn 3000
default_backend bk_postfix
backend bk_postfix
mode tcp
no option http-server-close
log global
option tcplog
timeout server 1m
timeout connect 30s
balance roundrobin
server postfix-host1 192.173.123.2:10025 check
server postfix-host2 192.173.123.3:10026 check
server postfix-host3 192.173.123.4:10027 check
After that start haproxy service by using following command.
If haproxy gets start without any issue that means haproxy setup and installation finish.
Postfix Installation.
To install postfix on host 1 use the following command from root user, Same steps of postfix installation and configuration will applicable on all hosts.
[root@linuxpcfix[~]# yum install postfix.
After that open the posfix master configuration file and modify as given below.
10025 inet n – n – 1 postscreen
smtpd pass – – n – – smtpd
#smtp pass n – n – – smtpd
#smtp inet n – n – 1 postscreen
ON host 2
smtpd pass – – n – – smtpd
#smtp pass n – n – – smtpd
#smtp inet n – n – 1 postscreen
On Host 3
smtpd pass – – n – – smtpd
#smtp pass n – n – – smtpd
#smtp inet n – n – 1 postscreen
Then open the main configuration and modify the inet_interfaces as given below.
Finally restart postfix server.
Now verify the everything working or not using telnet command from your own system.
Trying 192.173.123.1..
Connected to 192.173.123.1.
Escape character is ‘^]’.
220 host1.linuxpcfix.com ESMTP Postfix
[root@linuxpcfix[~]# telnet 192.173.123.1 25
Trying 192.173.123.1..
Connected to 192.173.123.1.
Escape character is ‘^]’.
220 host2.linuxpcfix.com ESMTP Postfix
[root@linuxpcfix[~]# telnet 192.173.123.1 25
Trying 192.173.123.1..
Connected to 192.173.123.1.
Escape character is ‘^]’.
220 host3.linuxpcfix.com ESMTP Postfix
If you are able to see different output (host1.linuxpcfix.com, host2.linuxpcfix.com etc…) each time while performing the telnet command from your system that’s mean haproxy load-balancer properly configured and ready to production use.
getting error [ALERT] 214/125221 (25262) : Starting frontend ft_smtp: cannot bind socket while starting the HAproxy.
getting error
Trying 192.173.123.1…
telnet: Unable to connect to remote host: Connection refused
when restarting the HAproxy
Once Check your Config file
Thanks
Working perfectly ….
great work.
only change i have to do in haproxy config is to comment line
# no option http-server-close
Thanks!
but…
how to do this for pop3/imap in order to download the mails from the server/s ?
You can use IMAPSYNC migration tool for download mails from one server to another server.