Progetto

Generale

Profilo

Actions

EnPostfixAdminInst » Cronologia » Versione 1

Versione 1/26 | Successivo »
Amministratore Truelite, 01-10-2009 11:52


TracNav(EnTOC)

A mail server with Postfixadmin, Postfix and Dovecot on Debian Lenny

This HOWTO will explain the installation and the configuration of a full featured mail server using Postfix as SMTP server, Dovecot as POP/IMAP server and Postfixadmin as management interface. As Postfixadmin need a database to maintain account and domain informations we will use MySQL (but also PostgresSQL or SQLite can be used). All the following instruction refers to a Debian Lenny.

=== Postfixadmin Installation ===

Postfixadmin is distributed as a Debian package directly by the maintainer, you just need to download the {{{.deb}}} file from [http://sourceforge.net/project/showfiles.php?group_id=191583&package_id=225300 here] because there in no repository. Before installing it you will need to install some dependencies (a web server, and because we want to use it on a standalone server also a database server). We choose Apache as web server and MySQL as database server, so you will need to install these and the other Postfixadmin dependencies the Debian way with the command: {{{
aptitude install dbconfig-common wwwconfig-common \
libapache2-mod-php5 php5 php5-imap php5-mysql \
mysql-client mysql-server postfix-mysql
}}}
(and we assume here that you can answer to the ordinary setup questions made by ''debconf'', mainly about the setup for the {{{root}}} user for MySQL).

Before installing the {{{.deb}}} file you will also need to create a dedicated database and a database user owning it for Postfixadmin; you can do this with the folowing commands: {{{
mysqladmin -u root -p create postfixadmin
mysql -u root -p
mysql> grant create, select, insert, update, delete, lock, index, alter, drop
on postfixadmin.* to 'postfixadmin'@'localhost'
identified by 'secretandcomplexpassword';
mysql> flush privileges;
mysql> \q
}}}
then you can install the {{{.deb}}} file with: {{{
dpkg -i postfixadmin_*.deb
}}}

You have two choices for Postfixadmin, you can download the 2.2 stable version or the new 2.3 release candidate that supports more features and is almost production ready. If you use the 2.2 stable version you will need to modify the following lines of the {{{/etc/postfixadmin/config.inc.php}}} file to setup the access to the previously created database: {{{
$CONF['configured'] = true;
...
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = 'secretandcomplexpassword';
$CONF['database_name'] = 'postfixadmin';
}}}

If instead you use the 2.3 development version, having {{{dbconfig-common}}} e {{{wwwconfig-common}}} installed, the previous step of the database creation is managed by the package itself and it is no more needed. Also the database access configuration inside {{{/etc/postfixadmin/config.inc.php}}} is automatically done by ''debconf'', so all you will need is to give to ''debconf'' the password of the MySQL {{{root}}} user that you setup at the beginning, and then answer to the ''debconf'' questions about the password used for the Postfixadmin dedicated database user.

