본문 바로가기

Compute™/Linux

[Linux] CentOS + Qmail + vpopmail + mysql + imap + squirrelmail - 1 -

반응형
SMALL
[참고]
- 사 이 트 : http://linux.tini4u.net/

참조 : 김혁중(티니) 님의 knetqmail-1.06 설치 메뉴얼 을 참고 하시기 바랍니다.



[설치환경]
OS : CentOS 5.4  i386

[사전 필요 패키지 설치]
yum -y install gcc glibc-devel glibc-headers glibc-kernheaders cpp glibc glibc-common libgcc
yum -y install openssl openssl-devel

[sendmail 삭제]
/etc/rc.d/init.d/saslauthd stop;
/etc/rc.d/init.d/sendmail stop;
chkconfig --del saslauthd;
chkconfig --del sendmail ;
rpm -e --nodeps sendmail

[1. ucspi-tcp 0.88 설치]
 cd /var/tmp
wget http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
wget http://djbware.csi.hu/patches/ucspi-tcp-0.88.errno.patch
tar xfz ucspi-tcp-0.88.tar.gz
cd ucspi-tcp-0.88
patch -p1 < ../ucspi-tcp-0.88.errno.patch
echo "/usr/local" > conf-home
make
make setup check


[2. daemontools-0.76 설치]
설치 후 ps -ef |grep scan    또는 pstree 를 통해 해당 프로세스 확인
rroot      4231     1  0 14:40 ?        00:00:00 /bin/sh /command/svscanboot
root      4233  4231  0 14:40 ?        00:00:00 svscan /service

cd /var/tmp
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
wget http://djbware.csi.hu/patches/daemontools-0.76.errno.patch
tar xfz daemontools-0.76.tar.gz
cd admin/daemontools-0.76
patch -p1 < ../../daemontools-0.76.errno.patch
echo "/usr/local" > src/home
make -C src

mkdir /service /command
for i in `cat package/commands`; do cp -a src/$i /usr/local/bin/$i; done
for i in `cat package/commands`; do ln -sfv /usr/local/bin/$i /command/$i; done

echo "SV:345:respawn:/command/svscanboot" >> /etc/inittab
pkill -1 init



[3. 계정 및 그룹 생성]
groupadd -r nofiles
groupadd -r qmail
groupadd -r vchkpw

useradd -r -M -d /var/qmail/alias -s /sbin/nologin -c "qmail alias" -g qmail alias
useradd -r -M -d /var/qmail -s /sbin/nologin -c "qmail daemon" -g qmail qmaild
useradd -r -M -d /var/qmail -s /sbin/nologin -c "qmail logger" -g qmail qmaill
useradd -r -M -d /var/qmail -s /sbin/nologin -c "qmail passwd" -g qmail qmailp
useradd -r -M -d /var/qmail -s /sbin/nologin -c "qmail queue" -g qmail qmailq
useradd -r -M -d /var/qmail -s /sbin/nologin -c "qmail remote" -g qmail qmailr
useradd -r -M -d /var/qmail -s /sbin/nologin -c "qmail send" -g qmail qmails
useradd -r -M -d /home/vpopmail -s /sbin/nologin -c "Vpopmail User" -g vchkpw vpopmail


[4. vpopmail 5.4.30 설치]
* 설치 전 mysql 설치 필수 cdb를 이용할 경우 상관 없지만
mysql 을 연동하여 사용할 경우 mysql 설치가 먼저 되어 있어야 하므로
게시판에 mysql 설치편을 참조.
* configure 시에
--enable-incdir=/usr/include/mysql
--enable-libdir=/usr/lib/mysql
위 부분에서 mysql 설치된 위치를 지정하여야 한다.
현재 시스템에서는 /usr/local/mysql 에 설치가 되어 있으므로
--enable-incdir=/usr/local/mysql/include/mysql \
--enable-libdir=/usr/local/mysql/lib/mysql

mkdir -p /var/qmail/bin
touch /var/qmail/bin/qmail-newu
touch /var/qmail/bin/qmail-inject
touch /var/qmail/bin/qmail-newmrh

cd /var/tmp
wget http://cdnetworks-kr-2.dl.sourceforge.net/project/vpopmail/vpopmail-stable/5.4.30/vpopmail-5.4.30.tar.gz
tar xfz vpopmail-5.4.30.tar.gz
cd vpopmail-5.4.30

