VMware Images:
|
Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail (CentOS 6.2 x86_64)
|
Submitted by falko (Contact Author) (Forums) on Tue, 2012-01-31 19:54. :: Anti-Spam/Virus | CentOS | Email | Postfix
Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail (CentOS 6.2 x86_64)Version 1.0 This tutorial is Copyright (c) 2012 by Falko Timme. It is derived from a tutorial from Christoph Haas which you can find at http://workaround.org. You are free to use this tutorial under the Creative Commons license 2.5 or any later version. This document describes how to install a Postfix mail server that is based on virtual users and domains, i.e. users and domains that are in a MySQL database. I'll also demonstrate the installation and configuration of Courier (Courier-POP3, Courier-IMAP), so that Courier can authenticate against the same MySQL database Postfix uses. The resulting Postfix server is capable of SMTP-AUTH and TLS and quota (quota is not built into Postfix by default, I'll show how to patch your Postfix appropriately). Passwords are stored in encrypted form in the database (most documents I found were dealing with plain text passwords which is a security risk). In addition to that, this tutorial covers the installation of Amavisd, SpamAssassin and ClamAV so that emails will be scanned for spam and viruses. I will also show how to install SquirrelMail as a webmail interface so that users can read and send emails and change their passwords. The advantage of such a "virtual" setup (virtual users and domains in a MySQL database) is that it is far more performant than a setup that is based on "real" system users. With this virtual setup your mail server can handle thousands of domains and users. Besides, it is easier to administrate because you only have to deal with the MySQL database when you add new users/domains or edit existing ones. No more postmap commands to create db files, no more reloading of Postfix, etc. For the administration of the MySQL database you can use web based tools like phpMyAdmin which will also be installed in this howto. The third advantage is that users have an email address as user name (instead of a user name + an email address) which is easier to understand and keep in mind. This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web. This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!
1 Preliminary NoteThis tutorial is based on CentOS 6.2 x86_64, so you should set up a basic CentOS 6.2 server installation before you continue with this tutorial (e.g. as shown in the first six chapters of The Perfect Server - CentOS 6.2 x86_64 With Apache2 [ISPConfig 3]). The system should have a static IP address. I use 192.168.0.100 as my IP address in this tutorial and server1.example.com as the hostname. You should make sure that the firewall is off (at least for now) and that SELinux is disabled (this is important!).
2 Enable Additional Repositories And Install Some SoftwareFirst we import the GPG keys for software packages: rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY* Then we enable the RPMforge and EPEL repositories on our CentOS system as lots of the packages that we are going to install in the course of this tutorial are not available in the official CentOS 6.2 repositories: rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt cd /tmp (If the above link doesn't work anymore, you can find the current version of rpmforge-release here: http://packages.sw.be/rpmforge-release/) rpm --import https://fedoraproject.org/static/0608B895.txt yum install yum-priorities Edit /etc/yum.repos.d/epel.repo... vi /etc/yum.repos.d/epel.repo ... and add the line priority=10 to the [epel] section:
Then we update our existing packages on the system: yum update Now we install some software that we need later on: yum groupinstall 'Development Tools'
3 Install Apache, MySQL, phpMyAdminThis can all be installed with one single command (including the packages we need to build Courier-IMAP): yum install ntp httpd mysql-server php php-mysql php-mbstring rpm-build gcc mysql-devel openssl-devel cyrus-sasl-devel pkgconfig zlib-devel phpMyAdmin pcre-devel openldap-devel postgresql-devel expect libtool-ltdl-devel openldap-servers libtool gdbm-devel pam-devel gamin-devel libidn-devel db4-devel mod_ssl telnet
4 Install Courier-IMAP, Courier-Authlib, And MaildropUnfortunately there are no rpm packages for Courier-IMAP, Courier-Authlib, and Maildrop, therefore we have to build them ourselves. RPM packages should not be built as root; courier-imap will even refuse to compile if it detects that the compilation is run as the root user. Therefore we create a normal user account now (falko in this example) and give him a password: useradd -m -s /bin/bash falko We will need the sudo command later on so that the user falko can compile and install the rpm packages. But first, we must allow falko to run all commands using sudo: Run visudo In the file that opens there's a line root ALL=(ALL) ALL. Add a similar line for falko just below that line:
Now we are ready to build our rpm package. First become the user falko: su falko Next we create our build environment: mkdir $HOME/rpm echo "%_topdir $HOME/rpm" >> $HOME/.rpmmacros Now we create a downloads directory and download the source files from http://www.courier-mta.org/download.php: mkdir $HOME/downloads wget https://sourceforge.net/projects/courier/files/authlib/0.63.0/courier-authlib-0.63.0.tar.bz2/download (Please note that I use Courier-IMAP 4.9.3 here instead of the newer 4.10.0 because 4.10.0 depends on systemctl which exists for Fedora, but not for CentOS.) Now (still in $HOME/downloads) we can build courier-authlib: sudo rpmbuild -ta courier-authlib-0.63.0.tar.bz2 After the build process, the rpm packages can be found in /root/rpmbuild/RPMS/x86_64 (/root/rpmbuild/RPMS/i386 if you are on an i386 system). The command sudo ls -l /root/rpmbuild/RPMS/x86_64 shows you the available rpm packages: [falko@server1 downloads]$ sudo ls -l /root/rpmbuild/RPMS/x86_64 Select the ones you want to install, and install them like this: sudo rpm -ivh /root/rpmbuild/RPMS/x86_64/courier-authlib-0.63.0-1.el6.x86_64.rpm /root/rpmbuild/RPMS/x86_64/courier-authlib-mysql-0.63.0-1.el6.x86_64.rpm /root/rpmbuild/RPMS/x86_64/courier-authlib-devel-0.63.0-1.el6.x86_64.rpm Now we go back to our downloads directory: cd $HOME/downloads Run the following commands to create required directories/change directory permissions (because otherwise the build process for Courier-Imap will fail): sudo mkdir -p /var/cache/ccache/tmp Now run rpmbuild again, this time without sudo, otherwise the compilation will fail because it was run as root: rpmbuild -ta courier-imap-4.9.3.tar.bz2 After the build process, the rpm packages can be found in $HOME/rpm/RPMS/x86_64 ($HOME/rpm/RPMS/i386 if you are on an i386 system): cd $HOME/rpm/RPMS/x86_64 The command ls -l shows you the available rpm packages: [falko@server1 x86_64]$ ls -l You can install courier-imap like this: sudo rpm -ivh courier-imap-4.9.3-1.x86_64.rpm Now we go back to our downloads directory: cd $HOME/downloads and run rpmbuild again, this time to build a maildrop package: sudo rpmbuild -ta maildrop-2.5.5.tar.bz2 After the build process, the rpm packages can be found in /root/rpmbuild/RPMS/x86_64 (/root/rpmbuild/RPMS/i386 if you are on an i386 system). The command sudo ls -l /root/rpmbuild/RPMS/x86_64 shows you the available rpm packages: [falko@server1 downloads]$ sudo ls -l /root/rpmbuild/RPMS/x86_64 You can now install maildrop like this: sudo rpm -ivh /root/rpmbuild/RPMS/x86_64/maildrop-2.5.5-1.x86_64.rpm After you have compiled and installed all needed packages, you can become root again by typing exit
5 Apply Quota Patch To PostfixWe have to get the Postfix source rpm, patch it with the quota patch, build a new Postfix rpm package and install it. cd /usr/src The last command will show some warnings that you can ignore: warning: user mockbuild does not exist - using root cd /root/rpmbuild/SOURCES Now we must edit the file postfix.spec: vi postfix.spec Add Patch0: postfix-2.6.5-vda-ng.patch to the # Patches stanza, and %patch0 -p1 -b .vda-ng to the %setup -q stanza:
Then we build our new Postfix rpm package with quota and MySQL support: rpmbuild -ba postfix.spec Our Postfix rpm package is created in /root/rpmbuild/RPMS/x86_64 (/root/rpmbuild/RPMS/i386 if you are on an i386 system), so we go there: cd /root/rpmbuild/RPMS/x86_64 The command ls -l shows you the available packages: [root@server1 x86_64]# ls -l To make sure that no version of postfix was previously installed on your system, use: yum remove postfix Pick the Postfix package and install it like this: rpm -ivh postfix-2.6.6-2.2.el6.x86_64.rpm
|

![Creative Commons Attribution License [Creative Commons Attribution License]](http://creativecommons.org/images/public/somerights20.gif)


Recent comments
1 day 13 hours ago
1 day 15 hours ago
2 days 3 hours ago
2 days 6 hours ago
2 days 10 hours ago
2 days 16 hours ago
3 days 1 hour ago
3 days 3 hours ago
3 days 11 hours ago
3 days 13 hours ago