Complete Virtual Mail Server/Postfix to Database/ko

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Complete Virtual Mail Server/Postfix to Database and the translation is 100% complete.
Other languages:

Postfix 설치

postfix 설치는 약긴 간단합니다. Postfix 기본 설치 절차를 따르십시오.

Postfix 연동

postfix가 기본 수준에서 동작한다면 데이터베이스에 연결할 시간입니다.

접근 권한 획득

PostgreSQL

데이터베이스에 요청할 데이터베이스 사용자가 필요합니다:

user $createuser -U postgres --pwprompt postfix
Enter password for new role: $password
Enter it again: $password

또한 postfix 사용자는 테이블에 대한 권한이 필요합니다:

user $psql -U postfixadmin postfix
postfix=>GRANT SELECT ON alias TO postfix;
postfix=>GRANT SELECT ON domain TO postfix;
postfix=>GRANT SELECT ON mailbox TO postfix;

MySQL

MySQL을 PostgreSQL 대신 사용한다면 다음 절차를 따르십시오. 나중에 필요한 SQL 덤프를 가져와서 genericmailsql.sql 파일로 저장하십시오.

우선 MySQL을 설치하십시오:

root #emerge --ask mysql

초기 데이터베이스를 만드십시오:

root #/usr/bin/mysql_install_db

화면에 뜬 지시를 따라 MySQL에서 루트 암호를 추가하면 데이터베이스를 어디든 열 수 있습니다.

MySQL 데이터베이스 서버를 시작하고 mailsql 데이터베이스를 만드십시오:

root #/etc/init.d/mysql start
root #mysqladmin -u root -p create mailsql
root #mysql -u root -p mailsql < genericmailsql.sql

mysql 클라이언트를 실행하여 mailsql 데이터베이스에 적당한 권한을 부여하십시오:

root #mysql -u root -p mysql
mysql>GRANT SELECT,INSERT,UPDATE,DELETE ON mailsql.* TO mailsql@localhost IDENTIFIED BY '$password';
Query OK, 0 rows affected (0.02 sec)
mysql>FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>quit

mailsql 사용자가 mysql 서버에 연결할 수 있는지 확인하십시오:

root #mysql -u mailsql -p mailsql

새 데이터베이스에 기본 값을 넣었고 두 도메인에 대한 테이블을 설정했습니다. 다음 테이블을 포함합니다:

  • alias - 로컬 이메일 별칭 및 mailman 별칭 정보.
  • relocated - 재할당한 사용자 전자메일 주소 매핑
  • transport - 서비스를 제공하는 모든 도메인의 기본 메일 전송 정보
  • users - 모든 사용자 계정 정보
  • virtual - 가상 도메인 전자메일 별칭 매핑
코드 alias 테이블 예제
id   alias      destination
1    root       foo@bar.com
2    postmaster foo@bar.com
코드 user 테이블 예제
## (Line wrapped for clarity.)
id email            clear     name     uid     gid     homedir     \
  maildir                                quota  postfix
10 foo@virt-domain.com $password realname virtid  virtid  /home/vmail \
  /home/vmail/virt-domain.com/foo/.maildir/        y
13 foo@bar.com      $password realname localid localid /home/foo   \
  /home/foo/.maildir/                           y

virtid의 사용자 ID 값과 그룹 ID 값은 vmail 사용자 및 그룹의 ID여야합니다:

코드 transport 테이블 예제
id   domain          destination
1    bar.com         local:
2    virt-domain.com virtual:
코드 virtual 테이블 예제
id   email                destination
3    root@virt-domain.com other@email.address

요청

데이터베이스상 모든 요청문은 그 자체로 제대로 작성했는지 확인하려 시험했습니다. 데이터베이스를 쓸 수 있게 제대로 채울 필요가 있습니다. postfixadmin 을 사용한다면 UI에서 쉽게 끝낼 수 있습니다. 이 경우가 아니라면 간단한 INSERT SQL 구문을 작성하고 실행하십시오.

참고
이 전체 설명서에서 사용자는 testuser, 암호는 secret으로 사용합니다.

PostgreSQL

postfix를 데이터베이스에 연동하는건 그다지 특별하지 않으며 postfix는 단지 미리 정해둔 SQL 루틴을 실행할 뿐입니다. SQL 요청문은 디렉터리에 요청별로 파일로 저장합니다.

root #mkdir /etc/postfix/pgsql

이 파일에 있는 설정 정보에서 나타나는 어떤 오류든 원인을 찾아보기 어려울 수 있다는 점을 알아두십시오. 파일의 내용과 이름에 세심한 주의를 기울이십시오. 이 파일에서 일어나는 대부분의 오류는 별 다른 내용 없이 "user example@example.com doesn't exist"로만 나타납니다.