./configure \
--prefix=/home/vpopmail \
--enable-vpopuser=vpopmail \
--enable-vpopgroup=vchkpw \
--enable-tcprules-prog=/usr/local/bin/tcprules \
--enable-tcpserver-file=/etc/tcprules.d/tcp.smtp \
--disable-users-big-dir \
--enable-qmail-ext \
--enable-domainquotas \
--enable-logging=v \
--enable-log-name=vpopmail \
--enable-valias \
--disable-many-domains \
--enable-auth-module=mysql \
--enable-incdir=/usr/local/mysql/include/mysql \
--enable-libdir=/usr/local/mysql/lib/mysql

make
make install-strip

rm -rf /var/qmail


[5. libdomainkeys 0.69 설치]

 cd /var/tmp
wget http://cdnetworks-kr-2.dl.sourceforge.net/project/domainkeys/libdomainkeys/0.69/libdomainkeys-0.69.tar.gz
tar xfz libdomainkeys-0.69.tar.gz
mv libdomainkeys-0.69 libdomainkeys
cd libdomainkeys
echo "-lresolv" > dns.lib
make


[6-1. knetqmail 1.06 설치]
*knetqmail은 해당 http://qmail.kldp.net/ 에서 회원 가입 후 직접 다운로드 받도록 하자.

 cd /var/tmp
wget http://.../knetqmail-1.06-20110908.tar.gz
wget http://jeremy.kister.net/code/qmail-dk-0.54-auth.patch
tar xfz knetqmail-1.06-20110908.tar.gz
cd knetqmail-1.06-20110908
patch -p0 < ../qmail-dk-0.54-auth.patch

echo "gcc -O2 -g -DTLS=20070408 -I/usr/include/openssl -I/home/vpopmail/include" > conf-cc
echo "gcc -s -O2 -g" > conf-ld

make
make setup check

cp -a spfquery /var/qmail/bin
cp -a /var/tmp/libdomainkeys/dknewkey /var/qmail/bin
chown root:qmail /var/qmail/bin/spfquery /var/qmail/bin/dknewkey
chmod 755 /var/qmail/bin/spfquery /var/qmail/bin/dknewkey


[6-2. 설정 파일 생성]

 cd /var/qmail/control
touch rcpthosts smtproutes
echo "localhost"       > locals
echo "bestks.co.kr" > me
echo "bestks.co.kr" > defaultdomain
echo "bestks.co.kr" > defaulthost
echo "bestks.co.kr" > plusdomain
echo "60"              > concurrencyremote
echo "100"             > concurrencyincoming
echo "86400"           > queuelifetime
echo "1"               > spfbehavior
echo "Welcome to Qmail SMTP Server" > smtpgreeting
echo "./Maildir/"      > defaultdelivery
chmod 644 *

cd /var/qmail/users
touch cdb
echo "." > assign
chmod 644 *


[6-3. 큐메일 데몬을 위한 디렉토리 및 스크립트 생성]

mkdir -p /var/qmail/supervise
for i in send smtp pop3 submission; do mkdir -p /var/qmail/supervise/$i/log; done

vi /var/qmail/rc

#!/bin/sh

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

vi /var/qmail/supervise/send/run

#!/bin/sh

exec /var/qmail/rc

vi /var/qmail/supervise/send/log/run

#!/bin/sh

exec /usr/local/bin/setuidgid qmaill \
        /usr/local/bin/multilog t /var/log/qmail/send 2>&1

vi /var/qmail/supervise/smtp/run

#!/bin/sh

VPOP_UID=`id -u vpopmail`
VPOP_GID=`id -g vpopmail`

MAXSMTPD=`cat /var/qmail/control/concurrencyincoming`

exec /usr/local/bin/softlimit -m 64000000 \
        /usr/local/bin/tcpserver -vRHl0 \
        -x /etc/tcprules.d/tcp.smtp.cdb \
        -c ${MAXSMTPD} \
        -u ${VPOP_UID} -g ${VPOP_GID} 0 25 \
        /var/qmail/bin/qmail-smtpd \
        /home/vpopmail/bin/vchkpw /bin/true 2>&1

vi /var/qmail/supervise/smtp/log/run

#!/bin/sh

exec /usr/local/bin/setuidgid qmaill \
        /usr/local/bin/multilog t /var/log/qmail/smtp 2>&1

vi /var/qmail/supervise/pop3/run

#!/bin/sh

