qmail+ roundcube 연동하기 (centos 7)

| 2020년 8월 27일 | 0 Comments

안녕하세요 기술지원팀 오장욱입니다

qmail과 roundcube 설치 및 연동방법입니다

 

1.qmail 설치

centos 7에서 설치하였으며

apm이 소스(컴파일) 설치 된환경에서 설치하였습니다

APM 설치후

> yum install -y patch wget openssl-devel libtool-ltdl-devel libxml2-devel ncurses-devel imap-devel

Ucspi-tcp 설치

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

>  wget http://www.linuxfromscratch.org/patches/downloads/ucspi-tcp/ucspi-tcp-0.88-errno-1.patch

> tar zxvf ucspi-tcp-0.88.tar.gz

> cd ucspi-tcp-0.88.tar.gz

> patch -p1 < ../ucspi-tcp-0.88.errno.patch

> echo “/usr/local” > conf-home

> make

> make setup check

daemontools설치

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

>  wget https://github.com/nkadel/daemontools-0.76-srpm/blob/master/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

vi /etc/systemd/system/daemontools.service

열어 아래내용을 저장합니다

[Unit]

Description=daemontools Start supervise

After=getty.target

[Service]

Type=simple

User=root

Group=root

Restart=always

ExecStart=/command/svscanboot /dev/ttyS0

TimeoutSec=0

[Install]

WantedBy=multi-user.target

> systemctl start daemontools.service

> systemctl status daemontools.service

> systemctl enable daemontools.service

qmail vpopmail 계정을 생성합니다

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

vpopmail을 설치합니다

> mkdir -p /var/qmail/bin

> touch /var/qmail/bin/qmail-newu

> touch /var/qmail/bin/qmail-inject

> touch /var/qmail/bin/qmail-newmrh

> cd /usr/local/src

> wget https://qmailrocks.thibs.com/downloads/vpopmail-5.4.33.tar.gz

tar xfz vpopmail-5.4.33.tar.gz

> cd vpopmail-5.4.33

> ./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 –enable-libdir=/usr/local/mysql/lib

>make && make install-strip

vi /home/vpopmail/etc/vpopmail.mysql

접근하여 자신의 맞게 설정 후 저장

localhost|0|DB_USER|PASSWORD|DB_NAME 설정

mysql 에 접속하여 vpopmail DB를 생성해줍니다

> create database vpopmail;

> grant all privileges on vpopmail.* to vpopmail@localhost identified by ‘패스워드‘ with grant option;

> flush privileges;

>rm -rf /var/qmail

> cd /usr/local/src

> wget http://shupp.org/software/libdomainkeys-0.68.tar.gz

> tar xfz libdomainkeys-0.68.tar.gz

> mv libdomainkeys-0.68 libdomainkeys

> cd libdomainkeys

> echo “-lresolv” > dns.lib

> make

> cd /usr/local/src

> wget http://112.175.88.99/download/00.qmail_src/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 /usr/local/src/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

> cd /var/qmail/control

> touch rcpthosts smtproutes

> echo “localhost” > locals

> echo “도메인” > me

> echo “도메인” > defaultdomain

> echo “도메인” > defaulthost

> echo “도메인” > 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 *

> 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/send 2>&1

> vi /var/qmail/supervise/pop3/run

#!/bin/sh

VPOP_UID=`id -u vpopmail`

VPOP_GID=`id -g vpopmail`

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 도메인\

/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

> chmod 755 /var/qmail/rc

> chown root:qmail /var/qmail/rc

> chmod 700 /var/qmail/supervise

> chown -R qmaill:qmail /var/qmail/supervise

> for i in send smtp pop3 submission; do chmod 1700 /var/qmail/supervise/$i; done

>for i in send smtp pop3 submission; do chmod 700 /var/qmail/supervise/$i/log; done

>for i in send smtp pop3 submission; do chmod 751 /var/qmail/supervise/$i/run; done

>for i in send smtp pop3 submission; do chmod 751 /var/qmail/supervise/$i/log/run; done

>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″

데몬을 켜고 끄기 위해 다음과 같이 파일을 만들어 줍니다

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
> chmod 755 /etc/init.d/qmaild
> chkconfig --add qmaild
> chkconfig --level 345 qmaild
>chkconfig qmaild on
설치된 vpopmail로 도메인과 계정을 만들어줍니다
> /home/vpopmail/bin/vadddomain 도메인
> /home/vpopmail/bin/vadduser 계정@도메인