참고
다음 파일에서, 'hosts' 변수는 목적에 따라 주석처리하시는게 좋습니다. 호스트를 설정하지 않으면 로컬 유닉스 소켓을 사용합니다.
파일 /etc/postfix/pgsql/virtual_mailbox_domains.cfvirtual_mailbox_domains
# virtual_mailbox_domains.cf
user            = postfix
password        = $password
dbname          = postfix
#hosts          = localhost
query           = SELECT description FROM domain WHERE domain = '%s' AND backupmx = '0' AND active = '1';

데이터베이스의 요청문에 (복사하고 붙여넣어) 문제가 있는 부분이 없는지 시험하는 방법이 최선입니다:

root #psql -U postfix postfix
postfix=>SELECT description FROM domain WHERE domain = 'example.com' AND backupmx = '0' AND active = '1';
     description      
----------------------
 An example domain.
(1 row)
참고
postfix는 요청문 결과를 신경쓰지 않습니다. 단지 yes 또는 no라고 대답할 뿐입니다.
파일 /etc/postfix/pgsql/virtual_mailbox_maps.cfvirtual_mailbox_maps
# virtual_mailbox_maps.cf
user            = postfix
password        = $password
dbname          = postfix
#hosts          = localhost
query           = SELECT maildir FROM mailbox WHERE local_part='%u' AND domain='%d' AND active='1';

또한 이 상황에서도 데이터베이스에 요청문 실행을 다시 해보시는게 좋습니다:

root #psql -U postfix postfix
postfix=>SELECT maildir FROM mailbox WHERE local_part='testuser' AND domain='example.com' AND active='1';
      maildir
-------------------
 example.com/testuser/
(1 row)
파일 /etc/postfix/pgsql/virtual_alias_maps.cfvirtual_alias_maps
# virtual_alias_maps.cf
user            = postfix
password        = $password
dbname          = postfix
#hosts          = localhost
query           = SELECT goto FROM alias WHERE address='%s' AND active='1';

출력 내용을 확인하기 위해 데이터베이스에서 요청문을 실행하십시오:

root #psql -U postfix postfix
postfix=>SELECT goto FROM alias WHERE address='testuser@example.com' AND active='1';
       goto       
------------------
 testuser@example.com
(1 row)
참고
postfixadmin은 각 사용자에 대한 별칭을 만듭니다. postfix가 제대로 된 동작을 수행하는데 필요한건 아닙니다만 postfixadmin에게 필요한 것일 뿐입니다.

MySQL

postfix에서 전송에 필요한 모든 정보를 다루는데 필요한 설정 항목을 설정하십시오. 적절한 사용자, 사용자 ID, 암호, 별칭, 전자메일 주소 등의 값을 잊지 말고 바꾸십시오.

파일 /etc/postfix/mysql-aliases.cf
user         = mailsql
password     = $password
dbname       = mailsql
table        = alias
select_field = destination
where_field  = alias
hosts        = unix:/var/run/mysqld/mysqld.sock
파일 /etc/postfix/mysql-relocated.cf
user         = mailsql
password     = $password
dbname       = mailsql
table        = relocated
select_field = destination
where_field  = email
hosts        = unix:/var/run/mysqld/mysqld.sock
파일 /etc/postfix/mysql-transport.cf(선택)
user         = mailsql
password     = $password
dbname       = mailsql
table        = transport
select_field = destination
where_field  = domain
hosts        = unix:/var/run/mysqld/mysqld.sock
파일 /etc/postfix/mysql-virtual-gid.cf(선택)
user            = mailsql
password        = $password
dbname          = mailsql
table           = users
select_field    = gid
where_field     = email
additional_conditions = and postfix = 'y'
hosts           = unix:/var/run/mysqld/mysqld.sock
파일 /etc/postfix/mysql-virtual-maps.cf
user            = mailsql
password        = $password
dbname          = mailsql
table           = users
select_field    = maildir
where_field     = email
additional_conditions = and postfix = 'y'
hosts           = unix:/var/run/mysqld/mysqld.sock
파일 /etc/postfix/mysql-virtual-uid.cf(선택)
user            = mailsql
password        = $password
dbname          = mailsql
table           = users
select_field    = uid
where_field     = email
additional_conditions = and postfix = 'y'
hosts           = unix:/var/run/mysqld/mysqld.sock
파일 /etc/postfix/mysql-virtual.cf
user         = mailsql
password     = $password
dbname       = mailsql
table        = virtual
select_field = destination
where_field  = email
hosts        = unix:/var/run/mysqld/mysqld.sock

접근 권한

postfix가 이 파일에 암호가 있으므로 접근 권한을 보유해야합니다:

root #chown root:postfix -R /etc/postfix/
root #chmod 640 /etc/postfix/*.cf

postfix에서 요청 대상에 연결

Postgres

파일 /etc/postfix/main.cfpostfix를 postgres에 연결하기
#
# Settings required to support virtual mail delivery using lookups in
# the Postgres database.
#
 
# A list of all virtual domains serviced by this instance of postfix.
virtual_mailbox_domains = pgsql:/etc/postfix/pgsql/virtual_mailbox_domains.cf
 
