메일 서버 · 6 min read · Sep 28, 2025

Postfix, Courier, MySQL 및 SquirrelMail을 이용한 가상 사용자 및 도메인 (Debian Lenny) - 2페이지

5 Postfix 구성

이제 Postfix에 데이터베이스에서 모든 정보를 찾을 수 있는 위치를 알려줘야 합니다. 따라서 여섯 개의 텍스트 파일을 생성해야 합니다. Postfix에 localhost 대신 IP 주소 127.0.0.1에서 MySQL에 연결하도록 지시하는 것을 알 수 있습니다. 이는 Postfix가 chroot 감옥에서 실행되고 있으며, localhost를 사용하라고 지시하면 연결을 시도할 MySQL 소켓에 접근할 수 없기 때문입니다. 127.0.0.1을 사용하면 Postfix는 TCP 네트워킹을 사용하여 MySQL에 연결하며, 이는 chroot 감옥에서도 문제가 없습니다 (대안은 MySQL 소켓을 chroot 감옥으로 이동하는 것이며, 이는 다른 문제를 일으킵니다).

/etc/mysql/my.cnf에 다음 줄이 포함되어 있는지 확인하세요:

vi /etc/mysql/my.cnf

| [...] bind-address = 127.0.0.1 [...] |

/etc/mysql/my.cnf를 수정해야 했다면, 지금 MySQL을 재시작하세요:

/etc/init.d/mysql restart

다음 명령어를 실행하여 MySQL이 127.0.0.1 (localhost.localdomain)에서 수신 대기 중인지 확인하세요:

netstat -tap | grep mysql
server1:/usr/src# netstat -tap | grep mysql  
tcp        0      0 localhost.localdo:mysql *:*                     LISTEN      4559/mysqld  
server1:/usr/src#

이제 여섯 개의 텍스트 파일을 생성합시다.

vi /etc/postfix/mysql-virtual_domains.cf

| user = mail_admin password = mail_admin_password dbname = mail query = SELECT domain AS virtual FROM domains WHERE domain='%s' hosts = 127.0.0.1 |

vi /etc/postfix/mysql-virtual_forwardings.cf

| user = mail_admin password = mail_admin_password dbname = mail query = SELECT destination FROM forwardings WHERE source='%s' hosts = 127.0.0.1 |

vi /etc/postfix/mysql-virtual_mailboxes.cf

| user = mail_admin password = mail_admin_password dbname = mail query = SELECT CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/') FROM users WHERE email='%s' hosts = 127.0.0.1 |

vi /etc/postfix/mysql-virtual_email2email.cf

| user = mail_admin password = mail_admin_password dbname = mail query = SELECT email FROM users WHERE email='%s' hosts = 127.0.0.1 |

vi /etc/postfix/mysql-virtual_transports.cf

| user = mail_admin password = mail_admin_password dbname = mail query = SELECT transport FROM transport WHERE domain='%s' hosts = 127.0.0.1 |

vi /etc/postfix/mysql-virtual_mailbox_limit_maps.cf

| user = mail_admin password = mail_admin_password dbname = mail query = SELECT quota FROM users WHERE email='%s' hosts = 127.0.0.1 |

그런 다음 이러한 파일의 권한과 그룹을 변경하세요:

chmod o= /etc/postfix/mysql-virtual_*.cf  
chgrp postfix /etc/postfix/mysql-virtual_*.cf

이제 /home/vmail에 홈 디렉토리를 가진 vmail이라는 사용자와 그룹을 생성합니다. 여기에서 모든 메일 박스가 저장됩니다.

groupadd -g 5000 vmail  
useradd -g vmail -u 5000 vmail -d /home/vmail -m

다음으로 Postfix 구성을 진행합니다. server1.example.com을 유효한 FQDN으로 바꾸는 것을 잊지 마세요. 그렇지 않으면 Postfix가 제대로 작동하지 않을 수 있습니다!

postconf -e 'myhostname = server1.example.com'  
postconf -e 'mydestination = server1.example.com, localhost, localhost.localdomain'  
postconf -e 'mynetworks = 127.0.0.0/8'  
postconf -e 'message_size_limit = 30720000'  
postconf -e 'virtual_alias_domains ='  
postconf -e 'virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf'  
postconf -e 'virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf'  
postconf -e 'virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf'  
postconf -e 'virtual_mailbox_base = /home/vmail'  
postconf -e 'virtual_uid_maps = static:5000'  
postconf -e 'virtual_gid_maps = static:5000'  
postconf -e 'smtpd_sasl_auth_enable = yes'  
postconf -e 'broken_sasl_auth_clients = yes'  
postconf -e 'smtpd_sasl_authenticated_header = yes'  
postconf -e 'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination'  
postconf -e 'smtpd_use_tls = yes'  
postconf -e 'smtpd_tls_cert_file = /etc/postfix/smtpd.cert'  
postconf -e 'smtpd_tls_key_file = /etc/postfix/smtpd.key'  
postconf -e 'transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf'  
postconf -e 'virtual_create_maildirsize = yes'  
postconf -e 'virtual_maildir_extended = yes'  
postconf -e 'virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailbox_limit_maps.cf'  
postconf -e 'virtual_mailbox_limit_override = yes'  
postconf -e 'virtual_maildir_limit_message = "The user you are trying to reach is over quota."'  
postconf -e 'virtual_overquota_bounce = yes'  
postconf -e 'proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps'