After this you can proceed to populate the database, this should be done using Postfixadmin itself, using the following link in your browser (you can use the same link for database upgrade or to reset the Postfixadmin superuser password): {{{
http://MY.POSTFIXADMIN.SERVER.IP/postfixadmin/setup.php
}}}
up to 2.2 version this PHP script should be run once, and the removed after its use; with the 2.3 version when using it for the first time it would ask you for a setup password, then printing an hashed value that you will need to put inside the {{{/etc/postfixadmin/config.inc.php}}} file, modifying the following line: {{{
$CONF['setup_password'] = 'changeme';
}}}
with this modification done you will need to re-execute the script going back to {{{http://MY.POSTFIXADMIN.SERVER.IP/postfixadmin/setup.php}}}; this time you can give the setup password to create the superuser Postfixadmin account having full access to all management functions: take note that like all Postfixadmin account this also should be given in the form of an email address (something like {{{}}}).

To check that this initial setup has been completed successfully you can see if everything is working fine going to the {{{http://MY.POSTFIXADMIN.SERVER.IP/postfixadmin}}} address, logging in using the superuser account you just created. After this check you can pass to the following steps; the first one is to put proper references to your main domain in the web interface; this can be done with: {{{
cd /etc/postfixadmin/
mv config.inc.php config.inc.php.orig
sed -e 's/change-this-to-your.domain.tld/mydomain.it/g' config.inc.php.orig > config.inc.php
}}}
then you can check the file to be sure that all link on web page are correct (they will be always something like {{{http://mydomain.it}}}).

The second step is to configure the mailbox pathname, we choose to map an email account like {{{}}}) to a mailbox like {{{mydomain.it/username}}}, to do this we have to put the following configuration values in the {{{/etc/postfixadmin/config.inc.php}}} file: {{{
$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
}}}

Then if want to enable quotas you need to modify also the following line: {{{
$CONF['quota'] = 'YES';
}}}
and if you want to enable the {{{vacation}}} support you will need the following lines: {{{
$CONF['vacation'] = 'YES';
$CONF['vacation_domain'] = 'autoreply.mydomain.it'
}}}
where {{{autoreplay.mydomain.it}}} is the domain used by Postfix to manage {{{vacation}}} email (we'll look at this in the following). Other configuration that can be modified are the following: {{{
$CONF['default_language'] = 'it';
$CONF['min_password_length'] = 6;
$CONF['aliases'] = '50';
$CONF['mailboxes'] = '50';
$CONF['maxquota'] = '50';
}}}
to setup the web interface language, a minimum length for the accounts password, and the default limit on number of alias, mailbox and quota given to each domain (0 means no limit).

If you install the 2.3 version there is a new simplified management for to have the same aliases on more domains; this need more database queries and a modified Postfix configuration, so is better to disable it with: {{{
$CONF['alias_domain'] = 'NO';
}}}

=== Postfix configuration ===

We need now to tell Postfix to use Postfixadmin data for email account and domains

Il passo successivo è configurare Postfix per fare uso degli utenti e delle mailbox definite su PostfixAdmin, installando il pacchetto {{{postfix}}} si abbia cura di rispondere alla configurazione automatica di utilizzare il profilo per il sito internet, specificando il proprio dominio principale. Per lo stoccaggio della posta si dovrà usare una directory apposita, la cui proprietà sarà di un utente dedicato; una volta che si sia scelto un filesystem con adeguato spazio, la si potrà creare con i comandi: {{{
mkdir /var/mail/vmail
useradd -d /var/mail/vmail vmail
chown vmail:vmail /var/mail/vmail/
chmod o-xr /var/mail/vmail/
}}}

Poi si dovrà indicare a Postfix di usare i dati mantenuti su MySQL per le mailbox virtuali, per questo anzitutto si deve installare il pacchetto {{{postfix-mysql}}}, dopo di che si dovranno aggiungere le seguenti linee di configurazione al {{{main.cf}}}: {{{
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_base = /var/mail/vmail
virtual_minimum_uid = 106
virtual_transport = virtual
virtual_uid_maps = static:106
virtual_gid_maps = static:61
}}}
(dove 106 e 61 sono rispettivamente uid e gid dell'utente {{{vmail}}}).

Si dovranno inoltre creare il vari file {{{mysql_*}}} con le configurazioni per l'uso del database, il primo file è quello che consente di utilizzare gli alias definiti nel database, e deve essere qualcosa del tipo: {{{
user = postfixadmin
password = passsegretaedifficile
hosts = localhost
dbname = postfixadmin
query = SELECT goto FROM alias WHERE address='%s' AND active = 1
}}}
il secondo consente di ottenere l'elenco dei domini mantenuti nel database, e deve essere qualcosa del tipo: {{{
user = postfixadmin
password = passsegretaedifficile
hosts = localhost
dbname = postfixadmin
query = SELECT domain FROM domain WHERE domain='%s' and backupmx = '0' and active = '1'
}}}
il terzo consente di ottenere le directory con le mailbox che saranno create a partire dalla directory di base, e deve essere qualcosa del tipo: {{{
user = postfixadmin
password = passsegretaedifficile
hosts = localhost
dbname = postfixadmin
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = 1
}}}

Se poi si vogliono gestire con [http://postfixadmin.sourceforge.net/ PostfixAdmin] anche eventuali secondari di posta, si potrà aggiungere al {{{main.cf}}} di Postfix la riga: {{{
relay_domains = $mydestination, proxy:mysql:/etc/postfix/mysql_relay_domains_maps.cf
}}}
dove in {{{mysql_relay_domains_maps.cf}}} dovrà essere qualcosa del tipo: {{{
user = postfixadmin
password = passsegretaedifficile
hosts = localhost
dbname = postfixadmin
query = SELECT domain FROM domain WHERE domain='%s' and backupmx = '1' and active = '1'
}}}

=== Uso di vacation ===

