웹사이트 검색

Postfix, Courier, MySQL 및 SquirrelMail(Ubuntu 13.10)을 사용하는 가상 사용자 및 도메인


이 튜토리얼은 다음 OS 버전에 대해 존재합니다.

  • 우분투 13.10(Saucy Salamander)
  • 우분투 11.04(Natty Narwhal)

이 페이지에서

  1. 1 서문
  2. 2 Postfix, Courier, Saslauthd, MySQL, phpMyAdmin 설치
  3. 3 Postfix에 할당량 패치 적용\n
  4. 4 Postfix/Courier용 MySQL 데이터베이스 생성
  5. 5 Postfix 구성
  6. 6 Saslauthd 구성
  7. 7 Courier 구성
  8. 8 /etc/aliases 수정
  9. 9 amavisd-new, SpamAssassin 및 ClamAV 설치
  10. 10 Razor, Pyzor 및 DCC 설치 및 SpamAssassin 구성

이 튜토리얼은 Falko Timme & Srijan Kishore의 Copyright (c) 2014입니다. http://workaround.org에서 찾을 수 있는 Christoph Haas의 자습서에서 파생되었습니다. Creative Commons 라이선스 2.5 이상 버전에서 이 튜토리얼을 자유롭게 사용할 수 있습니다.

이 문서는 가상 사용자 및 도메인, 즉 MySQL 데이터베이스에 있는 사용자 및 도메인을 기반으로 하는 Postfix 메일 서버를 설치하는 방법을 설명합니다. 또한 Courier(Courier-POP3, Courier-IMAP)의 설치 및 구성을 시연하여 Courier가 Postfix가 사용하는 것과 동일한 MySQL 데이터베이스에 대해 인증할 수 있도록 합니다.

결과 Postfix 서버는 SMTP-AUTH 및 TLS 및 할당량을 사용할 수 있습니다(할당량은 기본적으로 Postfix에 내장되어 있지 않으며 Postfix를 적절하게 패치하는 방법을 보여 드리겠습니다). 암호는 데이터베이스에 암호화된 형태로 저장됩니다(내가 찾은 대부분의 문서는 보안 위험이 있는 일반 텍스트 암호를 다루고 있었습니다). 그 외에도 이 튜토리얼에서는 이메일에서 스팸 및 바이러스를 검사할 수 있도록 Amavisd, SpamAssassin 및 ClamAV를 설치하는 방법을 다룹니다. 또한 사용자가 이메일을 읽고 보내고 비밀번호를 변경할 수 있도록 SquirrelMail을 웹메일 인터페이스로 설치하는 방법도 보여드리겠습니다.

이러한 "가상" 설정(MySQL 데이터베이스의 가상 사용자 및 도메인)의 장점은 "실제" 시스템 사용자를 기반으로 하는 설정보다 성능이 훨씬 뛰어나다는 것입니다. 이 가상 설정을 통해 메일 서버는 수천 개의 도메인과 사용자를 처리할 수 있습니다. 게다가 새로운 사용자/도메인을 추가하거나 기존 사용자/도메인을 편집할 때 MySQL 데이터베이스만 처리하면 되기 때문에 관리가 더 쉽습니다. 더 이상 db 파일을 생성하기 위한 postmap 명령, Postfix 다시 로드 등이 없습니다. MySQL 데이터베이스 관리를 위해 이 하우투에도 설치될 phpMyAdmin과 같은 웹 기반 도구를 사용할 수 있습니다. 세 번째 장점은 사용자가 이해하고 기억하기 쉬운 사용자 이름으로 이메일 주소를 갖는다는 것입니다(사용자 이름 + 이메일 주소 대신).

이 하우투는 실용적인 가이드를 의미합니다. 그것은 이론적 배경을 다루지 않습니다. 그들은 웹의 다른 많은 문서에서 처리됩니다.