그 후 TLS에 필요한 SSL 인증서를 생성합니다:

cd /etc/postfix  
openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509

국가 이름 (2자리 코드) [AU]: <– 귀하의 국가 이름을 입력하세요 (예: “DE”).
주 또는 지방 이름 (전체 이름) [Some-State]: <– 귀하의 주 또는 지방 이름을 입력하세요.
지역 이름 (예: 도시) []: <– 귀하의 도시를 입력하세요.
조직 이름 (예: 회사) [Internet Widgits Pty Ltd]: <– 귀하의 조직 이름을 입력하세요 (예: 귀하의 회사 이름).
조직 단위 이름 (예: 섹션) []: <– 귀하의 조직 단위 이름을 입력하세요 (예: “IT 부서”).
일반 이름 (예: 귀하의 이름) []: <– 시스템의 완전한 도메인 이름을 입력하세요 (예: “server1.example.com”).
이메일 주소 []: <– 귀하의 이메일 주소를 입력하세요.

그런 다음 smtpd.key의 권한을 변경하세요:

chmod o= /etc/postfix/smtpd.key

6 Saslauthd 구성

먼저 다음 명령어를 실행하세요:

mkdir -p /var/spool/postfix/var/run/saslauthd

그런 다음 /etc/default/saslauthd를 편집합니다. START를 yes로 설정하고 OPTIONS=”-c -m /var/run/saslauthd” 줄을 OPTIONS=”-c -m /var/spool/postfix/var/run/saslauthd -r”로 변경하세요:

vi /etc/default/saslauthd

| # # saslauthd 데몬에 대한 설정 # 자세한 내용은 /usr/share/doc/sasl2-bin/README.Debian을 참조하세요. # # saslauthd가 자동으로 시작할까요? (기본값: 아니오) START=yes # 이 saslauthd 인스턴스에 대한 설명. 권장. # (제안: SASL 인증 데몬) DESC="SASL Authentication Daemon" # 이 saslauthd 인스턴스의 짧은 이름. 강력히 권장. # (제안: saslauthd) NAME="saslauthd" # saslauthd가 사용할 인증 메커니즘은 무엇인가요? (기본값: pam) # # 이 Debian 패키지에서 사용할 수 있는 옵션: # getpwent -- getpwent() 라이브러리 함수 사용 # kerberos5 -- Kerberos 5 사용 # pam -- PAM 사용 # rimap -- 원격 IMAP 서버 사용 # shadow -- 로컬 shadow 비밀번호 파일 사용 # sasldb -- 로컬 sasldb 데이터베이스 파일 사용 # ldap -- LDAP 사용 (구성은 /etc/saslauthd.conf에 있음) # # 한 번에 하나의 옵션만 사용할 수 있습니다. saslauthd 매뉴얼 페이지를 참조하세요. # # 예: MECHANISMS="pam" MECHANISMS="pam" # 이 메커니즘에 대한 추가 옵션. (기본값: 없음) # 메커니즘별 옵션에 대한 정보는 saslauthd 매뉴얼 페이지를 참조하세요. MECH_OPTIONS="" # 몇 개의 saslauthd 프로세스를 실행해야 하나요? (기본값: 5) # 값이 0이면 각 연결에 대해 새 프로세스를 포크합니다. THREADS=5 # 기타 옵션 (기본값: -c -m /var/run/saslauthd) # 주의: -m 옵션을 반드시 지정해야 saslauthd가 실행됩니다! # # 경고: -d 옵션을 지정하지 마세요. # -d 옵션은 saslauthd가 데몬이 아닌 포그라운드에서 실행되게 합니다. # 이는 시스템이 제대로 부팅되는 것을 방해합니다. 디버그 모드로 saslauthd를 실행하려면, 안전하게 수동으로 실행하세요. # # /usr/share/doc/sasl2-bin/README.Debian에서 Debian 전용 정보를 참조하세요. # saslauthd 매뉴얼 페이지 및 'saslauthd -h'의 출력을 참조하여 이러한 옵션에 대한 일반 정보를 확인하세요. # # postfix 사용자를 위한 예: "-c -m /var/spool/postfix/var/run/saslauthd" #OPTIONS="-c -m /var/run/saslauthd" OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r" |

그런 다음 /etc/pam.d/smtp 파일을 생성합니다. 다음 두 줄만 포함되어야 합니다 (정확한 데이터베이스 세부정보를 입력하세요):