VPOP_UID=`id -u vpopmail`
VPOP_GID=`id -g vpopmail`

HOSTNAME=`hostname -f`

exec /usr/local/bin/softlimit -m 48000000 \
        /usr/local/bin/tcpserver -vRHl0 \
        -u ${VPOP_UID} -g ${VPOP_GID} 0 110 \
        /var/qmail/bin/qmail-popup ${HOSTNAME} \
        /home/vpopmail/bin/vchkpw \
        /var/qmail/bin/qmail-pop3d Maildir 2>&1

vi /var/qmail/supervise/pop3/log/run

#!/bin/sh

exec /usr/local/bin/setuidgid qmaill \
        /usr/local/bin/multilog t /var/log/qmail/pop3 2>&1

vi /var/qmail/supervise/submission/run

#!/bin/sh

VPOP_UID=`id -u vpopmail`
VPOP_GID=`id -g vpopmail`

MAXSMTPD=`cat /var/qmail/control/concurrencyincoming`

exec /usr/local/bin/softlimit -m 48000000 \
        /usr/local/bin/tcpserver -vRHl0 \
        -x /etc/tcprules.d/tcp.smtp.cdb \
        -c ${MAXSMTPD} \
        -u ${VPOP_UID} -g ${VPOP_GID} 0 587 \
        /var/qmail/bin/qmail-smtpd \
        /home/vpopmail/bin/vchkpw /bin/true 2>&1

vi /var/qmail/supervise/submission/log/run

#!/bin/sh

exec /usr/local/bin/setuidgid qmaill \
        /usr/local/bin/multilog t /var/log/qmail/submission 2>&1



[6-3. tcp.smtp 설정]
mkdir -p /etc/tcprules.d
vi /etc/tcprules.d/tcp.smtp

127.0.0.1:allow,RELAYCLIENT="",CHKUSER_RCPTLIMIT="50",CHKUSER_WRONGRCPTLIMIT="10"
:allow,CHKUSER_RCPTLIMIT="50",CHKUSER_WRONGRCPTLIMIT="10"

tcprules /etc/tcprules.d/tcp.smtp.cdb /etc/tcprules.d/tcp.smtp.tmp < /etc/tcprules.d/tcp.smtp


/etc/init.d/qmaild cdb (cdb 갱신)
Reloaded /etc/tcprules.d/tcp.smtp.



[6-4. qmail log 디렉토리 생성]
for i in send smtp pop3 submission; do mkdir -p /var/log/qmail/$i; done
chmod -R 750 /var/log/qmail
chown -R qmaill:qmail /var/log/qmail


[6-5. qmail 구동 스크립트 생성]
vi /etc/init.d/qmaild

#!/bin/sh
#
# qmaild       This shell script takes care of starting and stopping
#              the qmail system.
#
# chkconfig: - 30 80
# description: qmail is a small, fast, secure replacement for the sendmail package, which is
#              the program that actually receives, routes, and delivers electronic mail.

export PATH="$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/var/qmail/bin"
svclist="send smtp pop3 submission"

