em Sem categoria

Instalando e configurando o qmail

Artigo retirado do site LinuxIT.

Atualizado em 22/08/2004 ?s 15:58:06

Bom a algum tempo prometi um tutorial do qmail, e aqui est? o mesmo. Pois bem, n?o irei fazer uma descri??o do qmail, pois j? existem v?rios artigos que j? fazem isso. Irei simplesmente mostrar como configur?-lo usando o daemontools para controlar os processos de inicializa??o. Lembrando que esta instala??o foi baseada no slackware 9.1.

Ser? instalado: qmail + vpopmail + courier-imap + qmailadmin + autorespond + ezmlm + ucspi-tcp.

Vamos primeiramente criar os diret?rios onde ser?o baixados os sources:

mkdir -p /usr/src/qmailsource/patches
cd /usr/src/qmailsource

agora vamos fazer o download dos pacotes necess?rios:

wget http://www.qmail.org/qmail-1.03.tar.gz
wget http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
wget http://www.inter7.com/devel/ezmlm-0.53-idx-0.41.tar.gz
wget http://umn.dl.sourceforge.net/sourceforge/vpopmail/vpopmail-5.4.6.tar.gz
wget http://umn.dl.sourceforge.net/sourceforge/qmailadmin/autorespond-2.0.4.tar.gz
wget http://umn.dl.sourceforge.net/sourceforge/qmailadmin/qmailadmin-1.2.1.tar.gz
wget http://umn.dl.sourceforge.net/sourceforge/courier/courier-imap-3.0.7.tar.bz2

cd patches

wget http://www.qmail.org/qmail-1.03-mfcheck.3.patch
wget http://www.qmail.org/qmailqueue-patch
wget http://www.palomine.net/qmail/tarpit.patch
wget http://www.qmail.org/netscape-progress.patch
wget http://www.qmail.org/moni.csi.hu/pub/glibc-2.3.1/qmail-1.03.errno.patch
wget http://www.qmail.org/moni.csi.hu/pub/glibc-2.3.1/ucspi-tcp-0.88.errno.patch
wget http://www.qmail.org/moni.csi.hu/pub/glibc-2.3.1/daemontools-0.76.errno.patch
wget http://www.suspectclass.com/~sgifford/qmail/qmail-0.0.0.0.patch

Instalando o ucspi-tcp

O ucspi-tcp ? um programa que gerencia a inicializa??o do qmail.

cd /usr/src/qmailsource
tar xvzf ucspi-tcp-0.88.tar.gz
cd ucspi-tcp-0.88
patch -p1 < ../patches/ucspi-tcp-0.88.errno.patch
make
make setup check

Instalando o qmail

Veja abaixo a descri??o dos patchs que ser?o instalados:

qmail-1.03.errno.patch – ? o patch que corrige o problema com o gcc 3.

qmailqueue-patch – aplique este patch caso pense em colocar o qmail-scanner.

qmail-0.0.0.0.patch – Este corrigue um bug do qmail, pois ele entende 0.0.0.0 como endere?o ip.

tarpit.patch – Este aqui adiciona um tempo de espera entre cada mensagem, uma especie de anti-spam.

netscape-progress.patch – Este patch corrige um bug do qmail com clients netscape.

Adicionando os usu?rios e grupos.

groupadd nofiles
useradd -g nofiles -d /var/qmail/alias alias
useradd -g nofiles -d /var/qmail qmaild
useradd -g nofiles -d /var/qmail qmaill
useradd -g nofiles -d /var/qmail qmailp
groupadd qmail
useradd -g qmail -d /var/qmail qmailq
useradd -g qmail -d /var/qmail qmailr
useradd -g qmail -d /var/qmail qmails

