Linux Mail

qmail + vpopmail + mysql 설치

2009.05.12 23:27

HOSTWAY 조회 수:22988

qmail + vpopmail + mysql 설치

이용되는 파일들은 cr.yp.to 등에서 다운로드한다.
qmail-1.03.tar.gz
autorespond-2.0.2.tar.gz
ucspi-tcp-0.88.tar.gz
daemontools-0.76.tar.gz
rblsmtpd-0.70.tgz
vpopmail-5.4.10.tar.gz

# 각각의 소스의 error.h 파일의 상단에 아래 라인을 추가합니다.

#include "errno.h"

1. sendmail 구동을 종료
[root@localhost root]# /etc/init.d/sendmail stop

2. qmail 설치
[root@localhost root]# tar zxvf qmail-1.03.tar.gz
[root@localhost root]# cd qmail-1.03
[root@localhost root]# mkdir /var/qmail
[root@localhost root]# groupadd nofiles
[root@localhost root]# useradd -g nofiles -d /var/qmail/alias alias
[root@localhost root]# useradd -g nofiles -d /var/qmail qmaild
[root@localhost root]# useradd -g nofiles -d /var/qmail qmaill
[root@localhost root]# useradd -g nofiles -d /var/qmail qmailp
[root@localhost root]# groupadd qmail
[root@localhost root]# useradd -g qmail -d /var/qmail qmailq
[root@localhost root]# useradd -g qmail -d /var/qmail qmailr
[root@localhost root]# useradd -g qmail -d /var/qmail qmails
[root@localhost root]# cp -a /usr/local/mysql/include/mysql /usr/include
[root@localhost root]# cp /usr/local/mysql/lib/mysql/* /usr/lib
[root@localhost root]# mkdir /usr/lib/mysql/
[root@localhost root]# ln -s /usr/lib/libmysqlclient.a /usr/lib/mysql/libmysqlclient.a
[root@localhost root]# make
[root@localhost root]# make setup check
[root@localhost root]# ./config-fast hostway.co.kr

[root@localhost root]# cd ../
[root@localhost root]# tar xzvf ucspi-tcp-0.88.tar.gz
[root@localhost root]# cd ucspi-tcp-0.88
[root@localhost root]# make
[root@localhost root]# make setup check

[root@localhost root]# cd ../
[root@localhost root]# mkdir -p /package
[root@localhost root]# chmod 1755 /package
[root@localhost root]# tar zxvf daemontools-0.76.tar.gz
[root@localhost root]# mv admin/ /package/
[root@localhost root]# cd /package/admin/daemontools-0.76/
[root@localhost root]# ./package/install

[root@localhost root]# cd ~
[root@localhost root]# tar zxvf autorespond-2.0.2.tar.gz
[root@localhost root]# cd autorespond-2.0.2
[root@localhost root]# make
[root@localhost root]# cp autorespond /usr/local/bin/

[root@localhost root]# vi /var/qmail/rc
    #!/bin/sh
    exec env - PATH="/var/qmail/bin:$PATH"
    qmail-start ./Maildir/


[root@localhost root]# chmod a+x /var/qmail/rc
[root@localhost root]# mkdir -p /var/qmail/supervise/qmail-send/log
[root@localhost root]# mkdir -p /var/qmail/supervise/qmail-smtpd/log
[root@localhost root]# chmod +t /var/qmail/supervise/qmail-send
[root@localhost root]# chmod +t /var/qmail/supervise/qmail-smtpd
[root@localhost root]# vi /var/qmail/supervise/qmail-send/run
    #!/bin/sh
    exec /var/qmail/rc


[root@localhost root]# 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@localhost root]# vi /var/qmail/supervise/qmail-smtpd/run
    #!/bin/sh
    Q_UID=`id -u vpopmail`
    Q_GID=`id -g vpopmail`
    exec /usr/local/bin/softlimit -m 8000000
          /usr/local/bin/tcpserver -vRHl 0
          -x /home/vpopmail/etc/tcp.smtp.cdb
          -u $Q_UID -g $Q_GID 0 25 /var/qmail/bin/qmail-smtpd hostway.co.kr
          /home/vpopmail/bin/vchkpw /bin/true 2>&1

[root@localhost root]# 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@localhost root]# chmod 755 /var/qmail/supervise/qmail-send/run
[root@localhost root]# chmod 755 /var/qmail/supervise/qmail-send/log/run
[root@localhost root]# chmod 755 /var/qmail/supervise/qmail-smtpd/run
[root@localhost root]# chmod 755 /var/qmail/supervise/qmail-smtpd/log/run
[root@localhost root]# mkdir -p /var/log/qmail/smtpd
[root@localhost root]# chown qmaill /var/log/qmail /var/log/qmail/smtpd
[root@localhost root]# echo admin@hostway.co.kr > /var/qmail/alias/.qmail-root
[root@localhost root]# echo admin@hostway.co.kr > /var/qmail/alias/.qmail-postmaster
[root@localhost root]# echo admin@hostway.co.kr > /var/qmail/alias/.qmail-mailer-daemon
[root@localhost root]# cd /var/qmail/alias/
[root@localhost root]# chmod 644 .qmail-root .qmail-postmaster .qmail-mailer-daemon

