# [EXIM/DOVECOT] Redundant mail servers

## Belliash

Hello,

I am facing a conceptional problem with a redundant mail servers setup.

The idea is to setup 2 mail servers in 2 different locations, each having Exim for SMTP and Dovecot for IMAP installed.

What i would like to achieve, is to eliminate a single point of failure. The goal here is not to get a consistency guarantee that any accepted e-mail will be available even if a server goes down, as there is still a chance that some e-mails will be lost until the server that received it comes back online. Instead, I would like to have guaranteed the following properties in case one of mail servers would go down:

1) New e-mails can be delivered via SMTP and then accessed by users via IMAP

2) New mails can be sent

What is more, when 2 servers will be reachable, all mails should be available to all users, whether they have been received by 1st of 2nd server.

Actually I thought about using the following technologies:

1) 2 MX sections in DNS with 1 and 10 priorities, so that 1st SMTP server would be used by default and 2nd one only when 1st goes down

2) Dovecot providing IMAP access installed on both machines and receiving mails only from local Exim

3) Users would be able to connect to both IMAP servers via round-robin in DNS

4) Dovecots should synchronize each other, otherwise consistences might occur (master/master replication?)

However, I am not sure if above problem cannot be solved in more elegant way.

I think the biggest problem here is that both servers will be running in different locations and they would connect to each-other only over the Internet or VPN. Using some clustered FS like GlusterFS would be rather a pain in this scenario.

Also I am not sure how to implement user management. Actually I got 1 mail server with backed in MySQL. Having 2 such server would mean, that I need to add or remove user on both of them.

Do you know about an already working solution in similar scenario?

----------

## C5ace

Have a look at ispconfig.org for inspiration. They support Mirrored Clusters. No support for Gentoo unless you add symlinks to Gentoo to emulate Debian or Ubunto.

----------

## Belliash

Well... I think that IMAP can be even configured as a singleton.

Anyway, I would need 2 SMTP servers up and running. Another scenario guarantees that:

1) 1st SMTP server would be configured with all its users, rules, clamav, spamassassin etc and would be storing all mails in maildir.

2) 2nd SMTP server would need to receive all mails and pass them to 1st one.

3) If first SMTP server goes down, 2nd one should retry mail delivering once per hour, until it reaches destination.

4) If 1st SMTP server rejects mail, eg due to virus attached, such information should be sent to 2nd SMTP server and it should send some notification to original sender.

5) 2nd SMTP server should not allow to send any mails (it would be used only as a kind of fail-over proxy for 1st one).

----------

## Syl20

I think you need a High-Availability solution, like corosync/pacemaker/pcs, to set up a "real" cluster. Some documentation here.

Bidirectional synchronization is a pain, but there are several ways to do. Like DRDB, for example. And two crossed master/slave replications for MySQL, or Galera for MariaDB.

----------

## Belliash

I think the main problem is location. One server is located in France, while second in Poland  :Wink: 

Both has symmetrical 100mbps connection, but still cluster over the net is a pain.

----------

## Syl20

Argl ! Indeed. I missed this.

That said, if you plan to keep the MySQL backend, the bidirectional replication is still a good solution.

If the mail boxes are in maildir format, perhaps unison is an interesting option. I also found this, but I never tested it.

----------

