본문 바로가기

리눅스

[리눅스] Qmail Install 메일서버

728x90

Qmail Install 메일서버

Qmail 관련 소스 다운로드

# qmail
$ wget http://www.qmail.org/netqmail-1.06.tar.gz

# ucspi-tcp
$ wget http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz

#daemontools
$ wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz

$ wget http://www.lug.or.kr/files/centos_book/qmail/qmail-date-localtime.patch

$ wget http://inoa.net/qmail-tls/netqmail-1.06-tls-20110119.patch

Sendmail 서비스 종료

[root@sangchul netqmail-1.05]$ /etc/init.d/saslauthd stop
saslauthd 를 정지 중:                                      [실패]

[root@sangchul netqmail-1.05]$ chkconfig --del

[root@sangchul netqmail-1.05]$ chkconfig --list | grep saslauthd
saslauthd       0:off   1:off   2:off   3:off   4:off   5:off   6:off

[root@sangchul netqmail-1.05]$ chkconfig --del saslauthd

[root@sangchul netqmail-1.05]$ chkconfig --list | grep saslauthd

[root@sangchul netqmail-1.05]$

[root@sangchul netqmail-1.05]$ chkconfig --list | grep dovecot
dovecot         0:off   1:off   2:off   3:off   4:off   5:off   6:off

[root@sangchul netqmail-1.05]$ chkconfig --del dovecot

[root@sangchul netqmail-1.05]$ chkconfig --list | grep dovecot

[root@sangchul netqmail-1.05]$

[root@sangchul netqmail-1.05]$ /etc/init.d/sendmail stop
sm-client을 종료 중:                                       [  OK  ]
sendmail를 종료 중:                                       [  OK  ]

ucspi-tcp 설치

[root@sangchul qmail]$ tar xvfz ucspi-tcp-0.88.tar.gz

[root@sangchul qmail]$ cd ucspi-tcp-0.88

[root@sangchul ucspi-tcp-0.88]$ patch -p1 < /usr/local/src/qmail/netqmail-1.05/other-patches/ucspi-tcp-0.88.errno.patch

[root@sangchul ucspi-tcp-0.88]$ patch -p1 < /usr/local/src/qmail/netqmail-1.05/other-patches/ucspi-tcp-0.88.a_record.patch

[root@sangchul ucspi-tcp-0.88]$ patch -p1 < /usr/local/src/qmail/netqmail-1.05/other-patches/ucspi-tcp-0.88.nodefaultrbl.patch

[root@sangchul ucspi-tcp-0.88]$ make

[root@sangchul ucspi-tcp-0.88]$ make setup check

daemontools 설치

[root@sangchul ucspi-tcp-0.88]$ cd ..

[root@sangchul qmail]$ mkdir -p /package

[root@sangchul qmail]$ chmod 1755 /package/

[root@sangchul qmail]$ tar xvfz daemontools-0.76.tar.gz -C /package/

[root@sangchul qmail]$ cd /package/admin/daemontools-0.76/

[root@sangchul daemontools-0.76]$ vi src/error.h
/- Public domain. *-
#include <errno.h>                  <<<<< 추가
#ifndef ERROR_H
#define ERROR_H

[root@sangchul daemontools-0.76]$ package/install

qmail 설치

[root@sangchul daemontools-0.76]# cd /usr/local/src/qmail/netqmail-1.05

[root@sangchul netqmail-1.05]$ mkdir /var/qmail

[root@sangchul netqmail-1.05]$ ./collate.sh

[root@sangchul netqmail-1.05]$ cd netqmail-1.05

[root@sangchul netqmail-1.05]$ groupadd nofiles

[root@sangchul netqmail-1.05]$ useradd -g nofiles -d /var/qmail/alias alias

[root@sangchul netqmail-1.05]$ useradd -M -g nofiles -d /var/qmail qmaild

[root@sangchul netqmail-1.05]$ useradd -M -g nofiles -d /var/qmail qmaill

[root@sangchul netqmail-1.05]$ useradd -M -g nofiles -d /var/qmail qmailp