2. Roundcube 설치

먼저 roundcube 파일을 다운받습니다

> wget https://github.com/roundcube/roundcubemail/releases/download/1.3.9/roundcubemail-1.3.9-complete.tar.gz

다운받은 파일을 압축을 풀어 줍니다

> tar zxvf roundcubemail-1.3.9-complete.tar.gz

압축 푼 roundcube 파일을 웹소스(웹메일 소스) 부분으로 옮겨 줍니다

> mv roundcubemail-1.3.9 /home/postmaster/webmail

apachevhost에등록해줍니다

> vi /usr/local/apache/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>

DocumentRoot “/home/postmaster/webmail”

ServerName mail.teuk0113.xyz

#ServerAlias m

ErrorLog “logs/dummy-mail.teuk0113.xyz-error_log”

CustomLog “logs/dummy-mail.teuk0113.xyz-access_log” common

</VirtualHost>

접속에러가 발생할수 있으므로 웹소스가 있는 디렉토리를 권한을 줍니다

> chmod 755 //home/postmaster

Database 연동을위해 계정 및 DB를 만들어 줍니다

>mysql -uroot -p

> create database roundcubemail;

>grant all privileges on roundcubemail.* to ’roundcube’@’%’ identified by ‘teuk0113’;

>flush privileges;

도메인/installer 로 접속하여 설치를 시작합니다

접속하게 되면 intl, LDAP ,Imagick 모듈을 찾을 수 없고 allow_url_fopen, date.time.zone NOT OK 로 나오게 됩니다

php 설치 파일을 찾아 initlLdap모듈을 설치하겠습니다

> cd /usr/local/src//php-7.2.17/ext/intl

>/usr/local/php/bin/phpize

>./configure –with-php-config=/usr/local/php/bin/php-config –enable-intl

> make && make install

> vi /usr/local/apache/conf/php.ini

> extension_dir=”/usr/local/php/lib/php/extensions/no-debug-zts-20170718/”

> extension=intl.so

> cd /usr/local/src//php-7.2.17/ext/ldap

>/usr/local/php/bin/phpize

>./configure –with-php-config=/usr/local/php/bin/php-config

> make && make install

> vi /usr/local/apache/conf/php.ini

> extension_dir=”/usr/local/php/lib/php/extensions/no-debug-zts-20170718/”

> extension=ldap.so

imagick 은 패키지와 설치 파일을 다운받아야합니다

>wget https://pecl.php.net/get/imagick-3.4.4.tgz

>tar zxvf imagick-3.4.4.tgz

> cd imagick-3.4.4.tgz

>yum install ImageMagick ImageMagick-devel

>/usr/local/php/bin/phpize

>./configure –with-php-config=/usr/local/php/bin/php-config

> make && make install

> vi /usr/local/apache/conf/php.ini

> extension_dir=”/usr/local/php/lib/php/extensions/no-debug-zts-20170718/”

> extension=imagick.so

> vi /usr/local/apache/conf/php.ini

allow_url_fopen =Off —- > ON

data.timezone = Asia/Seoul

설정후 아파치를 재시작 해줘야 합니다

모듈추가 및 php.ini설정을 다하였다면 다음과 같이 바뀌게 됩니다

모두 ok를 확인하고 다음으로 넘어갑니다

다음은 DB부분으로 DB정보와 맞는지 확인하고 패스워드를 적어줍니다

IMAP 부분에 도메인을 적어줍니다

smtp 부분에 mail.도메인을 입력해줍니다

Save in /tmp를 눌러 /tmp에 저장후

config 폴더에 추가해줍니다

>cp -arp /tmp/config.inc.php /home/postmaster/webmail/config/

Continue를 눌러주면 SMTPIMAP 테스트를 해줍니다

테스트가 완료가 되었다면 installer 부분을 삭제해줍니다

> rm -rf /home/postmaster/webmail/installer/

http:// 도메인 을 입력하면 로그인 창이 뜨게 됩니다

일반계정으로 로그인합니다

로그인시 권한이 없다고 나올시 chmod 755 /var/spool/mail/계정명 입력하시면 되며

추가로 ptr 레코드 등록 해주셔야 메일 수발신이 원할하게 적용될수있습니다

Category: 솔루션/IT기타

Avatar

About the Author ()