Replacing Courier IMAP with Dovecot IMAP
From Qmailtoaster
If your QMT is running Courier IMAP and you're experiencing poor IMAP performance with large mailboxes, this is your solution. Dovecot runs efficiently on relatively low powered hosts, with accounts having in excess of 10G of mail.
Thanks go to Phil and Scott for contributing to the first wiki content regarding dovecot. Their work helped to lay the foundation for getting dovecot integrated into QMT. Since then, this process has become much simpler.
Dovecot is scheduled to be included as the 'stock' IMAP software in QMTv1.5. The following procedure is for using dovecot on a QMTv1.3.x host.
WARNING: This is not a minor adjustment. This is a procedure to replace Courier IMAP and qmail-pop3d with Dovecot. There is a possibility of mistakes leading to data corruption or more commonly, your users having to re-download all stored mail. In any case, you should test this on a non-production installation matching your production server before doing this in production.
Now that the scary part is over, the part where most problems will occur is in the Mailbox Conversion step. If that is not done correctly, it can cause your users to have to re-download their mail. The rest is relatively straight forward and safe.
Contents |
Install
RPMS are available for CentOS 5 i386 and x86_64 in the QmailToaster-Plus (QTP) repository. If your QMT is running an available distro/version/arch and you have qmailtoaster-plus.repo installed, you can use yum to install dovecot:
# rpm -Uvh http://qtp.qmailtoaster.com/trac/downloads/1 # yum --enablerepo=qtp-CentOS install dovecot
If your QMT is running on a different distro/version, you'll need to download the source rpm, then build and install the binary rpm for your distro/version, e.g:
# cd /my/rpmbuild/SRPMS # wget http://qtp.qmailtoaster.com/repos/SRPMS/dovecot-2.0.11-2.qtp.src.rpm # rpmbuild --rebuild dovecot-*.src.rpm # rpm -ivh ../RPMS/*86*/dovecot-*.rpm
That might not work exactly, but you get the idea.
Configure
The configuration files included in the rpm should work as is. There is an /etc/dovecot/toaster.conf file which contains settings particular to QMT. This file should not typically be changed much.
You may want to do things for your environment such as creating shared folders. Any changes you need to make should be added to the /etc/dovecot/local.conf file, which is also included, but not required.
The /etc/dovecot/dovecot.conf file is the main configuration file. It simply contains include directives for these 2 files. It is probably best not to modify this file directly.
There is also an /etc/dovecot/conf.d/ directory which contains examples of many dovecot configuration parameters. Be aware that these configuration files are not active, so don't make configuration changes there. Modify your local.conf file instead to make changes effective.
Stop Courier, qmail Services
First we need to stop Courier IMAP:
# cd /var/qmail/supervise # touch imap4/down imap4/log/down # touch imap4-ssl/down imap4-ssl/log/down # service qmail stop
Convert the mailboxes
This is the part you really should test. The success or failure of this part will determine how transparent your migration is to your users. You'll not likely loose any mail (you have backups, right??), but your users might end up having to re-subscribe to folders and/or re-download email headers, depending on the client software they use.
First we’ll get the conversion script:
# cd /usr/local/sbin # wget http://www.dovecot.org/tools/courier-dovecot-migrate.pl ... # chmod 0700 courier-dovecot-migrate.pl # cd ~vpopmail/domains
This command will do a "dry run" to make sure things will work correctly...
# /usr/local/sbin/courier-dovecot-migrate.pl --recursive
You should see your user accounts scroll by and say something like “UIDLIST not found” but nothing else. At the end of the script you should have 0 ERRORS.
This command actually does the conversion.
# /usr/local/sbin/courier-dovecot-migrate.pl --recursive --convert
If everything went well, you can proceed. If not, you might want to post a message to the qmail-toaster list to get some help.
Start Dovecot, qmail Services
Now we can start dovecot and qmail:
# service qmail start # chkconfig dovecot on # service dovecot start
Testing
# tail /var/log/dovecot.log
should show that dovecot has started, with no errors.
You should telnet to the server on ports 143 and 993 to test the connections.
SquirrelMail Configuration
Squirrelmail needs some adjustments in order to work best with dovecot. This /etc/squirrelmail/config_local.php file should work for you:
<?php #################### # Local configuration for Qmail Toaster # configure to suit your requirements # these are in toaster config, # changed/removed for stock dovecot (w/out courier compat config) # $imap_server_type = 'courier'; # $optional_delimiter = '.'; # $default_folder_prefix = 'INBOX.'; # $delete_folder = true; # $show_contain_subfolders_option = false; # these should be added to the toaster config (imho) $org_name = "QmailToaster"; # $org_logo = SM_PATH . 'images/sm_logo.png'; # $org_logo_width = '308'; # $org_logo_height = '111'; # $org_title = "SquirrelMail $version"; $provider_uri = 'http://www.qmailtoaster.org/'; $provider_name = 'QmailToaster'; # these were added so SM authenticates, # eliminating need for 127.: line in /etc/tcprules.d/tcp.smtp file $smtpServerAddress = 'localhost'; $smtpPort = 587; $smtp_auth_mech = 'login'; # these were added/changed for dovecot imap $imapServerAddress = 'localhost'; $imap_server_type = 'dovecot'; # squirrelmail doesn't support starttls until v1.5.1, so we'll use digest-md5 #$use_imap_tls = true; $imap_auth_mech = 'digest-md5'; # these are what's left from stock QMT configuration $useSendmail = false; $optional_delimiter = 'detect'; $default_folder_prefix = ''; $show_prefix_option = false; $force_username_lowercase = true; $hide_sm_attributions = true; $plugins[] = 'calendar'; $plugins[] = 'notes'; $plugins[] = 'filters'; $plugins[] = 'quota_usage'; $plugins[] = 'unsafe_image_rules'; $plugins[] = 'qmailadmin_login'; ?>
Timekeeping
Dovecot is very sensitive to variations in time, and will terminate if it detects a rather small variance. This is particularly problematic in VM guests. You should be running ntpd on your QMT to keep accurate time. In order to start dovecot automatically in the event that dovecot terminates itself, this script run every few minutes as cron job will do the trick:
#!/bin/sh # check if dovecot's running, and start it if it's not # shubes - 20090206 - created service dovecot status >/dev/null 2>&1 || \ service dovecot start >/dev/null 2>&1
It is suggested that you name the script "dovecot-check" and put it in the /usr/local/sbin directory. Don't forget to "chmod +x /usr/local/sbin/dovecot-check" so that the script will execute!
In order so that this runs every five minutes, add this line to your crontab:
0-59/5 * * * * /usr/local/sbin/dovecot-check 2>&1 > /dev/null
Dovecot POP3
In order to use dovecot for POP3 as well as IMAP, you need to stop the qmail pop3 service, and configure dovecot to handle it.
# cd /var/qmail/supervise/ # touch pop3/down pop3/log/down # touch pop3-ssl/down pop3-ssl/log/down # service qmail stop # service qmail start
Edit /etc/dovecot/toaster.conf, adding pop3 to the protocols parameter:
protocols = imap pop3
Edit /etc/dovecot/local.conf, adding a section for protocol pop3:
protocol pop3 { pop3_client_workarounds = outlook-no-nuls oe-ns-eoh pop3_fast_size_lookups = yes pop3_lock_session = yes # %f format is compatible with qmail-pop3d # pop3_uidl_format = %f }
If you have users who use pop3 and have left messages on the server (the messages would be located in their Maildir/cur directory), then you should uncomment the pop3_uidl_format line. Otherwise, these messages would be downloaded again by dovecot.
If you want to change over to dovecot's UIDL format, you can remove the messages in the Maildir/cur directory. Be absolutely sure that the users are using pop3 and not imap if you do this. Messages which have not been downloaded yet would be in their Maildir/new directory.
Then restart dovecot:
# service dovecot restart
That should do it for you.
Upgrading
In the case of all upgrades, be sure to review the dovecot wiki regarding upgrades for the versions you're upgrading from/to. There may be considerations there for your particular environment that are not mentioned here.
dovecot 2.0.x rpm
Once you're running dovecot v2.0.x from the QTP repo, upgrading to subsequent releases from that repo is simple:
# yum --enablerepo=qtp-CentOS update dovecot # service dovecot restart
Version 2.0.11 is current as of this writing, so versions beyond 2.0.x might have other considerations.
dovecot 1.x.x rpm
If you are upgrading from an rpm of dovecot version 1.x, you need to migrate your configuration settings to the new config file syntax. The easiest way to do this is to run the new doveconf program against your previous dovecot.conf file, then manually apply any custom settings you had (shared folders and such) to the new local.conf file. After upgrading the rpm package, do:
# cd /etc/dovecot # doveconf -n >dovecot-2.conf.old # mv dovecot.conf dovecot-1.conf # mv dovecot.conf.rpmnew dovecot.conf
If you were running a pretty much 'stock' configuration, you will probably be able to use the new configuration as is, after renaming the dovecot.conf files to activate the new one, as above. To be sure you're carrying forward your previous settings, review the dovecot-2.conf.old file and add any settings you have there which are not already in the toaster.conf file to the local.conf file.
dovecot 1.x.x non-rpm
If you installed dovecot using the procedure that was previously here on the wiki (the old-fashioned manual way), you should remove that installation before installing the RPM, but be sure to save your configuration file first:
# mkdir /etc/dovecot # cp /usr/local/etc/dovecot.conf /etc/dovecot/dovecot.conf # cd /the/directory/you/installed/from # sudo make uninstall
Then install the RPM as in a new install, and follow the notes for upgrading your configuration settings. You will not need to convert mailboxes, but you will need to disable any supervise scripts which you created:
# cd /var/qmail/supervise # mv dovecot .dovecot
By hiding the dovecot supervise directory, this will prevent it from attempting to start.
Dovecot without ipv6
after disabling ip V6 dovecot will not start, telling
"Fatal: listen(143) failed: Address already in use"
In dovecots configfile replace the line:
listen = *, ::
with
listen = *
like that it only listens on ipv4 and starts perfectly
Questions
If there are any questions or comments about this, please post to the list.
Corrections
If you see something here that needs correction, by all means, correct it! :)