case "$1" in
    start)
        echo "Starting qmail"

        for svc in $svclist; do
            if [ -e /service/${svc} ]; then
                if svok /service/${svc}; then
                    svc -u /service/${svc}
                else
                    echo "${svc} supervise not running"
                fi
            else
                ln -s /var/qmail/supervise/${svc} /service/
            fi
        done

        if [ -d /var/lock/subsys ]; then
            touch /var/lock/subsys/qmail
        fi
        ;;
    stop)
        echo "Stopping qmail..."

        for svc in $svclist; do
            if [ -e /service/${svc} ]; then
                echo "  ${svc}"
                svc -dx /service/${svc} /service/${svc}/log
                rm -f /service/${svc}
            fi
        done

        if [ -f /var/lock/subsys/qmail ]; then
            rm -f /var/lock/subsys/qmail
        fi
        ;;
    stat)
        for svc in $svclist; do
            if [ -e /service/${svc} ]; then
                svstat /service/${svc}
                svstat /service/${svc}/log
            fi
        done
        qmail-qstat
        ;;
    doqueue|alrm|flush)
        if [ -e /service/send ]; then
            echo "Flushing timeout table and sending ALRM signal to send."
            /var/qmail/bin/qmail-tcpok
            svc -a /service/send
        fi
        ;;
    queue)
        qmail-qstat
        qmail-qread
        ;;
    reload|hup)
        if [ -e /service/send ]; then
            echo "Sending HUP signal to send."
            svc -h /service/send
        fi
        ;;
    pause)
        for svc in $svclist; do
            if [ -e /service/${svc} ]; then
                echo "Pausing ${svc}"
                svc -p /service/${svc}
            fi
        done
        ;;
    cont)
        for svc in $svclist; do
            if [ -e /service/${svc} ]; then
                echo "Continuing ${svc}"
                svc -c /service/${svc}
            fi
        done
        ;;
    restart)
        echo "Restarting qmail:"
        for svc in $svclist; do
            if [ -e /service/${svc} ]; then
                if [ "${svc}" != "send" ]; then
                    echo "* Stopping ${svc}."
                    svc -d /service/${svc}
                fi
            fi
        done

        if [ -e /service/send ]; then
            echo "* Sending send SIGTERM and restarting."
            svc -t /service/send
        fi

        for svc in $svclist; do
            if [ -e /service/${svc} ]; then
                if [ "${svc}" != "send" ]; then
                    echo "* Restarting ${svc}."
                    svc -u /service/${svc}
                fi
            fi
        done
        ;;
    cdb)
        if [ -z "`grep '\#define POP_AUTH_OPEN_RELAY 1' /home/vpopmail/include/config.h 2>/dev/null`" ]; then
            tcprules /etc/tcprules.d/tcp.smtp.cdb /etc/tcprules.d/tcp.smtp.tmp < /etc/tcprules.d/tcp.smtp
        else
            /home/vpopmail/bin/clearopensmtp
        fi

        echo "Reloaded /etc/tcprules.d/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 send a TERM & restarts it
    doqueue -- schedules queued messages for immediate delivery
     reload -- sends 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



[6-6. qmail 서비스 등록]
chmod 755 /etc/init.d/qmaild
chkconfig --add qmaild
chkconfig --level 345 qmaild


[7. qmail 시작 및 메일 발송 테스트]
/etc/init.d/qmaild start
netstat 을 통해 110 , 25 포트 LISTEN 상태 확인
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN

ps -ef |grep mail  (프로세스 확인)
qmaill    2860  2850  0 15:13 ?        00:00:00 /usr/local/bin/multilog t /var/log/qmail/pop3
qmaill    2861  2852  0 15:13 ?        00:00:00 /usr/local/bin/multilog t /var/log/qmail/submission
vpopmail  2862  2851  0 15:13 ?        00:00:00 /usr/local/bin/tcpserver -vRHl0 -x /etc/tcprules.d/tcp.smtp.cdb -c 100 -u 108 -g 105 0 587 /var/qmail/bin/qmail-smtpd /home/vpopmail/bin/vchkpw /bin/true
qmaill    2863  2854  0 15:13 ?        00:00:00 /usr/local/bin/multilog t /var/log/qmail/send
vpopmail  2864  2855  0 15:13 ?        00:00:00 /usr/local/bin/tcpserver -vRHl0 -x /etc/tcprules.d/tcp.smtp.cdb -c 100 -u 108 -g 105 0 25 /var/qmail/bin/qmail-smtpd /home/vpopmail/bin/vchkpw /bin/true
qmails    2865  2853  0 15:13 ?        00:00:00 qmail-send
qmaill    2866  2856  0 15:13 ?        00:00:00 /usr/local/bin/multilog t /var/log/qmail/smtp
vpopmail  2867  2849  0 15:13 ?        00:00:00 /usr/local/bin/tcpserver -vRHl0 -u 108 -g 105 0 110 /var/qmail/bin/qmail-popup mail /home/vpopmail/bin/vchkpw /var/qmail/bin/qmail-pop3d Maildir
root      2882  2865  0 15:13 ?        00:00:00 qmail-lspawn ./Maildir/
qmailr    2883  2865  0 15:13 ?        00:00:00 qmail-rspawn
qmailq    2884  2865  0 15:13 ?        00:00:00 qmail-clean

telnet localhost 25
220 Welcome to Qmail SMTP Server ESMTP
ehlo  (입력)
250-Welcome to Qmail SMTP Server
250-PIPELINING
250-8BITMIME
250-SIZE 0
250 AUTH LOGIN PLAIN CRAM-MD5

echo To : kkarijoo@bestks.co.kr| /var/qmail/bin/qmail-inject    (제목없는 메일 발송 테스트)



반응형
LIST