cd /usr/src/qmailsource
tar xvzf qmail-1.03.tar.gz
patch -p0 < patches/qmail-1.03.errno.patch
patch -p0 < patches/qmailqueue-patch
patch -p0 < patches/qmail-0.0.0.0.patchcd qmail-1.03
patch -p0 < ../patches/tarpit.patch
patch -p0 < ../patches/netscape-progress.patchmkdir /var/qmail
mkdir /etc/qmail
ln -s /etc/qmail /var/qmail/control

make setup check

./config-fast maquina.dominio

cd ~alias
touch .qmail-postmaster .qmail-mailer-daemon .qmail-root
chmod 644 ~alias/.qmail*

Instalando o vpopmail

O vpopmail ? o respons?vel pelos usu?rios, j? que com ele, n?o ? necess?rio ter os usu?rios cadastrados no sistema.

Adicionando o usu?rio e grupo sob o qual o vpopmail ira rodar:

groupadd -g 89 vchkpw
useradd -g vchkpw -u 89 -d /var/vpopmail vpopmail

cd /usr/src/qmailsource
tar xvzf vpopmail-5.4.6.tar.gz
mkdir -p /var/vpopmail/etc

cd vpopmail-5.4.6

./configure –enable-roaming-users=y \
–enable-relay-clear-minutes=30 \
–disable-md5-passwords \
–enable-logging=e \
–enable-valias=y \
–enable-ip-alias-domains=y

make
make install-strip

echo ‘127.:allow,RELAYCLIENT=””‘ >> /var/vpopmail/etc/tcp.smtp
tcprules /var/vpopmail/etc/tcp.smtp.cdb /var/vpopmail/etc/tcp.smtp.tmp < /var/vpopmail/etc/tcp.smtpVamos adicionar uma entrada no crontab para limpar o open-relay ap?s 30 minutos, ou seja ap?s esse tempo o usu?rio ter? que fazer um pop novamente para poder usar o smtp.crontab -l > /tmp/crontab.vpopmail
echo “30 * * * * /var/vpopmail/bin/clearopensmtp >/dev/null 2>&1 ” >> /tmp/crontab.vpopmail
crontab /tmp/crontab.vpopmail -u root
rm /tmp/crontab.vpopmail

Instalando o autorespond

Como o pr?prio nome diz, ele ? um programa que serve para enviar uma resposta autom?tica, definida pelo usu?rio.

cd /usr/src/qmailsource
tar xvzf autorespond-2.0.4.tar.gz
cd autorespond-2.0.4
make
make install

Instalando o ezmlm

ezmlm ? um gerenciador de lista de discurs?es.

cd /usr/src/qmailsource
tar xvzf ezmlm-0.53-idx-0.41.tar.gz
cd ezmlm-0.53-idx-0.41
make
make setup

Instalando o daemontools

O daemontools ? uma cole??o de scripts que serve para gerenciar servi?os em sistemas *UNIX. N? nossa instala??o ele ser? usado para controlar o qmail + vpopmail e o courier-imap.

cd /usr/src/qmailsource
tar xvzf daemontools-0.76.tar.gz
cd admin
mv daemontools-0.76 /usr/local/
chmod 1755 /usr/local/daemontools-0.76
cd /usr/local/daemontools-0.76
patch -p1 < /usr/src/qmailsource/patches/daemontools-0.76.errno.patch
sh package/install

Instalando o Courier-imap

courier-imap ? um excelente servidor pop/imap. Foi feito para ser usado com o qmail, e tem total compatibilidade com o vpopmail.

cd /usr/src/qmailsource
tar xvjf courier-imap-3.0.7.tar.bz2

cd courier-imap-3.0.7
./configure –without-authuserdb \
–without-authpam \
–without-authpwd \
–without-authshadow \
–without-authldap \
–without-authdaemon \
–disable-root-check \
–with-authvchkpw \
–with-mailuser=vpopmail \
–with-mailgroup=vchkpw \
–disable-root-check \
–enable-workarounds-for-imap-client-bugs
make
make install-strip
make install-configure