Se si è scelto di usare {{{vacation}}} la configurazione diventa leggermente più complessa, anzitutto si deve creare un utente apposito per la gestione dei delle risposte automatiche, questo lo si può fare con i seguenti comandi che assicurano che l'utente abbia i minimi privilegi: {{{
groupadd -g 65501 vacation
useradd -g 65501 -u 65501 -c Vacation -s /sbin/nologin -d /nonexistent vacation
}}}
dopo di che si dovrà creare una directory ad accesso esclusivo di questo utente dove saranno mantenuti anche i suoi file temporanei, questo si fa con i comandi: {{{
mkdir /var/spool/vacation
chown -R vacation.vacation /var/spool/vacation
chmod o-xr /var/spool/vacation
}}}
infine si dovrà copiare lo script perl fornito con [http://postfixadmin.sourceforge.net/ PostfixAdmin] nella suddetta directory e renderlo eseguibile: {{{
cd /usr/share/doc/postfixadmin/examples/VIRTUAL_VACATION/
zcat vacation.pl.gz > /var/spool/vacation/vacation.pl
chmod 700 /var/spool/vacation/vacation.pl
}}}
per farlo funzionare sono però necessari una serie di moduli per il perl, che si dovranno installare con: {{{
aptitude install libemail-valid-perl libmime-encwords-perl libmime-perl \
libmail-sender-perl liblog-log4perl-perl
}}}
inoltre si dovranno modificare le prime righe dello script dove sono impostate le credenziali di accesso al database, con qualcosa del genere: {{{
our $db_type = 'mysql';
our $db_host = 'localhost';
our $db_username = 'postfixadmin';
our $db_password = 'passsegretaedifficile';
our $db_name = 'postfixadmin';

our $vacation_domain = 'autoreply.miodominio.it';
}}}

Occorre poi eseguire una configurazione ulteriore di Postfix, anzitutto occorre definire un nuovo tipo di trasporto ad uso di vacation, aggiungendo le righe seguenti a {{{/etc/postfix/master.cf}}}: {{{
vacation unix - n n - - pipe
flags=Rq user=vacation argv=/var/spool/vacation/vacation.pl f ${sender} - ${recipient}
}}}
dopo di che si dovrà utilizzarlo per il trasporto delle email indirizzate ad {{{autoreply.miodominio.it}}}, definendo dentro {{{/etc/postfix/transport}}}: {{{
autoreply.miodominio.it vacation:
}}}
ed infine aggiungere a {{{/etc/postfix/main.cf}}}: {{{
transport_maps = hash:/etc/postfix/transport
}}}
fatto questo si dovrà fare usare a Postfix la nuova configurazione con: {{{
postmap /etc/postfix/transport
postfix reload
}}}

=== Configurare Dovecot per Postfixadmin ===

Per l'accesso alla posta mantenuta da Postfixadmin è necessario un server IMAP, vedremo allora come configurare Dovecot che fornisce comunque anche l'accesso con POP, ed il tutto sia in chiaro che con cifratura sotto SSL. Si inizi anzitutto con l'installare le varie componenti di Dovecot, questo si fa al solito con: {{{
aptitude install dovecot-imapd dovecot-pop3d
}}}
la configurazione di base dovrà essere modificata anzitutto per il fatto che la posta deve essere trovate in delle maildir a partire dalla directory {{{/var/mail/vmail}}} ed acceduta con l'utente {{{vmail}}} creato in precedenza, nel nostro caso questo comporta la modifica delle seguenti righe de file di configurazione principale che è {{{/etc/dovecot/dovecot.conf}}}: {{{
mail_location = maildir:/var/mail/vmail/%d/%n
mail_privileged_group = vmail
first_valid_uid = 106
}}}
(dove 106 è l'uid dell'utente {{{vmail}}}).

Occorre poi disabilitare l'autenticazione sugli utenti locali (via PAM) ed utilizzare i dati di MySQL, questo comporta la sostituzione delle direttive {{{userdb}}} e {{{passdb}}} che fan riferimento a PAM con le seguenti che indicano il file da usare per i parametri di accesso al database: {{{
passdb sql {
args = /etc/dovecot/dovecot-mysql.conf
}
userdb sql {
args = /etc/dovecot/dovecot-mysql.conf
}
}}}
ed infine dovremo inserire nel file {{{/etc/dovecot/dovecot-mysql.conf}}} le necessarie configurazioni per l'accesso al database ed ai relativi dati, con un contenuto del tipo di: {{{
driver = mysql
connect = host=localhost dbname=postfixadmin user=postfixadmin password=passsegretaedifficile client_flags=0
default_pass_scheme = MD5
user_query = SELECT maildir, 106 AS uid, 61 AS gid FROM mailbox WHERE username = '%u'
password_query = SELECT password FROM mailbox WHERE username = '%u' AND active = '1'
}}}
(dove 106 e 61 sono uid e gid dell'utente {{{vmail}}}).

Aggiornato da Amministratore Truelite oltre 14 anni fa · 1 revisions