[root@sangchul netqmail-1.05]$ groupadd qmail

[root@sangchul netqmail-1.05]$ useradd -M -g qmail -d /var/qmail qmailq

[root@sangchul netqmail-1.05]$ useradd -M -g qmail -d /var/qmail qmailr

[root@sangchul netqmail-1.05]$ useradd -M -g qmail -d /var/qmail qmails

[root@sangchul netqmail-1.05]$ patch -p1 < /usr/local/src/qmail/qmail-date-localtime.patch

[root@sangchul netqmail-1.05]$ patch -p0 < /usr/local/src/qmail/netqmail-1.05-tls-smtpauth-20070417.patch

[root@sangchul netqmail-1.05]$ make

[root@sangchul netqmail-1.05]$ make setup check

[root@sangchul netqmail-1.05]$ make cert
Generating a 1024 bit RSA private key
.............++++++
..........++++++
writing new private key to '/var/qmail/control/servercert.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:KR
State or Province Name (full name) [Berkshire]:Seoul
Locality Name (eg, city) [Newbury]:guro-gu
Organization Name (eg, company) [My Company Ltd]:sangchul_home
Organizational Unit Name (eg, section) []:lab
Common Name (eg, your name or your server's hostname) []:sangchul.kr
Email Address []:anti1346@sangchul.kr

[root@sangchul netqmail-1.05]$

[root@sangchul netqmail-1.05]$ make tmprsadh

[root@sangchul netqmail-1.05]$ ./config-fast mail.sangchul.kr

supervise script 작성

[root@sangchul netqmail-1.05]$ vi /var/qmail/rc
#!/bin/sh
# Using splogger to send the log through syslog.
# Using qmail-local to deliver messages to ~/Maildir/ by default.

exec env - PATH="/var/qmail/bin:$PATH" \

qmail-start ./Maildir/ splogger qmail
[root@sangchul netqmail-1.05]$ chmod 755 /var/qmail/rc

[root@sangchul netqmail-1.05]$ mkdir -p /var/qmail/supervise/qmail-send/log

[root@sangchul netqmail-1.05]$ mkdir -p /var/qmail/supervise/qmail-smtpd/log

[root@sangchul netqmail-1.05]$ chmod +t /var/qmail/supervise/qmail-send

[root@sangchul netqmail-1.05]$ chmod +t /var/qmail/supervise/qmail-smtpd
[root@sangchul netqmail-1.05]$ vi /var/qmail/supervise/qmail-send/run
#!/bin/sh

exec /var/qmail/rc
[root@sangchul netqmail-1.05]$ vi /var/qmail/supervise/qmail-send/log/run
#!/bin/sh

exec /usr/local/bin/setuidgid qmaill \
     /usr/local/bin/multilog t /var/log/qmail
[root@sangchul netqmail-1.05]$ vi /var/qmail/supervise/qmail-smtpd/run
#!/bin/sh

Q_UID=`id -u qmaild`
Q_GID=`id -g qmaild`

exec /usr/local/bin/softlimit -m 20000000 \
     /usr/local/bin/tcpserver -vRHl 0 -x /etc/tcp.smtp.cdb \
     -u $Q_UID -g $Q_GID 0 25 /var/qmail/bin/qmail-smtpd 2>&1
[root@sangchul netqmail-1.05]$ vi /var/qmail/supervise/qmail-smtpd/log/run
#!/bin/sh

exec /usr/local/bin/setuidgid qmaill \
     /usr/local/bin/multilog t /var/log/qmail/smtpd
[root@sangchul netqmail-1.05]$ chmod 755 /var/qmail/supervise/qmail-send/run

[root@sangchul netqmail-1.05]$ chmod 755 /var/qmail/supervise/qmail-send/log/run

[root@sangchul netqmail-1.05]$ chmod 755 /var/qmail/supervise/qmail-smtpd/run

[root@sangchul netqmail-1.05]$ chmod 755 /var/qmail/supervise/qmail-smtpd/log/run

[root@sangchul netqmail-1.05]$ mkdir -p /var/log/qmail/smtpd

[root@sangchul netqmail-1.05]$ chown qmaill /var/log/qmail /var/log/qmail/smtpd
[root@sangchul netqmail-1.05]$ vi /etc/tcp.smtp
127.0.0.1:allow,RELAYCLIENT=""
192.168.0.100:allow,RELAYCLIENT=""
[root@sangchul netqmail-1.05]$ tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp

qmailctl script 작성

[root@sangchul netqmail-1.05]$ vi /etc/rc.d/init.d/qmail
#!/bin/sh
# For RedHat chkconfig
# chkconfig: - 80 30
# 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 /service/qmail-send/log
    else
      echo "qmail-send supervise not running"
    fi
    if svok /service/qmail-smtpd ; then
      svc -u /service/qmail-smtpd /service/qmail-smtpd/log
    else
      echo "qmail-smtpd supervise not running"
    fi
    if [ -d /var/lock/subsys ]; then
      touch /var/lock/subsys/qmail
    fi
    ;;
  stop)
    echo "Stopping qmail..."
    echo "  qmail-smtpd"
    svc -d /service/qmail-smtpd /service/qmail-smtpd/log
    echo "  qmail-send"
    svc -d /service/qmail-send /service/qmail-send/log
    if [ -f /var/lock/subsys/qmail ]; then
      rm /var/lock/subsys/qmail
    fi
    ;;
  stat)
    svstat /service/qmail-send
    svstat /service/qmail-send/log
    svstat /service/qmail-smtpd
    svstat /service/qmail-smtpd/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
    ;;
  cont)
    echo "Continuing qmail-send"
    svc -c /service/qmail-send
    echo "Continuing qmail-smtpd"
    svc -c /service/qmail-smtpd
    ;;
  restart)
    echo "Restarting qmail:"
    echo "* Stopping qmail-smtpd."
    svc -d /service/qmail-smtpd /service/qmail-smtpd/log
    echo "* Sending qmail-send SIGTERM and restarting."
    svc -t /service/qmail-send /service/qmail-send/log
    echo "* Restarting qmail-smtpd."
    svc -u /service/qmail-smtpd /service/qmail-smtpd/log
    ;;
  cdb)
    tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp
    chmod 644 /etc/tcp.smtp.cdb
    echo "Reloaded /etc/tcp.smtp."
    ;;
  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 -- 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
