1.4. Configuring replication between two Dovecot servers
With two-way replication, you can make your Dovecot server high-available, and IMAP and POP3 clients can access a mailbox on both servers. Dovecot keeps track of changes in the index logs of each mailbox and solves conflicts in a safe way.
Perform this procedure on both replication partners.
Replication works only between server pairs. Consequently, in a large cluster, you need multiple independent backend pairs.
Prerequisites
- Both servers use the same authentication backend. Preferably, use LDAP or SQL to maintain accounts centrally.
-
The Dovecot user database configuration supports user listing. Use the
doveadm user '*'command to verify this. -
Dovecot accesses mailboxes on the file system as the
vmailuser instead of the user’s ID (UID).
Procedure
Create the
/etc/dovecot/conf.d/10-replication.conffile and perform the following steps in it:Enable the
notifyandreplicationplugins:mail_plugins = $mail_plugins notify replicationAdd a
service replicatorsection:service replicator { process_min_avail = 1 unix_listener replicator-doveadm { mode = 0600 user = vmail } }With these settings, Dovecot starts at least one replicator process when the
dovecotservice starts. Additionally, this section defines the settings on thereplicator-doveadmsocket.Add a
service aggregatorsection to configure thereplication-notify-fifopipe andreplication-notifysocket:service aggregator { fifo_listener replication-notify-fifo { user = vmail } unix_listener replication-notify { user = vmail } }Add a
service doveadmsection to define the port of the replication service:service doveadm { inet_listener { port = 12345 } }Set the password of the
doveadmreplication service:doveadm_password = <replication_password>The password must be the same on both servers.
Configure the replication partner:
plugin { mail_replica = tcp:server2.example.com:12345 }Optional: Define the maximum number of parallel
dsyncprocesses:replication_max_conns = 20The default value of
replication_max_connsis10.
Set secure permissions on the
/etc/dovecot/conf.d/10-replication.conffile:# chown root:root /etc/dovecot/conf.d/10-replication.conf # chmod 600 /etc/dovecot/conf.d/10-replication.confEnable the
nis_enabledSELinux Boolean to allow Dovecot to open thedoveadmreplication port:# setsebool -P nis_enabled onConfigure
firewalldrules to allow only the replication partner to access the replication port, for example:# firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="192.0.2.1/32" port protocol="tcp" port="12345" accept" # firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv6" source address="2001:db8:2::1/128" port protocol="tcp" port="12345" accept" # firewall-cmd --reloadThe subnet masks
/32for the IPv4 and/128for the IPv6 address limit the access to the specified addresses.- Perform this procedure also on the other replication partner.
Reload Dovecot:
# systemctl reload dovecot
Verification
- Perform an action in a mailbox on one server and then verify if Dovecot has replicated the change to the other server.
Display the replicator status:
# doveadm replicator status Queued 'sync' requests 0 Queued 'high' requests 0 Queued 'low' requests 0 Queued 'failed' requests 0 Queued 'full resync' requests 30 Waiting 'failed' requests 0 Total number of known users 75Display the replicator status of a specific user:
# doveadm replicator status <user_name> username priority fast sync full sync success sync failed <user_user> none 02:05:28 04:19:07 02:05:28 -