vi /etc/pam.d/smtp

| auth required pam_mysql.so user=mail_admin passwd=mail_admin_password host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1 account sufficient pam_mysql.so user=mail_admin passwd=mail_admin_password host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1 |

다음으로 /etc/postfix/sasl/smtpd.conf 파일을 생성합니다. 다음과 같아야 합니다:

vi /etc/postfix/sasl/smtpd.conf

| pwcheck_method: saslauthd mech_list: plain login allow_plaintext: true auxprop_plugin: mysql sql_hostnames: 127.0.0.1 sql_user: mail_admin sql_passwd: mail_admin_password sql_database: mail sql_select: select password from users where email = '%u' |

다음으로 postfix 사용자를 sasl 그룹에 추가합니다 (이렇게 하면 Postfix가 saslauthd에 접근할 수 있는 권한을 갖게 됩니다):

adduser postfix sasl

그런 다음 Postfix와 Saslauthd를 재시작합니다:

/etc/init.d/postfix restart  
/etc/init.d/saslauthd restart

7 Courier 구성

이제 Courier에 MySQL 데이터베이스에 대해 인증해야 한다고 알려줘야 합니다. 먼저 /etc/courier/authdaemonrc를 편집하고 authmodulelist의 값을 다음과 같이 변경합니다:

vi /etc/courier/authdaemonrc

| [...] authmodulelist="authmysql" [...] |

그런 다음 /etc/courier/authmysqlrc의 백업을 만들고 이전 파일을 비워둡니다:

cp /etc/courier/authmysqlrc /etc/courier/authmysqlrc_orig  
cat /dev/null > /etc/courier/authmysqlrc

그런 다음 /etc/courier/authmysqlrc를 열고 다음 줄을 추가합니다:

vi /etc/courier/authmysqlrc

| MYSQL_SERVER localhost MYSQL_USERNAME mail_admin MYSQL_PASSWORD mail_admin_password MYSQL_PORT 0 MYSQL_DATABASE mail MYSQL_USER_TABLE users MYSQL_CRYPT_PWFIELD password #MYSQL_CLEAR_PWFIELD password MYSQL_UID_FIELD 5000 MYSQL_GID_FIELD 5000 MYSQL_LOGIN_FIELD email MYSQL_HOME_FIELD "/home/vmail" MYSQL_MAILDIR_FIELD CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/') #MYSQL_NAME_FIELD MYSQL_QUOTA_FIELD quota |

설치 중에 IMAP-SSL 및 POP3-SSL에 대한 SSL 인증서가 localhost라는 호스트 이름으로 생성됩니다. 이를 올바른 호스트 이름 (이 튜토리얼에서는 server1.example.com)으로 변경하려면 인증서를 삭제하세요…

cd /etc/courier  
rm -f /etc/courier/imapd.pem  
rm -f /etc/courier/pop3d.pem

… 그리고 다음 두 파일을 수정하세요; CN=localhost를 CN=server1.example.com으로 바꾸세요 (필요한 경우 다른 값도 수정할 수 있습니다):

vi /etc/courier/imapd.cnf

| [...] CN=server1.example.com [...] |

vi /etc/courier/pop3d.cnf

| [...] CN=server1.example.com [...] |

그런 다음 인증서를 다시 생성하세요…

mkimapdcert  
mkpop3dcert

… 그리고 Courier를 재시작하세요:

/etc/init.d/courier-authdaemon restart  
/etc/init.d/courier-imap restart  
/etc/init.d/courier-imap-ssl restart  
/etc/init.d/courier-pop restart  
/etc/init.d/courier-pop-ssl restart

다음 명령어를 실행하여

telnet localhost pop3

POP3 서버가 제대로 작동하는지 확인할 수 있습니다. +OK Hello there.를 반환해야 합니다. (종료하려면 quit을 입력하세요.)

server1:/etc/courier# telnet localhost pop3  
Trying 127.0.0.1...  
Connected to localhost.  
Escape character is '^]'.  
+OK Hello there.  
quit  
+OK Better luck next time.  
Connection closed by foreign host.  
server1:/etc/courier#

8 /etc/aliases 수정

이제 /etc/aliases를 열어야 합니다. postmaster가 root를 가리키고 root가 귀하의 사용자 이름 또는 이메일 주소를 가리키도록 하세요. 예를 들어 다음과 같이:

vi /etc/aliases

| [...] postmaster: root root: [email protected] [...] |

또는 다음과 같이 (administrator가 귀하의 사용자 이름인 경우):

| [...] postmaster: root root: administrator [...] |

/etc/aliases를 수정할 때마다 다음 명령어를 실행해야 합니다:

newaliases

그런 다음 Postfix를 재시작하세요:

/etc/init.d/postfix restart
Share: X/Twitter LinkedIn

새 게시물을 받은 편지함에서 받기

스팸은 없습니다. 언제든지 구독 해지 가능합니다.