[root@localhost root]# vi /etc/init.d/qmail
#!/bin/sh

# For Red Hat chkconfig
# chkconfig: - 80 30
# description: the qmail MTA

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

case "$1" in
  start)
    echo "Starting qmail"
     if [ -e /service/qmail-send ] ; then
         if svok /service/qmail-send ; then
            svc -u /service/qmail-send
        else
            echo qmail-send supervise not running
        fi
     else
         ln -s /var/qmail/supervise/qmail-send /service/
     fi

     if [ -e /service/qmail-smtpd ] ; then
         if svok /service/qmail-smtpd ; then
            svc -u /service/qmail-smtpd
        else
            echo qmail-smtpd supervise not running
        fi
     else
         ln -s /var/qmail/supervise/qmail-smtpd /service/
     fi
     
    if [ -d /var/lock/subsys ]; then
      touch /var/lock/subsys/qmail
    fi
   killall readproctitle > /dev/null 2>&1
    ;;
  stop)
    echo "Stopping qmail..."
    echo "  qmail-smtpd"
    svc -dx /service/qmail-smtpd /service/qmail-smtpd/log
     rm -f /service/qmail-smtpd
    echo "  qmail-send"
    svc -dx /service/qmail-send /service/qmail-send/log
     rm -f /service/qmail-send
    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
    echo "* Sending qmail-send SIGTERM and restarting."
    svc -t /service/qmail-send
    echo "* Restarting qmail-smtpd."
    svc -u /service/qmail-smtpd
    ;;
  cdb)
    tcprules /home/vpopmail/etc/tcp.smtp.cdb /home/vpopmail/etc/tcp.smtp.tmp < /home/vpopmail/etc/tcp.smtp
    chmod 644 /home/vpopmail/etc/tcp.smtp.cdb
    echo "Reloaded /home/vpopmail/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@localhost root]# chmod 700 /etc/init.d/qmail
[root@localhost root]# chkconfig --add qmail

3. vpopmail 설치
[root@localhost root]# groupadd vchkpw
[root@localhost root]# useradd -g vchkpw vpopmail
[root@localhost root]# cd ~
[root@localhost root]# tar zxvf vpopmail-5.4.10.tar.gz
[root@localhost root]# cd vpopmail-5.4.10
[root@localhost root]# ./configure --enable-auth-module=mysql --enable-tcprules-prog=/usr/local/bin/tcprules --enable-relay-clear-minutes=15
[root@localhost root]# make
[root@localhost root]# make install-strip
[root@localhost root]# vi ~vpopmail/etc/defaultdomain
hostway.co.kr

[root@localhost root]# vi ~vpopmail/etc/vpopmail.mysql
localhost|0|root|패스워드|vpopmail

[root@localhost root]# echo "127.0.0.1:allow,RELAYCLIENT=""" > ~vpopmail/etc/tcp.smtp
[root@localhost root]# echo "qmail을설치한서버의아이피:allow,RELAYCLIENT=""" >> ~vpopmail/etc/tcp.smtp
[root@localhost root]# mkdir /var/qmail/supervise/vpop
[root@localhost root]# vi /var/qmail/supervise/vpop/run
    #!/bin/sh
    VPOP_UID=`id -u vpopmail`
    VPOP_GID=`id -g vpopmail`

    exec /usr/local/bin/softlimit -m 5000000
         tcpserver -vRHl 0 -u $VPOP_UID -g $VPOP_GID 0 110
         /var/qmail/bin/qmail-popup hostway.co.kr
         /home/vpopmail/bin/vchkpw /var/qmail/bin/qmail-pop3d Maildir 2>&1

[root@localhost root]# chmod 755 /var/qmail/supervise/vpop/run
[root@localhost root]# mv /usr/lib/sendmail /usr/lib/sendmail.old
[root@localhost root]# mv /usr/sbin/sendmail /usr/sbin/sendmail.old
[root@localhost root]# ln -s /var/qmail/bin/sendmail /usr/lib
[root@localhost root]# ln -s /var/qmail/bin/sendmail /usr/sbin
[root@localhost root]# ln -s /var/qmail/supervise/qmail-send /service/
[root@localhost root]# ln -s /var/qmail/supervise/qmail-smtpd /service/
[root@localhost root]# ln -s /var/qmail/supervise/vpop /service

[root@localhost root]# /etc/init.d/qmail cdb
[root@localhost root]# /etc/init.d/qmail start

예) 기본 도메인에 사용자 추가
[root@localhost root]# cd /home/vpopmail/bin
[root@localhost root]# ./vadduser admin@hostway.co.kr

예) 새로운 도메인을 추가
[root@localhost root]# ./vadddomain hostway2.co.kr