이 문서는 어떤 종류의 보증 없이 제공됩니다! 나는 이것이 그러한 시스템을 설정하는 유일한 방법이 아니라고 말하고 싶습니다. 이 목표를 달성하는 방법에는 여러 가지가 있지만 이것이 제가 취하는 방법입니다. 나는 이것이 당신에게 효과가 있을 것이라는 어떠한 보증도 하지 않습니다!

1 서문

이 튜토리얼은 Ubuntu 13.10 서버(Saucy Salamander)를 기반으로 하므로 이 튜토리얼을 계속하기 전에 기본 Ubuntu 13.10 서버 설치를 설정해야 합니다. 시스템에는 고정 IP 주소가 있어야 합니다. 이 튜토리얼에서는 192.168.0.100을 IP 주소로 사용하고 server1.example.com을 호스트 이름으로 사용합니다.

루트로 로그인했는지 확인하십시오(입력

sudo su

이 자습서의 모든 단계를 루트 사용자로 실행해야 하기 때문입니다.

/bin/sh를 /bin/bash에 대한 심볼릭 링크로 만드는 것이 매우 중요합니다...

dpkg-reconfigure dash

대시를 기본 시스템 셸(/bin/sh)로 사용하시겠습니까? <-- 아니요

... 그리고 AppArmor를 비활성화합니다.

/etc/init.d/apparmor stop 
update-rc.d -f apparmor remove
apt-get remove apparmor apparmor-utils

2 Postfix, Courier, Saslauthd, MySQL, phpMyAdmin 설치

Postfix, Courier, Saslauthd, MySQL 및 phpMyAdmin을 설치하려면 간단히 실행합니다.

apt-get install postfix postfix-mysql postfix-doc mysql-client mysql-server courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl libsasl2-2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl phpmyadmin apache2 libapache2-mod-php5 php5 php5-mysql libpam-smbpass

몇 가지 질문을 받게 됩니다.

MySQL "root" 사용자의 새 비밀번호: <-- yourrootsqlpassword
MySQL "root" 사용자의 비밀번호 반복: <-- yourrootsqlpassword
웹 기반 관리를 위한 디렉토리를 만드시겠습니까? <-- 아니오
일반 메일 구성 유형: <-- 인터넷 사이트
시스템 메일 이름: <-- server1.example.com
SSL 인증서 필요 <-- 확인
재구성할 웹 서버 자동으로: <-- apache2
dbconfig-common을 사용하여 phpmyadmin용 데이터베이스를 구성하시겠습니까? <-- 아니요

3 Postfix에 할당량 패치 적용

Postfix 소스를 가져와 할당량 패치로 패치하고 새 Postfix .deb 패키지를 빌드하고 해당 .deb 패키지를 설치해야 합니다.

apt-get build-dep postfix
cd /usr/src
apt-get source postfix

(다음 명령에서 올바른 Postfix 버전을 사용했는지 확인하십시오. Postfix 2.10.2가 설치되어 있습니다. 다음을 실행하여 Postfix 버전을 확인할 수 있습니다.

postconf -d | grep mail_version

출력은 다음과 같아야 합니다.

:/usr/src#
wget http://vda.sourceforge.net/VDA/postfix-vda-v13-2.10.0.patch
cd postfix-2.10.2
patch -p1 < ../postfix-vda-v13-2.10.0.patch

다음으로 debian/rules를 열고 DEB_BUILD_HARDENING을 1에서 0으로 변경합니다.

vi debian/rules
[...]
export DEB_BUILD_HARDENING=0
[...]

이렇게 하지 않으면 다음 오류 메시지와 함께 빌드가 실패합니다.

maildir.c: In function âdeliver_maildirâ:
maildir.c:974:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c:977:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c:983:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c:986:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c: In function âsql2fileâ:
maildir.c:404:25: warning: ignoring return value of âreadâ, declared with attribute warn_unused_result [-Wunused-result]
maildir.c:417:26: warning: ignoring return value of âwriteâ, declared with attribute warn_unused_result [-Wunused-result]
cc1: some warnings being treated as errors
make: *** [maildir.o] Error 1
make: Leaving directory `/usr/src/postfix-2.10.2/src/virtual'
make[1]: *** [update] Error 1
make[1]: Leaving directory `/usr/src/postfix-2.10.2'
make: *** [build] Error 2
dpkg-buildpackage: error: debian/rules build gave error exit status 2
:/usr/src/postfix-2.10.2#

이제 새로운 Postfix .deb 패키지를 빌드할 수 있습니다.

dpkg-buildpackage

이제 새로운 .deb 패키지가 생성된 디렉토리로 이동합니다.

cd ..

명령

ls -l

사용 가능한 패키지를 보여줍니다.

:/usr/src# ls -l
total 7124
drwxr-xr-x 18 root root    4096 Apr 16 04:29 postfix-2.10.2
-rw-r--r--  1 root root   48594 Apr 16 04:29 postfix-cdb_2.10.2-1_amd64.deb
-rw-r--r--  1 root root  161974 Apr 16 04:29 postfix-dev_2.10.2-1_all.deb
-rw-r--r--  1 root root 1094344 Apr 16 04:29 postfix-doc_2.10.2-1_all.deb
-rw-r--r--  1 root root   57342 Apr 16 04:29 postfix-ldap_2.10.2-1_amd64.deb
-rw-r--r--  1 root root   50554 Apr 16 04:29 postfix-mysql_2.10.2-1_amd64.deb
-rw-r--r--  1 root root   50804 Apr 16 04:29 postfix-pcre_2.10.2-1_amd64.deb
-rw-r--r--  1 root root   50756 Apr 16 04:29 postfix-pgsql_2.10.2-1_amd64.deb
-rw-r--r--  1 root root   55701 Jun  7  2013 postfix-vda-v13-2.10.0.patch
-rw-r--r--  1 root root  282175 Apr 16 04:28 postfix_2.10.2-1.diff.gz
-rw-r--r--  1 root root    1522 Apr 16 04:28 postfix_2.10.2-1.dsc
-rw-r--r--  1 root root    3899 Apr 16 04:29 postfix_2.10.2-1_amd64.changes
-rw-r--r--  1 root root 1542368 Apr 16 04:29 postfix_2.10.2-1_amd64.deb
-rw-r--r--  1 root root 3828326 Sep 12  2013 postfix_2.10.2.orig.tar.gz

postfix 및 postfix-mysql 패키지를 선택하고 다음과 같이 설치합니다.

dpkg -i postfix_2.10.2-1_amd64.deb postfix-mysql_2.10.2-1_amd64.deb

4 Postfix/Courier용 MySQL 데이터베이스 생성

이제 메일이라는 데이터베이스를 만듭니다.

mysqladmin -u root -p create mail

다음 질문을 받게 됩니다.

비밀번호 입력: <-- yourrootsqlpassword

다음으로 MySQL 셸로 이동합니다.

mysql -u root -p

MySQL 셸에서 메일 데이터베이스에 대한 SELECT,INSERT,UPDATE,DELETE 권한이 있는 암호 mail_admin_password(자신의 암호로 대체)를 사용하여 mail_admin 사용자를 생성합니다. 이 사용자는 Postfix 및 Courier에서 메일 데이터베이스에 연결하는 데 사용됩니다.

GRANT SELECT, INSERT, UPDATE, DELETE ON mail.* TO 'mail_admin'@'localhost' IDENTIFIED BY 'mail_admin_password';
GRANT SELECT, INSERT, UPDATE, DELETE ON mail.* TO 'mail_admin'@'localhost.localdomain' IDENTIFIED BY 'mail_admin_password';
FLUSH PRIVILEGES;

여전히 MySQL 셸에서 Postfix 및 Courier에 필요한 테이블을 만듭니다.

USE mail;
CREATE TABLE domains (
domain varchar(50) NOT NULL,
PRIMARY KEY (domain) )
ENGINE=MyISAM;
CREATE TABLE forwardings (
source varchar(80) NOT NULL,
destination TEXT NOT NULL,
PRIMARY KEY (source) )
ENGINE=MyISAM;
CREATE TABLE users (
email varchar(80) NOT NULL,
password varchar(20) NOT NULL,
quota INT(10) DEFAULT '10485760',
PRIMARY KEY (email)
) ENGINE=MyISAM;
CREATE TABLE transport (
domain varchar(128) NOT NULL default '',
transport varchar(128) NOT NULL default '',
UNIQUE KEY domain (domain)
) ENGINE=MyISAM;
quit;

알다시피, 종료와 함께; 명령 우리는 MySQL 셸을 떠났고 Linux 셸로 돌아왔습니다.

domains 테이블은 Postfix가 이메일을 수신해야 하는 각 가상 도메인(예: example.com)을 저장합니다.

domain
example.com

전달 테이블은 하나의 이메일 주소를 다른 이메일 주소에 별칭으로 지정하기 위한 것입니다. [email 의 이메일을 전달합니다.

source destination
[email  [email 

users 테이블은 모든 가상 사용자(예: 이메일 주소와 사용자 이름이 동일하기 때문에 이메일 주소)와 암호(암호화된 형식!) 및 각 사서함의 할당량 값( 이 예에서 기본값은 10MB를 의미하는 10485760바이트입니다.

email password quota
[email  No9.E4skNvGa. ("secret" in encrypted form) 10485760

transport 테이블은 선택 사항이며 고급 사용자를 위한 것입니다. 단일 사용자, 전체 도메인 또는 모든 메일에 대한 메일을 다른 서버로 전달할 수 있습니다. 예를 들어,

domain transport
example.com smtp:[1.2.3.4]

example.com 에 대한 모든 이메일을 smtp 프로토콜을 통해 IP 주소 1.2.3.4 (대괄호 [ ] 은 "MX DNS 레코드를 조회하지 마십시오"를 의미합니다(IP 주소에 대해 이해가 됩니다...). 대신 FQDN(정규화된 도메인 이름)을 사용하는 경우 사각형을 사용하지 않습니다. 괄호.).

BTW, (메일 서버 시스템의 IP 주소가 192.168.0.100이라고 가정) 브라우저에서 http://192.168.0.100/phpmyadmin/을 통해 phpMyAdmin에 액세스하고 mail_admin으로 로그인할 수 있습니다. 그런 다음 데이터베이스를 볼 수 있습니다. 나중에 phpMyAdmin을 사용하여 메일 서버를 관리할 수 있습니다.

5 접미사 구성

이제 우리는 데이터베이스에서 모든 정보를 찾을 수 있는 위치를 Postfix에 알려야 합니다. 따라서 6개의 텍스트 파일을 만들어야 합니다. 내가 Postfix에 localhost 대신 IP 주소 127.0.0.1에서 MySQL에 연결하도록 지시한 것을 알 수 있을 것입니다. 이는 Postfix가 chroot 감옥에서 실행 중이고 내가 Postfix에 localhost를 사용하도록 지시한 경우 연결을 시도할 MySQL 소켓에 대한 액세스 권한이 없기 때문입니다. 127.0.0.1을 사용하는 경우 Postfix는 TCP 네트워킹을 사용하여 chroot 감옥에서도 문제가 되지 않는 MySQL에 연결합니다(대안은 MySQL 소켓을 chroot 감옥으로 이동하여 다른 문제를 유발함).

/etc/mysql/my.cnf에 다음 줄이 포함되어 있는지 확인하십시오.

vi /etc/mysql/my.cnf
[...]
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address           = 127.0.0.1
[...]

/etc/mysql/my.cnf를 수정해야 하는 경우 지금 MySQL을 다시 시작하십시오.

/etc/init.d/mysql restart

달리다

netstat -tap | grep mysql

MySQL이 127.0.0.1(localhost.localdomain)에서 수신하는지 확인하려면:

:~#

이제 여섯 개의 텍스트 파일을 만들어 보겠습니다.

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 '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_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 부서")을 입력합니다.
일반 이름(예: 귀하 name) []: <-- 시스템의 정규화된 도메인 이름을 입력합니다(예: "server1.example.com").
이메일 주소 []: <-- 이메일 주소를 입력합니다.

그런 다음 smtpd.key의 권한을 변경합니다.

chmod o= /etc/postfix/smtpd.key

6 Saslauthd 구성

첫 실행

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

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

vi /etc/default/saslauthd
#
# Settings for saslauthd daemon
# Please read /usr/share/doc/sasl2-bin/README.Debian for details.
#

# Should saslauthd run automatically on startup? (default: no)
START=yes

# Description of this saslauthd instance. Recommended.
# (suggestion: SASL Authentication Daemon)
DESC="SASL Authentication Daemon"

# Short name of this saslauthd instance. Strongly recommended.
# (suggestion: saslauthd)
NAME="saslauthd"

# Which authentication mechanisms should saslauthd use? (default: pam)
#
# Available options in this Debian package:
# getpwent  -- use the getpwent() library function
# kerberos5 -- use Kerberos 5
# pam       -- use PAM
# rimap     -- use a remote IMAP server
# shadow    -- use the local shadow password file
# sasldb    -- use the local sasldb database file
# ldap      -- use LDAP (configuration is in /etc/saslauthd.conf)
#
# Only one option may be used at a time. See the saslauthd man page
# for more information.
#
# Example: MECHANISMS="pam"
MECHANISMS="pam"

# Additional options for this mechanism. (default: none)
# See the saslauthd man page for information about mech-specific options.
MECH_OPTIONS=""

# How many saslauthd processes should we run? (default: 5)
# A value of 0 will fork a new process for each connection.
THREADS=5

# Other options (default: -c -m /var/run/saslauthd)
# Note: You MUST specify the -m option or saslauthd won't run!
#
# WARNING: DO NOT SPECIFY THE -d OPTION.
# The -d option will cause saslauthd to run in the foreground instead of as
# a daemon. This will PREVENT YOUR SYSTEM FROM BOOTING PROPERLY. If you wish
# to run saslauthd in debug mode, please run it by hand to be safe.
#
# See /usr/share/doc/sasl2-bin/README.Debian for Debian-specific information.
# See the saslauthd man page and the output of 'saslauthd -h' for general
# information about these options.
#
# Example for chroot Postfix users: "-c -m /var/spool/postfix/var/run/saslauthd"
# Example for non-chroot Postfix users: "-c -m /var/run/saslauthd"
#
# To know if your Postfix is running chroot, check /etc/postfix/master.cf.
# If it has the line "smtp inet n - y - - smtpd" or "smtp inet n - - - - smtpd"
# then your Postfix is running in a chroot.
# If it has the line "smtp inet n - n - - smtpd" then your Postfix is NOT
# running in a chroot.
#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: sql
sql_engine: 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 = '%[email %r'

다음으로 sasl 그룹에 postfix 사용자를 추가합니다(이렇게 하면 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를 돌려주어야 합니다. 안녕하세요. (Linux 쉘로 돌아가려면 quit를 입력하십시오.)

[이메일 보호됨]:/etc/courier#

8 /etc/aliases 수정

이제 /etc/aliases를 열어야 합니다. postmaster가 root를 가리키고 root가 자신의 사용자 이름이나 이메일 주소를 가리키는지 확인하십시오. 이와 같이:

vi /etc/aliases
[...]
postmaster: root
root: [email 
[...]

또는 다음과 같습니다(관리자가 자신의 사용자 이름인 경우):

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

/etc/aliases를 수정할 때마다 다음을 실행해야 합니다.

newaliases

나중에 Postfix를 다시 시작하십시오.

/etc/init.d/postfix restart

9 amavisd-new, SpamAssassin 및 ClamAV 설치

amavisd-new, spamassassin 및 clamav를 설치하려면 다음 명령을 실행하십시오.

apt-get install amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 libnet-ph-perl libnet-snpp-perl libnet-telnet-perl nomarch lzop pax

그런 다음 amavisd-new를 구성해야 합니다. 구성은 /etc/amavis/conf.d 디렉토리에 있는 다양한 파일로 나뉩니다. 각각을 살펴보고 구성에 익숙해지십시오. 대부분의 설정은 괜찮지만 다음 세 파일을 수정해야 합니다.

먼저 @bypass_virus_checks_maps 및 @bypass_spam_checks_maps 행의 주석 처리를 제거하여 /etc/amavis/conf.d/15-content_filter_mode에서 ClamAV 및 SpamAssassin을 활성화해야 합니다.

vi /etc/amavis/conf.d/15-content_filter_mode

파일은 다음과 같아야 합니다.

use strict;

# You can modify this file to re-enable SPAM checking through spamassassin
# and to re-enable antivirus checking.

#
# Default antivirus checking mode
# Please note, that anti-virus checking is DISABLED by
# default.
# If You wish to enable it, please uncomment the following lines:


@bypass_virus_checks_maps = (
   \%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re);


#
# Default SPAM checking mode
# Please note, that anti-spam checking is DISABLED by
# default.
# If You wish to enable it, please uncomment the following lines:


@bypass_spam_checks_maps = (
   \%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);

1;  # ensure a defined return

그런 다음 /etc/amavis/conf.d/20-debian_defaults에서 spam-/virus-mails에 대한 스팸 설정 및 작업을 살펴봐야 합니다. 기본 설정이 괜찮다면 아무 것도 변경할 필요가 없습니다. 파일에는 많은 설명이 포함되어 있으므로 여기에서 설정을 설명할 필요가 없습니다.

vi /etc/amavis/conf.d/20-debian_defaults
[...]
$QUARANTINEDIR = "$MYHOME/virusmails";
$quarantine_subdir_levels = 1; # enable quarantine dir hashing

$log_recip_templ = undef;    # disable by-recipient level-0 log entries
$DO_SYSLOG = 1;              # log via syslogd (preferred)
$syslog_ident = 'amavis';    # syslog ident tag, prepended to all messages
$syslog_facility = 'mail';
$syslog_priority = 'debug';  # switch to info to drop debug output, etc

$enable_db = 1;              # enable use of BerkeleyDB/libdb (SNMP and nanny)
$enable_global_cache = 1;    # enable use of libdb-based cache if $enable_db=1

$inet_socket_port = 10024;   # default listening socket

$sa_spam_subject_tag = '***SPAM*** ';
$sa_tag_level_deflt  = 2.0;  # add spam info headers if at, or above that level
$sa_tag2_level_deflt = 6.31; # add 'spam detected' headers at that level
$sa_kill_level_deflt = 6.31; # triggers spam evasive actions
$sa_dsn_cutoff_level = 10;   # spam level beyond which a DSN is not sent
[...]
$final_virus_destiny      = D_DISCARD;  # (data not lost, see virus quarantine)
$final_banned_destiny     = D_BOUNCE;   # D_REJECT when front-end MTA
$final_spam_destiny       = D_BOUNCE;
$final_bad_header_destiny = D_PASS;     # False-positive prone (for spam)
[...]

마지막으로 /etc/amavis/conf.d/50-user를 편집하고 $pax=pax; 줄을 추가합니다. 중간에:

vi /etc/amavis/conf.d/50-user
use strict;

#
# Place your configuration directives here.  They will override those in
# earlier files.
#
# See /usr/share/doc/amavisd-new/ for documentation and examples of
# the directives you can use in this file
#
$pax='pax';

#------------ Do not modify anything below this line -------------
1;  # ensure a defined return

그런 다음 다음 명령을 실행하여 clamav 사용자를 amavis 그룹에 추가하고 amavisd-new 및 ClamAV를 다시 시작합니다.

adduser clamav amavis
/etc/init.d/amavis restart
/etc/init.d/clamav-freshclam restart
/etc/init.d/clamav-daemon restart

이제 amavisd-new를 통해 들어오는 이메일을 파이프하도록 Postfix를 구성해야 합니다.

postconf -e 'content_filter = amavis:[127.0.0.1]:10024'
postconf -e 'receive_override_options = no_address_mappings'

그런 다음 /etc/postfix/master.cf에 다음 줄을 추가합니다.

vi /etc/postfix/master.cf
[...]
amavis unix - - - - 2 smtp
        -o smtp_data_done_timeout=1200
        -o smtp_send_xforward_command=yes

127.0.0.1:10025 inet n - - - - smtpd
        -o content_filter=
        -o local_recipient_maps=
        -o relay_recipient_maps=
        -o smtpd_restriction_classes=
        -o smtpd_client_restrictions=
        -o smtpd_helo_restrictions=
        -o smtpd_sender_restrictions=
        -o smtpd_recipient_restrictions=permit_mynetworks,reject
        -o mynetworks=127.0.0.0/8
        -o strict_rfc821_envelopes=yes
        -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks

그런 다음 Postfix를 다시 시작합니다.

/etc/init.d/postfix restart

이제 실행

netstat -tap

포트 25(smtp) 및 10025에서 수신 대기 중인 Postfix(마스터)와 포트 10024에서 amavisd-new가 표시되어야 합니다.

:/etc/courier#
 

10 Razor, Pyzor 및 DCC 설치 및 SpamAssassin 구성

Razor, Pyzor 및 DCC는 협업 필터링 네트워크를 사용하는 스팸 필터입니다. Razor 및 Pyzor를 설치하려면 다음을 실행하십시오.

apt-get install razor pyzor

DCC는 Ubuntu 13.10 리포지토리에서 사용할 수 없으므로 다음과 같이 설치합니다.

cd /tmp
wget http://www.dcc-servers.net/dcc/source/dcc-dccproc.tar.Z
tar xzvf dcc-dccproc.tar.Z
cd dcc-dccproc-1.3.1.154
./configure --with-uid=amavis
make
make install
chown -R amavis:amavis /var/dcc
ln -s /var/dcc/libexec/dccifd /usr/local/bin/dccifd

이제 SpamAssassin에게 이 세 가지 프로그램을 사용하도록 지시해야 합니다. /etc/spamassassin/local.cf를 편집하고 다음 줄을 추가합니다.

vi /etc/spamassassin/local.cf
[...]
#dcc
use_dcc 1
dcc_path /usr/local/bin/dccproc

#pyzor
use_pyzor 1
pyzor_path /usr/bin/pyzor

#razor
use_razor2 1
razor_config /etc/razor/razor-agent.conf

#bayes
use_bayes 1
use_bayes_rules 1
bayes_auto_learn 1

그런 다음 SpamAssassin에서 DCC 플러그인을 활성화해야 합니다. /etc/spamassassin/v310.pre를 열고 loadplugin Mail::SpamAssassin::Plugin::DCC 행의 주석 처리를 제거합니다.

vi /etc/spamassassin/v310.pre
[...]
# DCC - perform DCC message checks.
#
# DCC is disabled here because it is not open source.  See the DCC
# license for more details.
#
loadplugin Mail::SpamAssassin::Plugin::DCC
[...]

다음을 실행하여 SpamAssassin 구성을 확인할 수 있습니다.

spamassassin --lint

오류가 표시되면 안 됩니다.

나중에 amavisd-new를 다시 시작합니다.

/etc/init.d/amavis restart

이제 SpamAssassin 규칙 세트를 다음과 같이 업데이트합니다.

sa-update --no-gpg

규칙 세트가 정기적으로 업데이트되도록 크론 작업을 생성합니다. 달리다

crontab -e

cron 작업 편집기를 엽니다. 다음 cron 작업을 만듭니다.

23 4 */2 * * /usr/bin/sa-update --no-gpg &> /dev/null

이렇게 하면 규칙 세트가 격일로 4.23시에 업데이트됩니다.