mkdir -p /var/qmail/supervise/courier-imapd/log

Vamos agora criar os scripts para inicializar o courier-imap, ent?o crie o arquivo /var/qmail/supervise/courier-imapd/run com o seguinte conte?do:

—————————–inicia-aqui—————————–

#!/bin/sh
UIDVPOP=`id -u vpopmail`
GIDVPOP=`id -g vpopmail`
exec /usr/local/bin/softlimit -m 5000000 /usr/local/bin/tcpserver -v -R -H \
-l 0 -u $UIDVPOP -g $GIDVPOP -c 20 0 imap \
/usr/lib/courier-imap/sbin/imaplogin \
/usr/lib/courier-imap/libexec/authlib/authvchkpw \
/usr/lib/courier-imap/bin/imapd Maildir 2>&1

—————————termina-aqui—————————–

crie o arquivo /var/qmail/supervise/courier-imapd/log/run com o seguinte conte?do:

—————————–inicia-aqui—————————–

#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/courier-imapd

—————————termina-aqui—————————–

E para finalizar a instala??o do courier-imap:

chmod 755 /var/qmail/supervise/courier-imapd/run
chmod 755 /var/qmail/supervise/courier-imapd/log/run
mkdir -p /var/log/qmail/courier-imapd
chown qmaill.nofiles /var/log/qmail/courier-imapd
ln -s /var/qmail/supervise/courier-imapd /service

Instalando o qmailadmin

Qmailadmin ? uma interface web para a administra??o dos usu?rios do seu dom?nio, ou seja atrav?s dele voc? pode adicionar e remover usu?rios, mudar senhas, criar aliases (apelidos). etc.

Obs: ? necess?rio ter um servidor web para poder usar o qmailadmin. Favor instalar o apache. 🙂

cd /usr/src/qmailsource

tar xvzf qmailadmin-1.2.1.tar.gz
cd qmailadmin-1.2.1
./configure –enable-htmldir=/var/www/htdocs \
–enable-cgibindir=/var/www/cgi-bin \
–enable-modify-quota \
–enable-domain-autofill
make
make install-strip

Agora iremos criar o qmailctl, o site Life With Qmail disponibiliza este script, s? que o nosso qmailctl, est? alterado para iniciar o vpopmail e o courier-imap. Ent?o crie o arquivo qmailctl dentro do diret?rio /var/qmail/bin com o seguinte conte?do:

—————————–inicia-aqui—————————–

#!/bin/sh

# description: the qmail MTA

PATH=/var/qmail/bin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin
export PATH

QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`

case “$1” in
start)
echo “Starting qmail”
if svok /service/qmail-send ; then
svc -u /service/qmail-send
else
echo qmail-send supervise not running
fi
if svok /service/qmail-smtpd ; then
svc -u /service/qmail-smtpd
else
echo qmail-smtpd supervise not running
fi
if [ -d /var/lock/subsys ]; then
touch /var/lock/subsys/qmail
fi
if svok /service/qmail-pop3d ; then
svc -u /service/qmail-pop3d
else
echo qmail-pop3d supervise not running
fi
if svok /service/courier-imapd ; then
svc -u /service/courier-imapd
else
echo courier-courier-imapd supervise not running
fi
;;
stop)
echo “Stopping qmail…”
echo ” qmail-smtpd”
svc -d /service/qmail-smtpd
echo ” qmail-send”
svc -d /service/qmail-send
if [ -f /var/lock/subsys/qmail ]; then
rm /var/lock/subsys/qmail
fi
echo ” qmail-pop3d”
svc -d /service/qmail-pop3d
echo ” courier-courier-imapd”
svc -d /service/courier-imapd
;;
stat)
svstat /service/qmail-send
svstat /service/qmail-send/log
svstat /service/qmail-smtpd
svstat /service/qmail-smtpd/log
svstat /service/qmail-pop3d
svstat /service/qmail-pop3d/log
svstat /service/courier-imapd
svstat /service/courier-imapd/log
qmail-qstat
;;
doqueue|alrm|flush)
echo “Flushing timeout table and sending ALRM signal to qmail-send.”
/var/qmail/bin/qmail-tcpok
svc -a /service/qmail-send
;;
queue)
qmail-qstat
qmail-qread
;;
reload|hup)
echo “Sending HUP signal to qmail-send.”
svc -h /service/qmail-send
;;
pause)
echo “Pausing qmail-send”
svc -p /service/qmail-send
echo “Pausing qmail-smtpd”
svc -p /service/qmail-smtpd
echo “Pausing qmail-pop3d”
svc -p /service/qmail-pop3d
echo “Pausing courier-courier-imapd”
svc -p /service/courier-imapd
;;
cont)
echo “Continuing qmail-send”
svc -c /service/qmail-send
echo “Continuing qmail-smtpd”
svc -c /service/qmail-smtpd
echo “Continuing qmail-pop3d”
svc -c /service/qmail-pop3d
echo “Continuing courier-courier-imapd”
svc -c /service/courier-imapd
;;
restart)
echo “Restarting qmail:”
echo “* Stopping qmail-smtpd.”
svc -d /service/qmail-smtpd
echo “* Sending qmail-send SIGTERM and restarting.”
svc -t /service/qmail-send
echo “* Restarting qmail-smtpd.”
svc -u /service/qmail-smtpd
echo “* Restarting qmail-pop3d.”
svc -t /service/qmail-pop3d
echo “* Restarting courier-courier-imapd.”
svc -t /service/courier-imapd
;;
cdb)
tcprules /var/vpopmail/etc/tcp.smtp.cdb /var/vpopmail/etc/tcp.smtp.tmp < /var/vpopmail/etc/tcp.smtp
chmod 644 /var/vpopmail/etc/tcp.smtp.cdb
echo “Reloaded /var/vpopmail/etc/tcp.smtp.”
;;
help)
cat < 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 — schedules queued messages for immediate 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

—————————termina-aqui—————————–

Dando permiss?o de execu??o e fazendo o link para o qmailctl:

chmod 755 /var/qmail/bin/qmailctl
ln -sf /var/qmail/bin/qmailctl /usr/sbin

Vamor agora criar os scripts para inicializar o qmail:

crie o arquivo /var/qmail/rc com o seguinte conte?do:

—————————-inicia-aqui—————————–

#!/bin/sh

# Using stdout for logging
# Using control/defaultdelivery from qmail-local to deliver messages by default

exec env – PATH=”/var/qmail/bin:$PATH” \
qmail-start “`cat /var/qmail/control/defaultdelivery`”

—————————termina-aqui—————————–

Dando permiss?o de execu??o:

chmod 755 /var/qmail/rc

Definindo qual o tipo de caixa de mensagem que iremos usar:

echo “./Maildir” > /var/qmail/control/defaultdelivery

Criando os diret?rios necess?rios:

mkdir -p /var/qmail/supervise/qmail-send/log
mkdir -p /var/qmail/supervise/qmail-smtpd/log
mkdir -p /var/qmail/supervise/qmail-pop3d/log
mkdir -p /var/log/qmail/smtpd
mkdir -p /var/log/qmail/pop3d

Crie o arquivo /var/qmail/supervise/qmail-send/run com o conte?do:

—————————-inicia-aqui—————————–

#!/bin/sh
exec /var/qmail/rc

—————————termina-aqui—————————–

Agora crie o arquivo /var/qmail/supervise/qmail-send/log/run com o conte?do:

—————————-inicia-aqui—————————–

#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail

—————————termina-aqui—————————–

crie o arquivo /var/qmail/supervise/qmail-smtpd/run com o conte?do:

—————————-inicia-aqui—————————–

#!/bin/sh

QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`
MAXSMTPD=`cat /var/qmail/control/concurrencyincoming`
LOCAL=`head -1 /var/qmail/control/me`