# Look up the mailbox location based on the email address received.
virtual_mailbox_maps = pgsql:/etc/postfix/pgsql/virtual_mailbox_maps.cf
 
# Any aliases that are supported by this system
virtual_alias_maps = pgsql:/etc/postfix/pgsql/virtual_alias_maps.cf

MySQL/MariaDB

파일 /etc/postfix/main.cf
## (Ensure that there are no other alias_maps definitions)
alias_maps = mysql:/etc/postfix/mysql-aliases.cf
relocated_maps = mysql:/etc/postfix/mysql-relocated.cf
 
local_transport = local
local_recipient_maps = $alias_maps $virtual_mailbox_maps unix:passwd.byname
 
virtual_transport = virtual
## (The domains listed by the mydestination should not be listed in
##  the virtual_mailbox_domains parameter)
virtual_mailbox_domains = virt-domain.com, $other-virtual-domain.com
 
virtual_minimum_uid = 1000
## (Substitute $vmail-gid with the GID of the vmail group)
virtual_gid_maps = static:$vmail-gid
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual.cf
## (Substitute $vmail-uid with the UID of the vmail user)
virtual_uid_maps = static:$vmail-uid

Postfix 2.0.x에서는 1.1.x 릴리즈에 비해 상당히 많이 바뀌었습니다. 주목할만한 전송 처리, 가상 그룹 ID, 가상 사용자 ID 테이블은 더이상 필요하지 않습니다. 잠재적인 다른 용도를 지원하기 위해 테이블을 여전히 포함해두었습니다.

참고
가상 설정에 대해 더 알아보려면 postfix 문서에 들어있는 VIRTUAL_README 탐독을 추천합니다.

데이터베이스 연결 시험

postfix를 데이터베이스에 연결하려면 다시 시작해야합니다:

root #/etc/init.d/postfix restart

잘못된 권한 같은 문제는 /var/log/mail.log에서 확인하십시오.

텔넷을 활용하면, 메일 서버에서 데이터베이스를 제대로 활용하고 잇는지 다시한번 시험해볼 수 있습니다.

user $telnet localhost 25
Trying 127.0.0.1...
Connected to foo.example.com.
Escape character is '^]'.
220 foo.example.com ESMTP Postfix
mail from:me@you.com
250 2.1.0 Ok
rcpt to:testuser@example.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
Testmail to ensure Postfix is still working.
.
250 2.0.0 Ok: queued as EA94F164C7
mail from:me@you.com
250 2.1.0 Ok
rcpt to:test.user@example.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
Testmail to ensure Postfix is still really working.
.
250 2.0.0 Ok: queued as 3A276164C7
quit
221 2.0.0 Bye
Connection closed by foreign host.
파일 /var/log/mail.log시험 메시지 검증
Mar 16 19:25:15 foo postfix/smtpd[32321]: connect from unknown[127.0.0.1]
Mar 16 19:25:32 foo postfix/smtpd[32321]: EA94F164C7: client=unknown[127.0.0.1]
Mar 16 19:25:42 foo postfix/cleanup[32330]: EA94F164C7: message-id=<>
Mar 16 19:25:42 foo postfix/qmgr[31681]: EA94F164C7: from=<me@you.com>, size=215, nrcpt=1 (queue active)
Mar 16 19:25:42 foo postfix/virtual[32332]: EA94F164C7: to=<testuser@example.com>, relay=virtual, delay=22, delays=22/0.02/0/0.05, dsn=2.0.0, status=sent (delivered to maildir)
Mar 16 19:25:42 foo postfix/qmgr[31681]: EA94F164C7: removed
Mar 16 19:26:05 foo postfix/smtpd[32321]: 3A276164C7: client=unknown[127.0.0.1]
Mar 16 19:26:14 foo postfix/cleanup[32330]: 3A276164C7: message-id=<>
Mar 16 19:26:14 foo postfix/qmgr[31681]: 3A276164C7: from=<me@you.com>, size=199, nrcpt=1 (queue active)
Mar 16 19:26:15 foo postfix/smtp[32338]: 3A276164C7: to=<test.user@example.com>, orig_to=<test.user@example.com>, relay=virtual, delay=23, delays=22/0.02/0.57/0.39, dsn=2.0.0, status=sent (delivered to maildir)
Mar 16 19:26:15 foo postfix/qmgr[31681]: 3A276164C7: removed
경고
vda USE 플래그를 설정하면, 디스크 공간을 너무 많이 차지하는 문제 때문에 시험 메시지를 (소프트) 바운싱 처리하는 일이 일어납니다. 선택지는 두가지가 있습니다. vda USE 플래그를 빼고 다시 이머지처리하거나, 용량 제한 처리를 활성화한 상태에서 vda USE 플래그를 활성화하고 이머지 처리하는 방법입니다. 또는 일부 용량만 제한하게 건너뛰고 다음 과정을 따라간 다음에 여기로 다시 돌아오십시오.