Installare Qmail

Questo TIPS vuole introdure chi ι alle prime esperienze con gli MTA e nello specifico con QMAIL un server di posta leggero, affidabile e performante. Troverete di seguito una delle tante procedure da seguire per una installazione di un server di posta (Qmail)

Senza perdere altro tempo iniziamo subito a lavorare!
Per prima cosa procuriamoci Qmail (che necessita per l'installazione di altri due software UCSPI-TCP e DAEMONTOOLS):
                                                                                
nota: attenzione le versioni potrebbero cambiare
                                                                                
(download di Qmail)
wget ftp://cr.yp.to/software/qmail-1.03.tar.gz
                                                                                
(download di ucspi)
wget ftp://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
                                                                                
(download di daemontools)
wget ftp://cr.yp.to/daemontools/daemontools-0.70.tar.gz

Scompattiamo i software scaricati:
                                                                                
supponiamo di aver scaricato i software nella directory /usr/local/src
                                                                                
per cui andiamo in questa directory e digitiamo
                                                                                
umask 022
tar -xzf qmail-1.03.tar.gz
tar -xzf ucspi-tcp-0.88.tar.gz
tar -xzf daemontools-0.70.tar.gz
                                                                                
adesso entriamo nella directory di Qmail ed eseguiamo i comandi seguenti:
                                                                                
cd qmail-1.03
mkdir /var/qmail
                                                                                
groupadd nofiles
useradd -g nofiles -d /var/qmail/alias alias -s /nonexistent
useradd -g nofiles -d /var/qmail qmaild -s /nonexistent
useradd -g nofiles -d /var/qmail qmaill -s /nonexistent
useradd -g nofiles -d /var/qmail qmailp -s /nonexistent

groupadd qmail
useradd -g qmail -d /var/qmail qmailq -s /nonexistent
useradd -g qmail -d /var/qmail qmailr -s /nonexistent
useradd -g qmail -d /var/qmail qmails -s /nonexistent
                                                                                
a questo punto editiamo il file /etc/passwd e nel caso no siano gia' presenti, inseriamo alla fine del file le seguenti righe (attenzione i numeri tra i due punti potrebbero se presenti anche essere diversi):
                                                                                
alias:*:7790:2108::/var/qmail/alias:/bin/true
qmaild:*:7791:2108::/var/qmail:/bin/true
qmaill:*:7792:2108::/var/qmail:/bin/true
qmailp:*:7793:2108::/var/qmail:/bin/true
qmailq:*:7794:2107::/var/qmail:/bin/true
qmailr:*:7795:2107::/var/qmail:/bin/true
qmails:*:7796:2107::/var/qmail:/bin/true
                                                                                
installiamo Qmail (attenzione bisogna essere super user)
                                                                                
make setup check (se make non esiste provate con gmake)
./config-fast nome.del.host (il nome del server di posta)

adesso installiamo UCSPI
                                                                                
cd /usr/local/src/ucspi-tcp-0.88
make
make setup check
                                                                                
e ora daemontools
                                                                                
cd /usr/local/daemontools-0.70
make
make setup check
                                                                                
Su alcuni sistemi un po' absoleti ho riscontrato un problema di compilazione in
tai64nlocal.c per cui in caso di problemi su questo file, editarlo e cambiare la riga <sys/time.h> con <time.h> e rilanciare la compilazione.
                                                                                
adesso creiamo la directory service
                                                                                
mkdir /service
                                                                                
ed editiamo il file /etc/inittab aggiungendo alla fine la seguente linea (Attenzione a non dare invio deve essere tutta scritta in una sola riga)

SV:123456:respawn:env – PATH=/usr/local/bin:/usr/bin:/usr/bin:/bin svscan /service </dev/null >/dev/console 2>/dev/console
                                                                                
adesso facciamo rileggere al sistema il file /etc/inittab
                                                                                
kill -HUP 1
                                                                                
verifichiamo che svscan sia partito regolarmente:
                                                                                
ps -waux | grep svscan
                                                                                
adesso facciamo un paio di test per controllare che tutto sia a posto.
                                                                                
cd /usr/local/src/daemontools-0.70
./rts > rts.out
cmp rts.out rts.exp
                                                                                
se non viene evidenziato nessun messaggio vuol dire che i test sono andati a buon fine.
                                                                                
Adesso controlliamo i timestamps del sistema

date | ./tai64n | ./tai64nlocal
                                                                                
date | sh -c './multilog t e 2>&1' | ./tai64nlocal
                                                                                
i due comandi dovrebbero produrre lo stesso output con la differenza di solo qualche secondo di tempo.
                                                                                
Creiamo adesso lo script /var/qmail/rc
                                                                                
#!/bin/sh
                                                                                
exec env – PATH=”/var/qmail/bin:$PATH” \
qmail-start “`cat /var/qmail/control/defaultdelivery`”
                                                                                
(attenzione agli apici singoli sono apcici inversi ` non apici normali ' )
                                                                                
diamo i giusti permessi
                                                                                
chmod 755 /var/qmail/rc
                                                                                
configuriamo il file deafultdelivery

echo ./Maildir > /var/qmail/control/defaultdelivery
                                                                                
adesso creiamo lo script qmailctl (fate un copia e incolla)
                                                                                
#!/bin/sh
                                                                                
# For Red Hat chkconfig
# chkconfig: - 30 80
# description: the qmail MTA
#
                                                                                
                                                                                
PATH=/var/qmail/bin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin
export PATH
LOG=/var/log/qmailctl
                                                                                
echo `date` `tty` $* >>$LOG
                                                                                
if [ -d /service/qmail-pop3d ]; then
  POP=yes
else
  POP=no
fi
                                                                                
case "$1" in
  start)
    echo "Starting qmail"
    if svok /service/qmail-send ; then
      svc -u /service/qmail-send 2>&1 | tee -a $LOG
    else
      echo qmail-send service not running
    fi
    if svok /service/qmail-smtpd ; then
      svc -u /service/qmail-smtpd 2>&1 | tee -a $LOG
    else
      echo qmail-smtpd service not running
    fi
    if [ -d /var/lock/subsys ]; then
      touch /var/lock/subsys/qmail
    fi
    if [ $POP = yes ]; then
      if svok /service/qmail-pop3d ; then
        svc -u /service/qmail-pop3d
      else
        echo qmail-pop3d service not running
      fi
    fi
    ;;
  stop)
    echo "Stopping qmail..."
    echo "  qmail-smtpd"
    svc -d /service/qmail-smtpd 2>&1 | tee -a $LOG
    echo "  qmail-send"
    svc -d /service/qmail-send 2>&1 | tee -a $LOG
    if [ -f /var/lock/subsys/qmail ]; then
      rm /var/lock/subsys/qmail
    fi
    if [ $POP = yes ]; then
      echo "  qmail-pop3d"
      svc -d /service/qmail-pop3d
    fi
    ;;
  stat)
    svstat /service/qmail-send
    svstat /service/qmail-send/log
    svstat /service/qmail-smtpd
    svstat /service/qmail-smtpd/log
    if [ $POP = yes ]; then
      svstat /service/qmail-pop3d
      svstat /service/qmail-pop3d/log
    fi
    qmail-qstat
    ;;
  doqueue|alrm|flush)
    echo "Sending ALRM signal to qmail-send."
    svc -a /service/qmail-send 2>&1 | tee -a $LOG
    ;;
  queue)
    qmail-qstat
    qmail-qread
    ;;
  reload|hup)
    echo "Sending HUP signal to qmail-send."
    svc -h /service/qmail-send 2>&1 | tee -a $LOG
    ;;
  pause)
    echo "Pausing qmail-send"
    svc -p /service/qmail-send 2>&1 | tee -a $LOG
    echo "Pausing qmail-smtpd"
    svc -p /service/qmail-smtpd 2>&1 | tee -a $LOG
    if [ $POP = yes ]; then
      echo "Pausing qmail-pop3d"
      svc -p /service/qmail-pop3d
    fi
    ;;
  cont)
    echo "Continuing qmail-send"
    svc -c /service/qmail-send 2>&1 | tee -a $LOG
    echo "Continuing qmail-smtpd"
    svc -c /service/qmail-smtpd 2>&1 | tee -a $LOG
    if [ $POP = yes ]; then
      echo "Continuing qmail-pop3d"
      svc -c /service/qmail-pop3d
    fi
    ;;
  restart)
    echo "Restarting qmail:"
    echo "* Stopping qmail-smtpd."
    svc -d /service/qmail-smtpd 2>&1 | tee -a $LOG
    echo "* Sending qmail-send SIGTERM and restarting."
    svc -t /service/qmail-send 2>&1 | tee -a $LOG
    echo "* Restarting qmail-smtpd."
    svc -u /service/qmail-smtpd 2>&1 | tee -a $LOG
    if [ $POP = yes ]; then
      echo "* Restarting qmail-pop3d."
      svc -t /service/qmail-pop3d
    fi
    ;;
  cdb)
    tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp 2>&1 | tee -a $LOG
    chmod 644 /etc/tcp.smtp.cdb
    echo "Reloaded /etc/tcp.smtp."
    tcprules /etc/tcp.pop3.cdb /etc/tcp.pop3.tmp < /etc/tcp.pop3 2>&1 | tee -a $LOG
    if [ $POP = yes ]; then
      chmod 644 /etc/tcp.pop3.cdb
      echo "Reloaded /etc/tcp.pop3."
    fi
    ;;
  help)
    cat <<HELP
   stop -- stops mail service (smtp connections refused, nothing goes out)
  start -- starts mail service (smtp connection accepted, mail can go out)
pause -- temporarily stops mail service (connections accepted, nothing leaves)   cont -- continues paused mail service
   stat -- displays status of mail service
    cdb -- rebuild the tcpserver cdb file for smtp
restart -- stops and restarts smtp, sends qmail-send a TERM & restarts it
doqueue -- sends qmail-send ALRM, scheduling queued messages for delivery
reload -- sends qmail-send HUP, rereading locals and virtualdomains
  queue -- shows status of queue
   alrm -- same as doqueue
  flush -- same as doqueue
    hup -- same as reload
HELP
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|doqueue|flush|reload|stat|pause|cont|cdb|queue|help}"
    exit 1
    ;;
esac
                                                                                
exit 0

diamogli i giusti permessi e linkiamolo per eseguirlo da ovunque
                                                                                
chmod 755 /var/qmail/bin/qmailctl
ln -s /var/qmail/bin/qmailctl /usr/local/sbin
                                                                                
adesso creiamo i link di partenza e chiusura automatica di qmail (questi link sono per la versione di Linux della Red Hat per altre distro potrebbero cambiare controllare la vostra distro)
                                                                                
ln -s /var/qmail/bin/qmailctl /etc/rcd./init.d
ln -s ../init.d/qmail /etc/rc.d/rc0.d/K30qmail
ln -s ../init.d/qmail /etc/rc.d/rc1.d/K30qmail
ln -s ../init.d/qmail /etc/rc.d/rc2.d/S80qmail
ln -s ../init.d/qmail /etc/rc.d/rc3.d/S80qmail
ln -s ../init.d/qmail /etc/rc.d/rc4.d/S80qmail
ln -s ../init.d/qmail /etc/rc.d/rc5.d/S80qmail
ln -s ../init.d/qmail /etc/rc.d/rc6.d/K30qmail
                                                                                
adesso creiamo i servizi che servono a Qmail per funzionare
                                                                                
mkdir -p /var/qmail/supervise/qmail-send/log
mkdir -p /var/qmail/supervise/qmail-smtpd/log

chmod +t /var/qmail/supervise/qmail-send
chmod +t /var/qmail/supervise/qmail-smtpd
                                                                                
adesso creiamo lo script di partenza /var/qmail/supervise/qmail-send/run
                                                                                
#!/bin/sh
exec /var/qmail/rc
                                                                                
e quello per il log /var/qmail/supervise/qmail-send/log/run
                                                                                
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog -t /var/log/qmail
                                                                                
adesso creiamo il file /var/qmail/supervise/qmail-smtpd/run

#!/bin/sh
                                                                                
QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`
MAXSMTPD=`head -1 /var/qmail/control/concurrencyincoming`
if [ -z "$QMAILDUID" -o -z "$NOFILESGID" -o -z "$MAXSMTPD" ]; then
    echo QMAILDUID, NOFILESGID, or MAXSMTPD is unset in
    echo $0
    exit 1
fi
exec /usr/local/bin/softlimit -m 2000000 \
    /usr/local/bin/tcpserver -v -R -H -l 0 -x /etc/tcp.smtp.cdb -c "$MAXSMTPD" \        -u "$QMAILDUID" -g "$NOFILESGID" 0 smtp /var/qmail/bin/qmail-smtpd 2>&1
                                                                                
adesso creiamo il file concurrencyincoming
                                                                                
echo 20 > /var/qmail/control/concurrencyincoming
chmod 644 /var/qmail/control/concurrencyincoming
                                                                                
ed ora il file /var/qmail/supervise/qmail-smtpd/log/run

#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog \
  t /var/log/qmail/smtpd
                                                                                
diamogli i giusti permessi
chmod 755 /var/qmail/supervise/qmail-send/run
chmod 755 /var/qmail/supervise/qmail-send/log/run
chmod 755 /var/qmail/supervise/qmail-smtpd/run
chmod 755 /var/qmail/supervise/qmail-smtpd/log/run
                                                                                
creiamo le directory per il logging
                                                                                
mkdir -p /var/log/qmail/smtpd
chown -R qmaill /var/log/qmail
                                                                                
linkiamo i servizi alla directory /service
                                                                                
ln -s /var/qmail/supervise/qmail-send /var/qmail/supervise/qmail-smtpd /service
                                                                                
Attenzione: a questo punto se tutto è stato eseguito correttamente, qmail partirà automaticamente per cui diamo il comando qmailctl stop per fermarlo.

Adesso settiamo l'accesso per la spedizione della posta:
                                                                                
echo '127.:allow,RELAYCLIENT=””' > /etc/tcp.smtp
qmailctl cdb
                                                                                
Creiamo gli alias di sistema per gli utenti root, postmaster e mailer-daemon questi sono utenti che devo esistere su tutti i mail server.
                                                                                
echo \&[email protected] > /var/qmail/alias/.qmail-root
echo \&[email protected] > /var/qmail/alias/.qmail-postmaster
ln -s .qmail-postmaster /var/qmail/alias/.qmail-mailer-daemon
chmod 644 /var/qmail/alias/.qmail-root /var/qmail/alias/.qmail-postmaster
                                                                                
Adesso bisogna disinstallare SendMail (installato di default su molte distro)
                                                                                
stoppiamolo
/etc/rc.d/init.d/sendmail stop
                                                                                
e rimuoviamolo dal sistema
rpm -e - -nodeps sendmail

dato che molti software cercano sendmail installato sul sistema, creiamo dei link in modo da avere la compatibilità con sendmail
                                                                                
ln -s /var/qmail/bin/sendmail /usr/lib
ln -s /var/qmail/bin/sendmail /usr/sbin
                                                                                
a questo punto possiamo far partire qmail
                                                                                
qmailctl start
                                                                                
e vediamo se è attivo e funzionante
                                                                                
qmailctl stat
                                                                                
dovremmo vedere un output che ci dice qulale e' il PID e da quando tempo sono UP i servizi di Qmail (che dovrebbero essere 4) qmail-send, qmail-send/log, qmail-smtpd e qmail-smtpd/log oltre a dirci quanti messaggi abbiamo in coda.
                                                                                
Ancora un test..... proviamo ad inviare una e-mail al postmaster del nostro dominio

echo to: postmaster | /var/qmail/bin/qmail-inject
                                                                                
controllate il log di qmail con il comando
                                                                                
tail -f /var/log/qmail/current
                                                                                
dovreste trovare informazioni sulla spedizione del messaggio e una riga che vi dice:
delivery 4: success: 1.2.3.4_accepted_message./...
                                                                                
i numeri possono essere diversi ma ciò vuol dire che l'email è stata inviata correttamente.
                                                                                
Adesso testiamo il server SMTP (quello che si occupa della spedizione dei messaggi)
                                                                                
telnet 127.0.0.1 25
                                                                                
(messaggi)
Trying 127.0.0.1 . .
Connected to 127.0.0.1
Escape character is '^]'.
220 domain ESMTP
helo postmaster
                                                                                
(messaggi)
250 domain
                                                                                
mail from:<[email protected]>
                                                                                
(messaggi)
250 ok
                                                                                
rcpt to:<[email protected]>
                                                                                
(messaggi)
250 ok
                                                                                
data
                                                                                
(messaggi)
354 go ahead
                                                                                
Subject: testiamo
questo è un messaggio di test
.
                                                                                
(messaggi)
250 ok 8123456789 qp 123456
                                                                                
quit
                                                                                
(messaggi)
221 domain
Connection closed by foreign host.
                                                                                
In questo modo abbiamo testato che il server funziona e spedisce ai propri domini e a quelli esterni.
                                                                                
Per aggiungere nuove caselle, creare domini virtuali, vi rimando ad un mio prossimo post su questo stesso sito.
Per informazioni o consulenze contattatemi!

Privacy Policy