if [ -z “$QMAILDUID” -o -z “$NOFILESGID” -o -z “$MAXSMTPD” -o -z “$LOCAL” ]; then
echo QMAILDUID, NOFILESGID, MAXSMTPD, or LOCAL is unset in
echo /var/qmail/supervise/qmail-smtpd/run
exit 1
fi

if [ ! -f /var/qmail/control/rcpthosts ]; then
echo “No /var/qmail/control/rcpthosts!”
echo “Refusing to start SMTP listener because it’ll create an open relay”
exit 1
fi

exec /usr/local/bin/softlimit -m 5000000 \
/usr/local/bin/tcpserver -v -R -l “$LOCAL” -x /var/vpopmail/etc/tcp.smtp.cdb -c “$MAXSMTPD” \
-u “$QMAILDUID” -g “$NOFILESGID” 0 smtp /var/qmail/bin/qmail-smtpd 2>&1

—————————termina-aqui—————————–

crie o arquivo /var/qmail/supervise/qmail-smtpd/log/run com o conte?do:

—————————-inicia-aqui—————————–

#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/smtpd

—————————termina-aqui—————————–

crie o arquivo /var/qmail/supervise/qmail-pop3d/run com o conte?do:

—————————-inicia-aqui—————————–

#!/bin/sh
DOMAIN=`cat /etc/qmail/defaultdomain`
exec /usr/local/bin/softlimit -m 5000000 \
/usr/local/bin/tcpserver -v -R -H -l 0 0 110 /var/qmail/bin/qmail-popup \
$DOMAIN /var/vpopmail/bin/vchkpw /var/qmail/bin/qmail-pop3d Maildir 2>&1

—————————termina-aqui—————————–

Crie o arquivo /var/qmail/supervise/qmail-pop3d/log/run com o conte?do:

—————————-inicia-aqui—————————–

#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/pop3d

—————————termina-aqui—————————–

e para finalizar:

echo 20 > /var/qmail/control/concurrencyincoming
chmod 644 /var/qmail/control/concurrencyincoming
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
chmod 755 /var/qmail/supervise/qmail-pop3d/run
chmod 755 /var/qmail/supervise/qmail-pop3d/log/run
chown qmaill /var/log/qmail /var/log/qmail/smtpd /var/log/qmail/pop3d
echo 30 > /var/qmail/control/tarpitcount
echo 60 > /var/qmail/control/tarpitdelay
ln -s /var/qmail/supervise/qmail-send /var/qmail/supervise/qmail-smtpd /var/qmail/supervise/qmail-pop3d /service

Pronto, agora voc? tem um excelente servidor de email configurado.

Para adicionar o dom?nio entre no diret?rio /var/vpopmail/bin e digite:

./vadddomain dominio.com.br

o resultado ser?:

[email protected]:/var/vpopmail/bin# ./vadddomain linuxti.pro.br
Please enter password for postmaster:
enter password again:

Agora que seu dom?nio est? criado, basta apenas adicionar os usu?rios. Caso queira usar o qmailadmin para cadastr?-los, pois com ele ? muito mais f?cil e c?modo, pois tem uma interface simples e amig?vel. ent?o digite no seu browser:

http://ip_do_servidor/cgi-bin/qmailadmin

Vai aparecer a tela inicial do qmailadmin, ae ? s? preencher os dados e adicionar os usu?rios.

Para configurar a conta nos clientes de email outlook, evolution, thunderbird, etc. Voc? tem que colocar o nome do [email protected], pois a autentica??o ? feita assim.

Fiz tamb?m um script que faz toda esta instala??o de forma autom?tica, para baix?-lo v? na sess?o scripts e fa?a o download ou clique aqui.

Espero ter ajudado,

Cl?udio Borges

[email protected]

www.linuxti.pro.br