[root@sangchul netqmail-1.05]$ chmod 755 /etc/rc.d/init.d/qmail

[root@sangchul netqmail-1.05]$ chkconfig --add qmail

[root@sangchul netqmail-1.05]$ chkconfig --level 35 qmail on

[root@sangchul netqmail-1.05]$ chkconfig --list|grep qmail
qmail           0:off   1:off   2:off   3:on    4:off   5:on    6:off

[root@sangchul netqmail-1.05]$ mv /usr/lib/sendmail /usr/lib/sendmail.org

[root@sangchul netqmail-1.05]$ mv /usr/sbin/sendmail /usr/sbin/sendmail.org

[root@sangchul netqmail-1.05]$ ln -s /var/qmail/bin/sendmail /usr/lib

[root@sangchul netqmail-1.05]$ ln -s /var/qmail/bin/sendmail /usr/sbin

[root@sangchul netqmail-1.05]$ echo master > /var/qmail/alias/.qmail-root

[root@sangchul netqmail-1.05]$ echo master > /var/qmail/alias/.qmail-postmaster

[root@sangchul netqmail-1.05]$ echo master > /var/qmail/alias/.qmail-mailer-daemon

[root@sangchul netqmail-1.05]$ chmod 644 /var/qmail/alias/.qmail*

[root@sangchul netqmail-1.05]$ /var/qmail/bin/maildirmake /etc/skel/Maildir

[root@sangchul netqmail-1.05]$ /etc/rc.d/init.d/qmail start
Starting qmail

Test the Installation

[root@sangchul netqmail-1.05]$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 mail.sangchul.kr ESMTP
728x90