HowtoForge

Installing a Web, Email & MySQL Database Cluster on Debian 8.4 Jessie with ISPConfig 3.1 - Page 5

8 Sync Emails with Dovecot

Since Dovecot 2 it`s possible to use Dovect's dsync to keep the main base in sync. If you have already mail's on server1, they will be replicated to server2 without any further interaction.

You must use the same port (4711) and the same password (replication_password) on both servers.

server1:

Open /etc/dovecot/dovecot-sql.conf

vi /etc/dovecot/dovecot-sql.conf

and enable the iterate_query:

old:

#iterate_query = SELECT email as user FROM mail_user

new:

iterate_query = SELECT email as user FROM mail_user

Open /etc/dovecot/dovecot.conf

vi /etc/dovecot/dovecot.conf

and add the following content:

# Enable the replication plugin globally
mail_plugins = $mail_plugins notify replication quota

# Both the client and the server need to have a shared secret
doveadm_password = replication_password

# configure how many dsyncs can be run in parallel (10 by default)
replication_max_conns = 10

service aggregator {
        fifo_listener replication-notify-fifo {
                user = vmail
                mode = 0666
        }

        unix_listener replication-notify {
                user = vmail
                mode = 0666
        }
}

service replicator {
        unix_listener replicator-doveadm {
                mode = 0666
        }
}

service doveadm {
        user = vmail
        inet_listener {
                port = 4711
        }
}

service config {
        unix_listener config {
                user = vmail
        }
}

# use tcp:ip as the dsync target
plugin {
        replication_full_sync_interval = 1 hours
        mail_replica = tcp:192.168.0.106:4711
}

protocol imap {
mail_plugins = quota imap_quota notify replication
}

restart Dovecot:

service dovecot restart

server2:

Open /etc/dovecot/dovecot-sql.conf

vi /etc/dovecot/dovecot-sql.conf

and enable the iterate_query:

old:

#iterate_query = SELECT email as user FROM mail_user

new:

iterate_query = SELECT email as user FROM mail_user

Open /etc/dovecot/dovecot.conf

vi /etc/dovecot/dovecot.conf

and add the following content:

# Enable the replication plugin globally
mail_plugins = $mail_plugins notify replication quota

# Both the client and the server need to have a shared secret
doveadm_password = replication_password

# configure how many dsyncs can be run in parallel (10 by default)
replication_max_conns = 10

service aggregator {
        fifo_listener replication-notify-fifo {
                user = vmail
                mode = 0666
        }

        unix_listener replication-notify {
                user = vmail
                mode = 0666
        }
}

service replicator {
        unix_listener replicator-doveadm {
                mode = 0666
        }
}

service doveadm {
        user = vmail
        inet_listener {
                port = 4711
        }
}

service config {
        unix_listener config {
                user = vmail
        }
}

# use tcp:ip as the dsync target
plugin {
        replication_full_sync_interval = 1 hours
        mail_replica = tcp:192.168.0.105:4711
}

protocol imap {
mail_plugins = quota imap_quota notify replication
}

restart Dovecot:

service dovecot restart

You can check the replication on each server:

doveadm replicator status '*'
username                                                                                priority fast sync full sync failed
user@example.tld                                                                     none     00:16:34  00:16:40  -

9 Additional Notes

When you want to activate a firewall on the master or slave server, ensure that you open port 3306 for MySQL, 22 for SSH and 4711 for Dovecot on both servers.

Installing a Web, Email & MySQL Database Cluster on Debian 8.4 Jessie with ISPConfig 3.1 - Page 5